mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-22 08:48:38 +00:00
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""HistoricConditioning resolves an expired Historic EPC's stable attributes
|
|
into the cohort's code spaces (ADR-0054).
|
|
|
|
Only stable attributes are resolved — volatile ones (heating system, glazing,
|
|
PV, insulation states) never condition prediction. Every resolver degrades to
|
|
None on an unresolvable value, which leaves its cohort filter inactive.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import dataclasses
|
|
|
|
from datatypes.epc.domain.historic_epc import HistoricEpc
|
|
from domain.epc_prediction.historic_conditioning import (
|
|
HistoricConditioning,
|
|
conditioning_from_historic,
|
|
)
|
|
|
|
|
|
def _hist(**overrides: str) -> HistoricEpc:
|
|
fields = {f.name: "" for f in dataclasses.fields(HistoricEpc)}
|
|
fields.update(overrides)
|
|
return HistoricEpc(**fields)
|
|
|
|
|
|
def test_resolves_stable_attributes_into_cohort_code_spaces():
|
|
# Arrange — display-text values exactly as the old register lodged them.
|
|
record = _hist(
|
|
property_type="House",
|
|
built_form="Semi-Detached",
|
|
walls_description="Cavity wall, as built, no insulation (assumed)",
|
|
construction_age_band="England and Wales: 1930-1949",
|
|
main_fuel="mains gas (not community)",
|
|
total_floor_area="84",
|
|
)
|
|
|
|
# Act
|
|
conditioning = conditioning_from_historic(record)
|
|
|
|
# Assert — each attribute lands in the code space its cohort filter compares.
|
|
assert isinstance(conditioning, HistoricConditioning)
|
|
assert conditioning.property_type == "0"
|
|
assert conditioning.built_form == "2"
|
|
assert conditioning.wall_construction == 4
|
|
assert conditioning.construction_age_band == "C"
|
|
assert conditioning.main_fuel == 26
|
|
assert conditioning.total_floor_area_m2 == 84.0
|
|
|
|
|
|
def test_unresolvable_values_degrade_to_none():
|
|
# Arrange — junk and blanks must never guess a code.
|
|
record = _hist(
|
|
property_type="Castle",
|
|
built_form="Not Recorded",
|
|
walls_description="Average thermal transmittance 0.3 W/m²K",
|
|
construction_age_band="INVALID!",
|
|
main_fuel="To be used only when there is no heating system",
|
|
total_floor_area="",
|
|
)
|
|
|
|
# Act
|
|
conditioning = conditioning_from_historic(record)
|
|
|
|
# Assert
|
|
assert conditioning.property_type is None
|
|
assert conditioning.built_form is None
|
|
assert conditioning.wall_construction is None
|
|
assert conditioning.construction_age_band is None
|
|
assert conditioning.main_fuel is None
|
|
assert conditioning.total_floor_area_m2 is None
|