57 lines
2.0 KiB
Python
Executable File
57 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import analyze_psp_delta
|
|
|
|
|
|
def git(repo: Path, *args: str) -> str:
|
|
result = subprocess.run(
|
|
["git", "-C", str(repo), *args], text=True, capture_output=True, check=True
|
|
)
|
|
return result.stdout.strip()
|
|
|
|
|
|
def init(repo: Path, files: dict[str, str]) -> None:
|
|
repo.mkdir()
|
|
git(repo, "init", "-q")
|
|
for name, content in files.items():
|
|
path = repo / name
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(content, encoding="utf-8")
|
|
git(repo, "add", ".")
|
|
git(repo, "-c", "user.name=PSP Test", "-c", "user.email=x@example.invalid", "commit", "-qm", "base")
|
|
|
|
|
|
def main() -> int:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
reference = root / "reference"
|
|
target = root / "target"
|
|
init(reference, {"stable.ini": "new\n", "dirty.ini": "head\n", "gone.ini": "old\n"})
|
|
init(target, {"stable.ini": "old\n", "dirty.ini": "old\n", "gone.ini": "old\n", "local.ini": "base\n"})
|
|
(reference / "dirty.ini").write_text("dirty-reference\n", encoding="utf-8")
|
|
(reference / "gone.ini").unlink()
|
|
(target / "stable.ini").write_text("new\n", encoding="utf-8")
|
|
(target / "dirty.ini").write_text("dirty-reference\n", encoding="utf-8")
|
|
(target / "gone.ini").unlink()
|
|
(target / "local.ini").write_text("target-only\n", encoding="utf-8")
|
|
|
|
result = analyze_psp_delta.analyze(target, reference)
|
|
assert result["passed"] is True
|
|
assert result["reference"]["dirty"] is True
|
|
categories = result["categories"]
|
|
assert "stable.ini" in categories["matches_reference_head"]
|
|
assert "dirty.ini" in categories["matches_reference_dirty_worktree"]
|
|
assert "gone.ini" in categories["matches_reference_dirty_worktree"]
|
|
assert "local.ini" in categories["target_specific"]
|
|
|
|
print("PSP three-way delta tests passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|