from pathlib import Path import sys import yaml ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) from regulator_paper_assumptions import REGISTRY, load_registry_from_yaml # noqa: E402 from system_b_ledger import RETIRED_COMPOSITE_MW, build_ledger # noqa: E402 YAML_PATH = Path(__file__).resolve().parents[1] / "assumptions.yaml" def test_yaml_exists_and_has_evidence_classes(): data = yaml.safe_load(YAML_PATH.read_text()) assert "peak_record_mw" in data assert data["peak_record_mw"]["evidence"] in {"O", "C", "E", "A", "PD"} def test_registry_matches_yaml(): loaded = load_registry_from_yaml(YAML_PATH) assert loaded["scenario_full_mw"][0] == REGISTRY["scenario_full_mw"][0] assert loaded["hub_thermal_mwth"][0] == 50 assert loaded["hub_contingent_thermal_mwth"][0] == 95 assert loaded["hub_net_electric_mw"][0] == 38 assert loaded["btes_winter_planning_mw"][0] == 120 assert loaded["btes_winter_eligible_mw"][0] == 0 assert loaded["btes_winter_planning_mw"][1] == "E" assert loaded["btes_winter_eligible_mw"][1] == "C" def test_ledger_still_passes_from_yaml_backed_registry(): report = build_ledger().pass_report() assert report["passed"] is True assert RETIRED_COMPOSITE_MW not in ( build_ledger().accreditation_mw["full"], build_ledger().firm_headline_mw, ) def test_tests_passing_metadata_matches_collected_suite(): """Registry tests_passing must track the live pytest collection count.""" import subprocess data = yaml.safe_load(YAML_PATH.read_text()) claimed = int(data["tests_passing"]["value"]) result = subprocess.run( ["python3", "-m", "pytest", str(ROOT), "--collect-only", "-q"], cwd=ROOT.parent, capture_output=True, text=True, check=True, ) # Final summary line looks like: "84 tests collected in 0.59s" summary = [ln for ln in result.stdout.splitlines() if "tests collected" in ln] assert summary, result.stdout collected = int(summary[-1].split()[0]) assert claimed == collected, f"tests_passing={claimed} but suite collects {collected}"