"""Run a directory of API-shaped EPC JSONs through Modelling, offline.""" from __future__ import annotations from pathlib import Path from harness.cohort import ( CertResult, format_cohort_csv, format_cohort_summary, run_cohort, ) _GOLDEN = ( Path(__file__).resolve().parents[1] / "domain/sap10_calculator/rdsap/fixtures/golden" ) def test_run_cohort_models_each_api_json_offline() -> None: # Arrange — two real API-shaped EPC certs (identical to the EPC response). paths: list[Path] = sorted(_GOLDEN.glob("*.json"))[:2] assert len(paths) == 2 # Act — no database, no network. results: list[CertResult] = run_cohort(paths, goal_band="C") # Assert — one result per cert, each either modelled or carrying its error. assert len(results) == 2 for result in results: assert result.name assert result.error is not None or result.measures >= 0 # The summary renders without raising and counts the cohort. summary: str = format_cohort_summary(results) assert "2" in summary def test_cohort_carries_each_plan_and_renders_a_csv() -> None: # Arrange / Act paths: list[Path] = sorted(_GOLDEN.glob("*.json"))[:3] results: list[CertResult] = run_cohort(paths) # Assert — each cert either modelled (carries its Plan) or errored. for result in results: assert (result.plan is not None) != (result.error is not None) # CSV: a header row plus one row per cert, browsable in a spreadsheet. csv: str = format_cohort_csv(results) lines: list[str] = csv.splitlines() assert lines[0].startswith("cert,") assert len(lines) == len(results) + 1