Model/tests/domain/property_baseline/test_sap_fuel.py
Khalim Conn-Kowlessar 5f65b9be62 feat(baseline): SAP fuel-code -> Fuel mapping for billing (ADR-0014)
Slice 3 of Bill Derivation. sap_code_to_fuel(code) maps a SAP 10.2 / Table 32
fuel code to the canonical billing Fuel — bounded to the ~47 Table 32 codes (the
carrier, orthogonal to the PCDB product index, so all PCDB heat pumps share one
electricity code). Mains gas / LPG / oil+bioliquids / coal / smokeless / wood /
electricity (standard + off-peak) / heat-network groupings; an unmapped code
(dual fuel, grid-export) raises UnmappedSapCode rather than guessing.

Also: ADR-0014 deferred/TODO section records the stubbed appliances+cooking
(pending the SapResult fields), the off-peak day/night split, the heat-network
rate gap, and regional rates / ETL.

The SapResult -> EnergyBreakdown adapter (next slice) is gated on the
appliances/cooking fields landing on SapResult.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 09:50:10 +00:00

42 lines
1.4 KiB
Python

from __future__ import annotations
import pytest
from domain.fuel_rates.fuel import Fuel
from domain.property_baseline.sap_fuel import sap_code_to_fuel
from domain.sap10_calculator.exceptions import UnmappedSapCode
def test_mains_gas_code_maps_to_mains_gas() -> None:
# Arrange / Act / Assert — Table 32 code 1 is mains gas.
assert sap_code_to_fuel(1) == Fuel.MAINS_GAS
@pytest.mark.parametrize(
("code", "fuel"),
[
(1, Fuel.MAINS_GAS),
(2, Fuel.LPG),
(4, Fuel.OIL),
(76, Fuel.OIL), # bioethanol — a liquid fuel row
(11, Fuel.COAL), # house coal
(15, Fuel.COAL), # anthracite
(12, Fuel.SMOKELESS),
(20, Fuel.WOOD_LOGS),
(23, Fuel.WOOD_PELLETS),
(30, Fuel.ELECTRICITY), # standard tariff
(32, Fuel.ELECTRICITY_OFF_PEAK), # 7-hour tariff
(41, Fuel.HEAT_NETWORK), # heat from electric heat pump (community)
(50, Fuel.HEAT_NETWORK), # electricity for distribution pumping
],
)
def test_table_32_codes_map_to_their_billing_fuel(code: int, fuel: Fuel) -> None:
# Arrange / Act / Assert
assert sap_code_to_fuel(code) == fuel
def test_an_unmapped_code_raises_rather_than_guessing() -> None:
# Arrange — code 10 (dual fuel) has no single billing fuel.
# Act / Assert
with pytest.raises(UnmappedSapCode):
sap_code_to_fuel(10)