assembly-economics/checkpoints/test_run_checkpoint.py
tegwick 2521955749 Pin checkpoint runs to web-fetcher v0.2.0; add --cache/--replay
run_checkpoint.py refuses web-fetcher versions other than 0.2.0, records the
version in record and summary, and passes --cache/--replay through to
run_spec. Verified: live run with --cache and offline --replay give identical
observations. Execution declaration, AGENTS.md and ASSEMBLY-WP-0014 updated.
Requested by web-fetcher (WEBFETCH-WP-0003-T03).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 193986@bnt-lap001
Assistant-Session: 585bfbea-320e-47b3-8c0e-bc1513a53307
2026-10-19 14:47:15 +02:00

74 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Tests for the checkpoint runner (offline). Usage:
python3 -B -m unittest discover -s checkpoints -p 'test_*.py'
"""
import sys
import types
import unittest
from datetime import date
from pathlib import Path
import run_checkpoint as rc
SCHEDULE = (Path(__file__).parent / "schedule.md").read_text()
class TestWindow(unittest.TestCase):
def test_monthly_and_steady_windows(self):
self.assertEqual(rc.active_phase(date(2026, 11, 15), "light", SCHEDULE), "transition")
self.assertEqual(rc.active_phase(date(2027, 4, 15), "light", SCHEDULE), "steady")
self.assertEqual(rc.active_phase(date(2027, 1, 20), "full", SCHEDULE), "steady")
def test_out_of_window(self):
self.assertIsNone(rc.active_phase(date(2026, 10, 1), "light", SCHEDULE))
self.assertIsNone(rc.active_phase(date(2026, 11, 15), "full", SCHEDULE))
def test_parser_handles_ranges(self):
sched = "| setup | `light` | 2026-10-14 – 2026-10-16 | daily | x |\n"
self.assertEqual(rc.active_phase(date(2026, 10, 15), "light", sched), "setup")
self.assertIsNone(rc.active_phase(date(2026, 10, 17), "light", sched))
class TestPredictions(unittest.TestCase):
def test_registered_predictions_are_cited(self):
preds = rc.registered()
self.assertIn("P-2026-001", rc.band_position(preds, "L1", "US"))
self.assertIn("P-2026-002", rc.band_position(preds, "L2", "EU27_2020"))
self.assertEqual(rc.band_position(preds, "L9", "US"), "no prediction registered")
class TestRegimePointer(unittest.TestCase):
def test_full_record_points_to_regime_report(self):
full = rc.render(date(2027, 1, 15), "full", "steady", [], None, "x", "d.jsonl")
light = rc.render(date(2027, 1, 15), "light", "steady", [], None, "x", "d.jsonl")
self.assertIn("results/matching.md", full)
self.assertNotIn("results/matching.md", light)
class TestNumberGuard(unittest.TestCase):
def test_numbers_extraction(self):
self.assertEqual(rc._numbers("EU at 19.95 % in 2025, US 23.8."), {"19.95", "2025", "23.8"})
class TestWebFetcherPin(unittest.TestCase):
def _with_version(self, version):
saved = sys.modules.get("web_fetcher")
sys.modules["web_fetcher"] = types.SimpleNamespace(__version__=version)
try:
return rc.web_fetcher_version()
finally:
if saved is None:
del sys.modules["web_fetcher"]
else:
sys.modules["web_fetcher"] = saved
def test_pinned_version_accepted(self):
self.assertEqual(self._with_version(rc.WEB_FETCHER_VERSION), rc.WEB_FETCHER_VERSION)
def test_other_version_refused(self):
with self.assertRaises(SystemExit):
self._with_version("0.1.0")
if __name__ == "__main__":
unittest.main()