from __future__ import annotations import pytest from domain.fuel_rates.fuel import Fuel from domain.billing.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 @pytest.mark.parametrize( ("api_code", "fuel"), [ (26, Fuel.MAINS_GAS), # gov-API mains-gas enum -> Table 32 code 1 (0, Fuel.ELECTRICITY), # API "electricity" -> Table 32 code 30 (25, Fuel.HEAT_NETWORK), # API community heat -> Table 32 code 41 (14, Fuel.COAL), # API house coal -> Table 32 code 11 ], ) def test_raw_api_fuel_codes_normalize_before_mapping(api_code: int, fuel: Fuel) -> None: # Arrange — the calculator may carry a raw gov-API fuel code (not yet a Table # 32 code); sap_code_to_fuel normalizes via the calculator's own helper first. # Act / Assert assert sap_code_to_fuel(api_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)