#!/usr/bin/env python3 """Rewrite every golden file under tests/golden/. Run after an intentional change to the renderer, then read the diff -- that diff is the change, stated in output rather than in code: uv run python tests/regenerate_golden.py jj diff tests/golden """ from __future__ import annotations import shutil import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from conftest import EXAMPLES, GOLDEN, render_file # noqa: E402 from golden_cases import CASES, MULTI_CASES # noqa: E402 def main() -> int: GOLDEN.mkdir(parents=True, exist_ok=True) for name, (source, options) in CASES.items(): output = render_file(EXAMPLES / source, **options) (GOLDEN / f"{name}.wml").write_text(output.text, encoding="utf-8") print(f"wrote {name}.wml") for name, (source, options) in MULTI_CASES.items(): directory = GOLDEN / name if directory.exists(): shutil.rmtree(directory) directory.mkdir(parents=True) for document in render_file(EXAMPLES / source, **options).documents: (directory / (document.name or "index.wml")).write_text( document.text, encoding="utf-8" ) print(f"wrote {name}/ ({len(list(directory.iterdir()))} files)") return 0 if __name__ == "__main__": raise SystemExit(main())