Model/tests/scripts/test_backfill_boiler_efficiency_band.py
Khalim Conn-Kowlessar c690cd3183 feat(backfill): boiler_efficiency_band rows from existing heating descriptions
Idempotent, dry-run-by-default script (mirrors reclassify_main_heating). Parses
the SEDBUK band off each main_heating_system row's original_spreadsheet_description
with the SAME guard as the live classifier (no drift), upserting a
boiler_efficiency_band row per boiler that carries one. Pure core band_backfill_rows
unit-tested. FE-enum-gated writes (Class-A/B deferred) (ADR-0068).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-29 16:34:53 +00:00

54 lines
1.7 KiB
Python

from __future__ import annotations
from scripts.backfill_boiler_efficiency_band import (
BandBackfillRow,
MainHeatingRow,
band_backfill_rows,
)
def _row(desc: str, *, property_id: int = 1, building_part: int = 0) -> MainHeatingRow:
return MainHeatingRow(
property_id=property_id,
portfolio_id=796,
building_part=building_part,
original_spreadsheet_description=desc,
)
def test_backfills_a_band_row_per_boiler_with_a_parseable_band() -> None:
rows = [
_row("Boiler: D rated Regular Boiler", property_id=10),
_row("Boiler: G rated Combi", property_id=11, building_part=1),
]
result = band_backfill_rows(rows)
assert result == [
BandBackfillRow(10, 796, 0, "D", "Boiler: D rated Regular Boiler"),
BandBackfillRow(11, 796, 1, "G", "Boiler: G rated Combi"),
]
def test_leaves_descriptions_without_a_band_untouched() -> None:
rows = [
_row("Gas boiler"),
_row("Community Heating Systems: Community boilers only (RdSAP)"),
_row(""),
]
assert band_backfill_rows(rows) == []
def test_uses_the_same_guard_as_the_live_path_for_multi_system_and_electric() -> None:
rows = [
# Multi-system: primary (system 1) band wins — matches the guard.
_row("Boiler: A rated Combi, System 2: Boiler: C rated Combi", property_id=20),
# Band letter on an electric "NA" boiler is stored for fidelity; the
# gas/oil modelling gate ignores it at overlay time (ADR-0068).
_row("Boiler: A rated NA", property_id=21),
]
result = band_backfill_rows(rows)
assert [(r.property_id, r.override_value) for r in result] == [(20, "A"), (21, "A")]