Map Not-Defined glazing code to a valid type for windowless 18.0 certs 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-06-11 11:55:46 +00:00
parent 42f02f33d8
commit 0008c33ea9

View file

@ -1553,3 +1553,55 @@ class TestRdSap18_0ReducedFieldSynthesis:
# Assert
total_area = sum(w.window_width * w.window_height for w in result.sap_windows)
assert total_area == pytest.approx(0.148 * tfa * 1.25)
def test_synthesised_glazing_type_routed_through_cascade(self) -> None:
# Arrange — ADR-0028: 18.0 multiple_glazing_type shares 20.0.0's code
# space (verified vs epc_codes.csv), so route it through the verified
# cascade — code 1 ("DG pre-2002") must remap to 2, not be read as single.
# A windowless cert lodging multiple_glazing_type=1.
corpus = _load_18_0_corpus()
if not corpus:
pytest.skip("no RdSAP-Schema-18.0 corpus harvested")
cert = next(
(
c
for c in corpus
if not c.get("sap_windows") and c.get("multiple_glazing_type") == 1
),
None,
)
if cert is None:
pytest.skip("no corpus cert with multiple_glazing_type=1")
# Act
result = EpcPropertyDataMapper.from_api_response(cert)
# Assert — cascade remaps 1 ("DG pre-2002") -> 2 (double), not raw 1.
assert all(w.glazing_type == 2 for w in result.sap_windows)
def test_synthesised_glazing_type_handles_not_defined_code(self) -> None:
# Arrange — ADR-0028: 69/1000 18.0 certs lodge multiple_glazing_type "ND"
# (Not Defined), a string the int-keyed cascade cannot map. The
# synthesised window must carry a valid INTEGER glazing_type (treated as
# DG-modal, matching the calculator's _G_LIGHT_DEFAULT), never the raw
# "ND" string on an int field. A windowless cert lodging "ND".
corpus = _load_18_0_corpus()
if not corpus:
pytest.skip("no RdSAP-Schema-18.0 corpus harvested")
cert = next(
(
c
for c in corpus
if not c.get("sap_windows") and c.get("multiple_glazing_type") == "ND"
),
None,
)
if cert is None:
pytest.skip("no windowless corpus cert with multiple_glazing_type ND")
# Act
result = EpcPropertyDataMapper.from_api_response(cert)
# Assert — every synthesised window has an int glazing_type, not "ND".
assert result.sap_windows
assert all(isinstance(w.glazing_type, int) for w in result.sap_windows)