#!/usr/bin/env python3 """Compare Rust results to the Python reference using real media and both PDF layouts.""" import json from pathlib import Path import shutil import subprocess import sys import tempfile import zipfile ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) from tests.test_playback import PlaybackTests, picture, timing def main(): binary = Path(sys.argv[1]).resolve() for tool in ("ffmpeg", "ffprobe", "typst"): if not shutil.which(tool): raise SystemExit(f"Parity check requires {tool} on PATH.") with tempfile.TemporaryDirectory(prefix="reporter-parity-") as temporary: root = Path(temporary) clip = root / "clip.mp4" subprocess.run(["ffmpeg", "-v", "error", "-f", "lavfi", "-i", "color=c=blue:s=32x24:r=10", "-t", "10", "-c:v", "mpeg4", str(clip)], check=True) fixture = PlaybackTests() fixture.setUp() try: source = fixture.deck([ (picture("2", '') + picture("3", ''), timing("2", 'dur="indefinite"')), (picture("2", ''), timing("2", 'repeatCount="indefinite"')), (picture("2"), timing("2", 'spd="200000"')), (picture("2", ''), ''), (picture("2"), timing("99", 'repeatCount="indefinite"')), (picture("2"), timing("2", children='')), (picture("2"), timing("2", media_attrs='numSld="2"')), ]) presentation = root / "Présentation & .pptx" with zipfile.ZipFile(source) as old, zipfile.ZipFile(presentation, "w") as new: for name in old.namelist(): new.writestr(name, clip.read_bytes() if name.endswith(".mp4") else old.read(name)) new.writestr("ppt/media/orphan.mp4", clip.read_bytes()) for runner, output in [([sys.executable, str(ROOT / "tools/pptx_videos.py")], root / "python"), ([str(binary)], root / "rust")]: subprocess.run([*runner, str(presentation), "--timings-only", "--report", "all", "-o", str(output)], check=True) assert not (output / "videos").exists() for filename in ("timings.json", "timings.ontime.json"): expected = json.loads((root / "python/reports" / filename).read_text()) actual = json.loads((root / "rust/reports" / filename).read_text()) if actual != expected: raise AssertionError(f"{filename} differs:\nPython: {expected}\nRust: {actual}") for name in ("timings.pdf", "timings-dense.pdf"): assert (root / "rust/reports" / name).read_bytes().startswith(b"%PDF") # Optional retained review samples, only at an explicitly supplied location. if len(sys.argv) > 2: shutil.copytree(root / "rust", Path(sys.argv[2]), dirs_exist_ok=True) print("PASS: Python/Rust report and Ontime JSON match; all formats and both PDFs generated.") finally: fixture.doCleanups() if __name__ == "__main__": main()