From 8024065d04d5ef3d00a34c796b56b7b69660dfd1 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Thu, 25 Jun 2026 15:03:03 +0000 Subject: [PATCH] =?UTF-8?q?Raise=20ValueError=20when=20floor=20dims=20abse?= =?UTF-8?q?nt=20and=20synthesis=20guards=20cannot=20fire=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- datatypes/epc/domain/mapper.py | 6 ++++++ datatypes/epc/domain/tests/test_from_sap_schema.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/datatypes/epc/domain/mapper.py b/datatypes/epc/domain/mapper.py index 72bd667b..1c34d060 100644 --- a/datatypes/epc/domain/mapper.py +++ b/datatypes/epc/domain/mapper.py @@ -2968,6 +2968,12 @@ def _sap_17_1_building_part( ) ] else: + if not bp.sap_floor_dimensions: + raise ValueError( + f"building_part {bp.building_part_number!r}: sap_floor_dimensions " + f"is empty and cannot be synthesised (is_single_part={is_single_part}, " + f"is_flat={is_flat})" + ) floor_dimensions = [ SapFloorDimension( room_height_m=fd.storey_height, diff --git a/datatypes/epc/domain/tests/test_from_sap_schema.py b/datatypes/epc/domain/tests/test_from_sap_schema.py index 47b6cc8c..f55bbb8f 100644 --- a/datatypes/epc/domain/tests/test_from_sap_schema.py +++ b/datatypes/epc/domain/tests/test_from_sap_schema.py @@ -817,3 +817,15 @@ class TestFullSapSchema16xNoFloorDimensions: # Act / Assert assert fd.heat_loss_perimeter_m == pytest.approx(47.08) + + def test_raises_when_floor_dims_absent_and_synthesis_not_possible( + self, + ) -> None: + # Arrange: strip sap_flat_details so is_flat=False — synthesis guard + # cannot fire, empty floor dims must raise rather than silently produce []. + data = load("sap_16_0_full_no_floor_dims.json") + data.pop("sap_flat_details", None) + + # Act / Assert + with pytest.raises(ValueError, match="sap_floor_dimensions"): + EpcPropertyDataMapper.from_api_response(data)