Model/tests/domain/epc/test_water_heating_guard.py
Khalim Conn-Kowlessar d7f069b7c5 Deterministically guard structured biomass and immersion water-heating descriptions 🟥
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 13:05:47 +00:00

80 lines
2.7 KiB
Python

from __future__ import annotations
import pytest
from domain.epc.property_overrides.water_heating_guard import water_heating_guard
from domain.epc.property_overrides.water_heating_type import WaterHeatingType
@pytest.mark.parametrize(
("description", "expected"),
[
# The biomass/wood family the LLM funnelled into "house coal" (#1376).
(
"From main heating system: Wood Logs",
WaterHeatingType.FROM_MAIN_WOOD_LOGS,
),
(
"From main heating system: Dual Fuel: Mineral and Wood",
WaterHeatingType.FROM_MAIN_DUAL_FUEL_MINERAL_WOOD,
),
# "Hot-water only community scheme" flattens to "from main", per the
# existing convention (community mains-gas already resolves that way).
(
"From main heating system: Biomass (Community)",
WaterHeatingType.FROM_MAIN_BIOMASS_COMMUNITY,
),
(
"Hot-water only community scheme - boilers: Biomass (Community)",
WaterHeatingType.FROM_MAIN_BIOMASS_COMMUNITY,
),
(
"Hot-water only community scheme - boilers: Heat from Boilers "
"using Biodiesel from any source (Community)",
WaterHeatingType.FROM_MAIN_BIODIESEL_COMMUNITY,
),
# "No Heating or Hot Water" under "electric immersion assumed" is the
# assessment's own immersion assumption — honour it (ADR-0043).
(
"No hot water system present - electric immersion assumed: "
"No Heating or Hot Water",
WaterHeatingType.ELECTRIC_IMMERSION,
),
# A genuinely coal DHW stays house coal.
(
"From main heating system: House Coal",
WaterHeatingType.FROM_MAIN_HOUSE_COAL,
),
],
)
def test_guard_resolves_the_structured_biomass_and_immersion_descriptions(
description: str, expected: WaterHeatingType
) -> None:
# Act
result = water_heating_guard(description)
# Assert
assert result is expected
@pytest.mark.parametrize(
"description",
[
# Fuels the LLM already classifies correctly — the guard must not claim
# them (it only rescues the previously-misclassified structured cases).
"From main heating system: Mains Gas",
"Electric immersion: Electricity",
"From main heating system: Oil",
# A varied / unstructured phrasing is the LLM's job.
"hot water from the wood burner",
"",
],
)
def test_guard_defers_recognised_and_unstructured_descriptions_to_the_llm(
description: str,
) -> None:
# Act
result = water_heating_guard(description)
# Assert
assert result is None