diff options
| author | godosa <godosa@godosa.eu> | 2026-10-06 23:39:36 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-06 23:39:36 +0200 |
| commit | 39066900773e7857faf2d02e7ed51b71d219d97d (patch) | |
| tree | ffab8e4ddd971626776c3b1f4ce1da2c186c2187 /scripts/test_digest_compare.py | |
| download | godosa-engine-39066900773e7857faf2d02e7ed51b71d219d97d.tar.gz godosa-engine-39066900773e7857faf2d02e7ed51b71d219d97d.zip | |
godosa-engine: initial public history
Diffstat (limited to 'scripts/test_digest_compare.py')
| -rw-r--r-- | scripts/test_digest_compare.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/test_digest_compare.py b/scripts/test_digest_compare.py new file mode 100644 index 0000000..400e057 --- /dev/null +++ b/scripts/test_digest_compare.py @@ -0,0 +1,42 @@ +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).with_name("digest_compare.py") + + +def run(a: str, b: str) -> subprocess.CompletedProcess: + with tempfile.TemporaryDirectory() as d: + pa, pb = Path(d, "a.log"), Path(d, "b.log") + pa.write_text(a) + pb.write_text(b) + return subprocess.run([sys.executable, str(SCRIPT), str(pa), str(pb)], capture_output=True, text=True) + + +class DigestCompareTests(unittest.TestCase): + def test_equal(self): + r = run("x\ndigest 1 0 00000000000000aa\n", "y\ndigest 1 0 00000000000000aa\n") + self.assertEqual(0, r.returncode) + self.assertIn("1 digests equal", r.stdout) + + def test_first_difference(self): + r = run("digest 1 0 00000000000000aa\ndigest 2 0 00000000000000bb\n", + "digest 1 0 00000000000000aa\ndigest 2 0 00000000000000cc\n") + self.assertEqual(1, r.returncode) + self.assertIn("digest 2 differs", r.stdout) + + def test_count_mismatch(self): + r = run("digest 1 0 00000000000000aa\n", "digest 1 0 00000000000000aa\ndigest 2 0 00000000000000bb\n") + self.assertEqual(1, r.returncode) + self.assertIn("1 vs 2 digests", r.stdout) + + def test_none(self): + r = run("x\n", "y\n") + self.assertEqual(1, r.returncode) + self.assertIn("no digest lines", r.stdout) + + +if __name__ == "__main__": + unittest.main() |
