"""The Landlord-Override value → gov-EPC code mapping (ADR-0031 wiring). `property_type` is the HARD cohort filter, so its mapping is exhaustive over `PropertyType` and the only one that can silently empty a cohort; `built_form` is the SOFT filter. Both collapse an unresolvable value to None — gating lives downstream, the mapping just reports "no usable code". """ from __future__ import annotations from typing import Optional import pytest from domain.epc.property_overrides.built_form_type import BuiltFormType from domain.epc.property_overrides.override_code_mapping import ( built_form_to_code, property_type_to_code, ) from domain.epc.property_overrides.property_type import PropertyType def test_house_maps_to_gov_code_zero() -> None: # Act code = property_type_to_code("House") # Assert assert code == "0" @pytest.mark.parametrize( ("override_value", "expected_code"), [ (PropertyType.HOUSE.value, "0"), (PropertyType.BUNGALOW.value, "1"), (PropertyType.FLAT.value, "2"), (PropertyType.MAISONETTE.value, "3"), (PropertyType.PARK_HOME.value, "4"), ], ) def test_each_resolvable_property_type_maps_to_its_gov_code( override_value: str, expected_code: str ) -> None: # Act code = property_type_to_code(override_value) # Assert assert code == expected_code @pytest.mark.parametrize( "override_value", [PropertyType.UNKNOWN.value, "Castle", ""], ) def test_unresolvable_property_type_has_no_code(override_value: str) -> None: # Act code = property_type_to_code(override_value) # Assert assert code is None @pytest.mark.parametrize( ("override_value", "expected_code"), [ (BuiltFormType.DETACHED.value, "1"), (BuiltFormType.SEMI_DETACHED.value, "2"), (BuiltFormType.END_TERRACE.value, "3"), (BuiltFormType.MID_TERRACE.value, "4"), (BuiltFormType.ENCLOSED_END_TERRACE.value, "5"), (BuiltFormType.ENCLOSED_MID_TERRACE.value, "6"), ], ) def test_each_resolvable_built_form_maps_to_its_gov_code( override_value: str, expected_code: str ) -> None: # Act code = built_form_to_code(override_value) # Assert assert code == expected_code @pytest.mark.parametrize( "override_value", [BuiltFormType.UNKNOWN.value, BuiltFormType.NOT_RECORDED.value, "Castle", ""], ) def test_built_form_without_usable_code_returns_none(override_value: str) -> None: # Act code: Optional[str] = built_form_to_code(override_value) # Assert assert code is None