test_config_all.py 975 B

1234567891011121314151617181920212223242526272829
  1. """Assert that config-all.json matches what gen_example_config.py produces.
  2. Fails when a new configurable item is added (to a dataclass or to config.json)
  3. but config-all.json hasn't been regenerated. Fix by running the pre-commit hook
  4. or: uv run python scripts/gen_example_config.py > room_cal/config-all.json
  5. """
  6. import importlib.util
  7. from pathlib import Path
  8. _ROOT = Path(__file__).parent.parent
  9. def _load_generator():
  10. spec = importlib.util.spec_from_file_location(
  11. 'gen_example_config',
  12. _ROOT / 'scripts' / 'gen_example_config.py',
  13. )
  14. mod = importlib.util.module_from_spec(spec)
  15. spec.loader.exec_module(mod)
  16. return mod
  17. def test_config_all_is_current():
  18. generated = _load_generator().generate().strip()
  19. committed = (_ROOT / 'room_cal' / 'config-all.json').read_text(encoding='utf-8').strip()
  20. assert generated == committed, (
  21. 'config-all.json is stale. '
  22. 'Run: uv run python scripts/gen_example_config.py > room_cal/config-all.json'
  23. )