From 39066900773e7857faf2d02e7ed51b71d219d97d Mon Sep 17 00:00:00 2001 From: godosa Date: Tue, 6 Oct 2026 23:39:36 +0200 Subject: godosa-engine: initial public history --- scripts/test_digest_compare.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scripts/test_digest_compare.py (limited to 'scripts/test_digest_compare.py') 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() -- cgit