47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
||
"""rewrite-selection expectedRevision 纯函数离线测试(不连库)。"""
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
PROJECT_ROOT = Path(__file__).resolve().parents[3]
|
||
SCRIPTS = PROJECT_ROOT / "muse" / "content" / "work" / "skills" / "generate" / "rewrite-selection" / "scripts"
|
||
sys.path.insert(0, str(SCRIPTS))
|
||
|
||
import click # noqa: E402
|
||
|
||
from assert_expected_revision import ( # noqa: E402
|
||
RevisionConflict,
|
||
assert_expected_revision,
|
||
)
|
||
|
||
|
||
def expect_conflict(fn) -> None:
|
||
try:
|
||
fn()
|
||
except RevisionConflict:
|
||
return
|
||
raise AssertionError("应抛 RevisionConflict")
|
||
|
||
|
||
def main() -> None:
|
||
snap = {
|
||
"work_id": 8,
|
||
"chapter_order": 12,
|
||
"block_id": 99,
|
||
"revision": 4,
|
||
}
|
||
assert assert_expected_revision(snap, 4)["revision"] == 4
|
||
expect_conflict(lambda: assert_expected_revision(snap, 3))
|
||
empty = {**snap, "block_id": None, "revision": 0}
|
||
assert assert_expected_revision(empty, 0)["revision"] == 0
|
||
expect_conflict(lambda: assert_expected_revision(empty, 1))
|
||
try:
|
||
raise RevisionConflict("x")
|
||
except click.ClickException:
|
||
pass
|
||
print("PASS:assert_expected_revision 纯函数全部通过")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|