Model/tests/scripts/test_reclassify_flat_roof_thickness.py
Khalim Conn-Kowlessar 32e296ca3f Re-classify flat-roof overrides with a known depth onto their thickness member 🟩
One-time script (dry-run default, --apply in a transaction, idempotent) mapping a
flat roof's stated depth (flat: Nmm) onto the nearest Table 16 rung member so the
overlay scores it by thickness, not the age-band default. Updates property_overrides
(TEXT) immediately; the roof_type pgEnum cache writes are deferred until the FE adds
the FLAT_*MM members. Dry-run against the audited DB reports 102 rows, deferring
Flat 50/100/150 mm.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 10:19:09 +00:00

44 lines
1.7 KiB
Python

"""The flat-roof reclassify maps a stated depth onto its Table 16 thickness member,
leaves depthless / non-flat rows alone, and is idempotent (#1376 / ADR-0041)."""
from __future__ import annotations
from scripts.reclassify_flat_roof_thickness import flat_thickness_corrections
def test_flat_depth_rows_are_corrected_to_the_thickness_member() -> None:
# Arrange — flat roofs with a real depth (currently on the age-band-default
# value), alongside depthless flat rows and a pitched row that must be left.
stored = [
("flat: 150mm", "Flat, insulated (assumed)"),
("flat: 50mm", "Flat, insulated (assumed)"),
("flat: unknown", "Flat, insulated (assumed)"),
("flat: as built", "Flat, insulated (assumed)"),
("flat: no insulation", "Flat, no insulation"),
("pitchednormalloftaccess: 100mm", "Pitched, 100 mm loft insulation"),
]
# Act
corrections = flat_thickness_corrections(stored)
# Assert — only the flat-depth rows are re-mapped, to their thickness member.
assert corrections == {
"flat: 150mm": "Flat, 150 mm insulation",
"flat: 50mm": "Flat, 50 mm insulation",
}
def test_a_non_rung_depth_snaps_to_the_nearest_tabulated_rung() -> None:
# RdSAP Table 16 uses the nearest tabulated thickness <= the stated depth.
# Act / Assert
assert flat_thickness_corrections(
[("flat: 60mm", "Flat, insulated (assumed)")]
) == {"flat: 60mm": "Flat, 50 mm insulation"}
def test_already_corrected_flat_rows_need_no_change() -> None:
# Act / Assert — idempotent.
assert (
flat_thickness_corrections([("flat: 150mm", "Flat, 150 mm insulation")]) == {}
)