diff --git a/tests/repositories/epc/test_epc_round_trip.py b/tests/repositories/epc/test_epc_round_trip.py index f32e40b1..ed49b6d9 100644 --- a/tests/repositories/epc/test_epc_round_trip.py +++ b/tests/repositories/epc/test_epc_round_trip.py @@ -86,6 +86,42 @@ def test_non_separated_conservatory_round_trips(db_engine: Engine) -> None: assert reloaded == original +def test_floor_dimension_heat_loss_flags_round_trip(db_engine: Engine) -> None: + # SAP 10.2 ยง3.3 โ€” `is_exposed_floor` and `is_above_partially_heated_space` + # are heat-loss flags on a `SapFloorDimension`: the calculator routes a floor + # over outside air / over a partially-heated space through a different + # U-value path. They had no `epc_floor_dimension` column, so a True flag + # round-tripped back to the `False` default and silently flipped the floor's + # heat loss (persist != score). We force both True on a clean fixture so the + # ONLY thing that can break deep-equality is these two flags. + from dataclasses import replace + + # Arrange โ€” a green fixture with a floor dimension, both flags forced True. + original = _load_epc("RdSAP-Schema-21.0.0") + assert original.sap_building_parts, "fixture must have a building part" + bp0 = original.sap_building_parts[0] + assert bp0.sap_floor_dimensions, "fixture building part must have a floor dimension" + dim0 = replace( + bp0.sap_floor_dimensions[0], + is_exposed_floor=True, + is_above_partially_heated_space=True, + ) + bp0 = replace(bp0, sap_floor_dimensions=[dim0, *bp0.sap_floor_dimensions[1:]]) + original = replace( + original, sap_building_parts=[bp0, *original.sap_building_parts[1:]] + ) + + # Act + with Session(db_engine) as session: + epc_property_id = EpcPostgresRepository(session).save(original) + session.commit() + with Session(db_engine) as session: + reloaded = EpcPostgresRepository(session).get(epc_property_id) + + # Assert โ€” both flags survive the round-trip, deep-equal. + assert reloaded == original + + def test_building_part_wall_insulation_thickness_preserves_int( db_engine: Engine, ) -> None: