diff --git a/etl/epc/tests/test_epcrecord.py b/etl/epc/tests/test_epcrecord.py index bc484d74..9dc2c01b 100644 --- a/etl/epc/tests/test_epcrecord.py +++ b/etl/epc/tests/test_epcrecord.py @@ -2,11 +2,16 @@ import pickle import pytest from etl.epc.Record import EPCRecord from etl.epc.settings import DATA_ANOMALY_MATCHES -import random class TestEpcRecord: + @pytest.fixture + def base_record(self): + record = EPCRecord(run_mode="training") + record._prepared_epc = {} + return record + @pytest.fixture() def cleaning_data(self): with open("recommendations/tests/test_data/cleaning_data.pkl", "rb") as f: @@ -17,163 +22,84 @@ class TestEpcRecord: @pytest.fixture() def epc_records_1(self): epc_records_1 = { - 'original_epc': { - 'low-energy-fixed-light-count': '', 'address': '139 School Road, Hall Green', - 'uprn-source': 'Energy Assessor', 'floor-height': '2.6', 'heating-cost-potential': '1138', - 'unheated-corridor-length': '', 'hot-water-cost-potential': '175', - 'construction-age-band': 'England and Wales: 1900-1929', 'potential-energy-rating': 'B', - 'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Average', 'lighting-energy-eff': 'Very Good', - 'environment-impact-potential': '82', 'glazed-type': 'double glazing, unknown install date', - 'heating-cost-current': '2711', 'address3': '', - 'mainheatcont-description': 'Programmer, TRVs and bypass', - 'sheating-energy-eff': 'N/A', 'property-type': 'House', 'local-authority-label': 'Birmingham', - 'fixed-lighting-outlets-count': '11', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', - 'hot-water-cost-current': '310', 'county': '', 'postcode': 'B28 8JF', 'solar-water-heating-flag': 'N', - 'constituency': 'E14000562', 'co2-emissions-potential': '2.0', 'number-heated-rooms': '4', - 'floor-description': 'Suspended, no insulation (assumed)', 'energy-consumption-potential': '107', - 'local-authority': 'E08000025', 'built-form': 'Semi-Detached', 'number-open-fireplaces': '0', - 'windows-description': 'Fully double glazed', 'glazed-area': 'Normal', 'inspection-date': '2023-07-05', - 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '65', 'address1': '139 School Road', - 'heat-loss-corridor': '', 'flat-storey-count': '', 'constituency-label': 'Birmingham, Hall Green', - 'roof-energy-eff': 'Average', 'total-floor-area': '103.0', 'building-reference-number': '10004697322', - 'environment-impact-current': '43', 'co2-emissions-current': '6.7', - 'roof-description': 'Pitched, 100 mm loft insulation', 'floor-energy-eff': 'N/A', - 'number-habitable-rooms': '4', 'address2': 'Hall Green', 'hot-water-env-eff': 'Good', - 'posttown': 'BIRMINGHAM', 'mainheatc-energy-eff': 'Average', 'main-fuel': 'mains gas (not community)', - 'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Average', 'floor-env-eff': 'N/A', - 'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 82% of fixed outlets', - 'roof-env-eff': 'Average', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', - 'lighting-cost-potential': '182', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '100', - 'main-heating-controls': '', 'lodgement-datetime': '2023-07-13 08:23:07', 'flat-top-storey': '', - 'current-energy-rating': 'E', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', - 'transaction-type': 'rental', 'uprn': '100070505235', 'current-energy-efficiency': '51', - 'energy-consumption-current': '366', 'mainheat-description': 'Boiler and radiators, mains gas', - 'lighting-cost-current': '182', 'lodgement-date': '2023-07-13', 'extension-count': '0', - 'mainheatc-env-eff': 'Average', - 'lmk-key': 'c1d137711da433fb3cced74b1a6848da8bbc1159d076455d26d7b4668982601e', - 'wind-turbine-count': '0', - 'tenure': 'Rented (social)', 'floor-level': '', 'potential-energy-efficiency': '84', - 'hot-water-energy-eff': 'Good', 'low-energy-lighting': '82', - 'walls-description': 'Solid brick, as built, no insulation (assumed)', - 'hotwater-description': 'From main system'}, 'full_sap_epc': {}, 'old_data': [] + "original_epc": { + "fixed-lighting-outlets-count": "11", + "property-type": "House", + "built-form": "Semi-Detached", + "construction-age-band": "England and Wales: 1900-1929", + "local-authority": "E08000025", + "number-habitable-rooms": "4", + "number-heated-rooms": "4", + }, + "full_sap_epc": {}, + "old_data": [], } return epc_records_1 - def test_clean_mechanical_ventilation(self, cleaning_data, epc_records_1): - # We have an epc with Natural ventilation - the resulting epc should also have natural ventulation - + def test_clean_built_form_valid_remap(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "mechanical-ventilation": "natural" - } - record._clean_ventilation() - assert record._prepared_epc["mechanical-ventilation"] == "natural" - - record2 = EPCRecord(cleaning_data=cleaning_data) - record2._prepared_epc = { - "mechanical-ventilation": "" - } - - record2._clean_ventilation() - - assert record2._prepared_epc["mechanical-ventilation"] is None - - record3 = EPCRecord(cleaning_data=cleaning_data) - record3._prepared_epc = { - "mechanical-ventilation": None - } - - record3._clean_ventilation() - - assert record3._prepared_epc["mechanical-ventilation"] is None - - record4 = EPCRecord(cleaning_data=cleaning_data) - record4._prepared_epc = { - "mechanical-ventilation": "INVALID" - } - - record4._clean_ventilation() - - assert record4._prepared_epc["mechanical-ventilation"] is None - - def test_clean_energy_valid_values(self, cleaning_data, epc_records_1): - record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "energy-consumption-current": "200", - "co2-emissions-current": "5.5" - } - record._clean_energy() - - assert record._prepared_epc["energy-consumption-current"] == 200.0 - assert record._prepared_epc["co2-emissions-current"] == 5.5 - - def test_clean_energy_empty_values(self, cleaning_data): - # We cannot have invalid values so this should raise an exception - record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "energy-consumption-current": "", - "co2-emissions-current": "" - } - - with pytest.raises(ValueError): - record._clean_energy() - - def test_clean_built_form_valid_remap(self, cleaning_data, epc_records_1): - record = EPCRecord(cleaning_data=cleaning_data) - # Assuming "Semi" should be remapped to "Semi-Detached" record._prepared_epc = { "built-form": "Semi-Detached", - "property-type": "Flat" # Assuming this affects the remapping + "property-type": "Flat" } + record._clean_built_form() assert record._prepared_epc["built-form"] == "Semi-Detached" - def test_clean_built_form_anomaly(self, cleaning_data, epc_records_1): + def test_clean_built_form_anomaly(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) record._prepared_epc = { "built-form": "", "property-type": "Flat" } + record._clean_built_form() assert record._prepared_epc["built-form"] == "End-Terrace" def test_clean_floor_area_valid(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) + record._prepared_epc = { "total-floor-area": "120.5" } + record._clean_floor_area() assert record._prepared_epc["total-floor-area"] == 120.5 def test_clean_floor_area_empty(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) + record._prepared_epc = { "total-floor-area": "" } - # We have no known case of missing floor area + with pytest.raises(ValueError): record._clean_floor_area() def test_clean_heat_loss_corridor_valid(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) + record._prepared_epc = { "heat-loss-corridor": "unheated corridor", "unheated-corridor-length": "" } + record._clean_heat_loss_corridor() assert record._prepared_epc["heat-loss-corridor"] == "unheated corridor" record = EPCRecord(cleaning_data=cleaning_data) + record._prepared_epc = { "heat-loss-corridor": "unheated corridor", "unheated-corridor-length": None } + record._clean_heat_loss_corridor() assert record._prepared_epc["heat-loss-corridor"] == "unheated corridor" @@ -181,46 +107,23 @@ class TestEpcRecord: def test_clean_heat_loss_corridor_anomaly(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) - # Assuming "InvalidCorridor" is an anomaly + record._prepared_epc = { "heat-loss-corridor": "InvalidCorridor", "unheated-corridor-length": "" } + record._clean_heat_loss_corridor() assert record._prepared_epc["heat-loss-corridor"] == "no corridor" - def test_clean_mains_gas_valid(self, cleaning_data): - record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "mains-gas-flag": "Y" - } - record._clean_mains_gas() - - assert record._prepared_epc["mains-gas-flag"] is True - - def test_clean_mains_gas_anomaly(self, cleaning_data): - record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "mains-gas-flag": "InvalidValue" - } - # It should always be Y or N or an anomally value - with pytest.raises(KeyError): - record._clean_mains_gas() - - record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "mains-gas-flag": random.choice(list(DATA_ANOMALY_MATCHES)) - } - record._clean_mains_gas() - - assert record._prepared_epc["mains-gas-flag"] is None - def test_clean_solar_hot_water_valid(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) + record._prepared_epc = { "solar-water-heating-flag": "Y" } + record._clean_solar_hot_water() assert record._prepared_epc["solar-water-heating-flag"] == "Y" @@ -228,9 +131,11 @@ class TestEpcRecord: def test_clean_solar_hot_water_empty(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) + record._prepared_epc = { "solar-water-heating-flag": "" } + record._clean_solar_hot_water() assert record._prepared_epc["solar-water-heating-flag"] == "N" @@ -238,16 +143,20 @@ class TestEpcRecord: def test_clean_number_lighting_outlets_valid(self, cleaning_data, epc_records_1): record = EPCRecord(cleaning_data=cleaning_data, epc_records=epc_records_1) + record._prepared_epc = { "fixed-lighting-outlets-count": "5" } + record._clean_number_lighting_outlets() assert record._prepared_epc["fixed-lighting-outlets-count"] == 5.0 - def test_clean_number_lighting_outlets_empty(self, cleaning_data, epc_records_1): + def test_clean_number_lighting_outlets_empty(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) + record.run_mode = "newdata" + record._prepared_epc = { "fixed-lighting-outlets-count": "", "property-type": "Flat", @@ -257,35 +166,18 @@ class TestEpcRecord: "number-habitable-rooms": "4", "number-heated-rooms": "4", } + record.old_data = [] - record.full_sap_epc = [] + record.full_sap_epc = {} + record._clean_number_lighting_outlets() assert record._prepared_epc["fixed-lighting-outlets-count"] == 10 - def test_clean_count_variables(self, cleaning_data): - record = EPCRecord(cleaning_data=cleaning_data) - - record._prepared_epc = { - "number-open-fireplaces": "1", - "extension-count": None, - "flat-storey-count": "", - "number-habitable-rooms": "INVALID!", - } - - record._clean_count_variables() - - assert record._prepared_epc["number-open-fireplaces"] == 1.0 - assert record._prepared_epc["extension-count"] == 0 - assert record._prepared_epc["flat-storey-count"] is None - assert record._prepared_epc["number-habitable-rooms"] is None - def test_clean_floor_level(self, cleaning_data): record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "floor-level": "1", - } + record._prepared_epc = {"floor-level": "1"} record._clean_floor_level() @@ -293,69 +185,12 @@ class TestEpcRecord: record = EPCRecord(cleaning_data=cleaning_data) - record._prepared_epc = { - "floor-level": "", - } + record._prepared_epc = {"floor-level": ""} record._clean_floor_level() assert record._prepared_epc["floor-level"] is None - record = EPCRecord(cleaning_data=cleaning_data) - - record._prepared_epc = { - "floor-level": None, - } - - record._clean_floor_level() - - assert record._prepared_epc["floor-level"] is None - - def test_clean_solar_hot_water(self, cleaning_data): - record = EPCRecord(cleaning_data=cleaning_data) - - record._prepared_epc = { - "solar-water-heating-flag": "Y", - } - - record._clean_solar_hot_water() - - assert record._prepared_epc["solar-water-heating-flag"] == "Y" - assert record.solar_water_heating_flag_bool is True - - record = EPCRecord(cleaning_data=cleaning_data) - - record._prepared_epc = { - "solar-water-heating-flag": "N", - } - - record._clean_solar_hot_water() - - assert record._prepared_epc["solar-water-heating-flag"] == "N" - assert record.solar_water_heating_flag_bool is False - - record = EPCRecord(cleaning_data=cleaning_data) - - record._prepared_epc = { - "solar-water-heating-flag": "", - } - - record._clean_solar_hot_water() - - assert record._prepared_epc["solar-water-heating-flag"] == "N" - assert record.solar_water_heating_flag_bool is False - - record = EPCRecord(cleaning_data=cleaning_data) - - record._prepared_epc = { - "solar-water-heating-flag": None, - } - - record._clean_solar_hot_water() - - assert record._prepared_epc["solar-water-heating-flag"] == "N" - assert record.solar_water_heating_flag_bool is False - def test_year_built(self, cleaning_data): # This test handles a specific test case # Mock the property object @@ -417,161 +252,60 @@ class TestEpcRecord: assert prepared_epc.get("year_built") == 1900 - def test_casting(self, cleaning_data): - # Tests expected type casting, against previously hard-coded expectations to ensure that the - # expected types are correct and that we don't accidentally change them in future - - test_epc_records = { - 'original_epc': { - 'uprn': '100023417525', 'county': 'Greater London Authority', 'tenure': 'rental (social)', - 'address': '31 Mimosa House, Larch Crescent', - 'lmk-key': '201660309922019061719223615438661', 'address1': '31 Mimosa House', - 'address2': 'Larch Crescent', 'address3': '', 'postcode': 'UB4 9DH', 'posttown': 'HAYES', - 'main-fuel': 'mains gas (not community)', 'built-form': 'Mid-Terrace', 'floor-level': 2, - 'glazed-area': 'Normal', 'glazed-type': 'double glazing, unknown install date', - 'report-type': '100', 'uprn-source': 'Address Matched', 'constituency': 'E14000737', - 'floor-height': 2.39, 'photo-supply': None, 'roof-env-eff': 'Average', - 'energy-tariff': 'Single', 'floor-env-eff': 'N/A', 'property-type': 'Maisonette', - 'walls-env-eff': 'Average', 'lodgement-date': '2019-06-17', 'mains-gas-flag': True, - 'extension-count': 0, 'flat-top-storey': 'Y', 'inspection-date': '2019-06-17', - 'local-authority': 'E09000017', 'roof-energy-eff': 'Average', 'windows-env-eff': 'Average', - 'floor-energy-eff': 'NO DATA!', 'lighting-env-eff': 'Good', 'mainheat-env-eff': 'Good', - 'roof-description': 'Pitched, 100 mm loft insulation', 'sheating-env-eff': 'N/A', - 'total-floor-area': 67.0, 'transaction-type': 'rental (social)', - 'walls-energy-eff': 'Average', 'flat-storey-count': None, - 'floor-description': '(another dwelling below)', 'hot-water-env-eff': 'Good', - 'mainheatc-env-eff': 'Average', 'walls-description': 'Cavity wall, filled cavity', - 'constituency-label': 'Hayes and Harlington', 'heat-loss-corridor': 'no corridor', - 'lodgement-datetime': '2019-06-17 19:22:36', 'wind-turbine-count': 0, - 'windows-energy-eff': 'Average', 'lighting-energy-eff': 'Good', - 'low-energy-lighting': '67', 'mainheat-energy-eff': 'Good', 'number-heated-rooms': 3.0, - 'sheating-energy-eff': 'N/A', 'windows-description': 'Fully double glazed', - 'heating-cost-current': '310', 'hot-water-energy-eff': 'Good', - 'hotwater-description': 'From main system', - 'lighting-description': 'Low energy lighting in 67% of fixed outlets', - 'mainheat-description': 'Boiler and radiators, mains gas', - 'mainheatc-energy-eff': 'Average', 'co2-emissions-current': 2.1, - 'construction-age-band': 'England and Wales: 1950-1966', 'current-energy-rating': 'C', - 'lighting-cost-current': '70', 'local-authority-label': 'Hillingdon', - 'main-heating-controls': '2104', 'heating-cost-potential': '265', - 'hot-water-cost-current': '136', 'mechanical-ventilation': 'natural', - 'multi-glaze-proportion': '100', 'number-habitable-rooms': 3.0, - 'number-open-fireplaces': 0, 'secondheat-description': 'None', - 'co2-emissions-potential': 1.7, 'lighting-cost-potential': '53', - 'potential-energy-rating': 'C', 'hot-water-cost-potential': '106', - 'mainheatcont-description': 'Programmer and room thermostat', - 'solar-water-heating-flag': 'N', 'unheated-corridor-length': None, - 'building-reference-number': '6110075568', 'current-energy-efficiency': 73, - 'energy-consumption-current': 180.0, 'environment-impact-current': '72', - 'potential-energy-efficiency': 77, 'energy-consumption-potential': '141', - 'environment-impact-potential': '78', 'fixed-lighting-outlets-count': 9, - 'low-energy-fixed-light-count': '', 'co2-emiss-curr-per-floor-area': '32' - }, - 'full_sap_epc': {}, - 'old_data': [ - {'uprn': '100023417525', 'county': 'Greater London Authority', 'tenure': 'rental (social)', - 'address': '31 Mimosa House, Larch Crescent', 'lmk-key': '201660300922008121514105815828768', - 'address1': '31 Mimosa House', 'address2': 'Larch Crescent', 'address3': '', 'postcode': 'UB4 9DH', - 'posttown': 'HAYES', - 'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used', - 'built-form': 'Mid-Terrace', 'floor-level': '2nd', 'glazed-area': 'Normal', - 'glazed-type': 'double glazing, unknown install date', 'report-type': '100', - 'uprn-source': 'Address Matched', 'constituency': 'E14000737', 'floor-height': '2.36', - 'photo-supply': '0.0', 'roof-env-eff': 'Good', 'energy-tariff': 'Single', 'floor-env-eff': 'N/A', - 'property-type': 'Flat', 'walls-env-eff': 'Poor', 'lodgement-date': '2008-12-15', - 'mains-gas-flag': 'Y', 'extension-count': '0', 'flat-top-storey': 'Y', 'inspection-date': '2008-12-12', - 'local-authority': 'E09000017', 'roof-energy-eff': 'Good', 'windows-env-eff': 'Average', - 'floor-energy-eff': 'N/A', 'lighting-env-eff': 'Good', 'mainheat-env-eff': 'Good', - 'roof-description': 'Pitched, 150 mm loft insulation', 'sheating-env-eff': 'N/A', - 'total-floor-area': '69.8', 'transaction-type': 'rental (social)', 'walls-energy-eff': 'Poor', - 'flat-storey-count': '4.0', 'floor-description': '(other premises below)', 'hot-water-env-eff': 'Good', - 'mainheatc-env-eff': 'Poor', 'walls-description': 'Cavity wall, as built, no insulation (assumed)', - 'constituency-label': 'Hayes and Harlington', 'heat-loss-corridor': 'no corridor', - 'lodgement-datetime': '2008-12-15 14:10:58', 'wind-turbine-count': '0', - 'windows-energy-eff': 'Average', 'lighting-energy-eff': 'Good', 'low-energy-lighting': '56', - 'mainheat-energy-eff': 'Good', 'number-heated-rooms': '3', 'sheating-energy-eff': 'N/A', - 'windows-description': 'Fully double glazed', 'heating-cost-current': '315', - 'hot-water-energy-eff': 'Good', 'hotwater-description': 'From main system', - 'lighting-description': 'Low energy lighting in 56% of fixed outlets', - 'mainheat-description': 'Boiler and radiators, mains gas', 'mainheatc-energy-eff': 'Poor', - 'co2-emissions-current': '2.8', 'construction-age-band': 'England and Wales: 1967-1975', - 'current-energy-rating': 'C', 'lighting-cost-current': '46', 'local-authority-label': 'Hillingdon', - 'main-heating-controls': '2104', 'heating-cost-potential': '207', 'hot-water-cost-current': '119', - 'mechanical-ventilation': 'natural', 'multi-glaze-proportion': '100', 'number-habitable-rooms': '3', - 'number-open-fireplaces': '0', 'secondheat-description': 'None', 'co2-emissions-potential': '1.7', - 'lighting-cost-potential': '32', 'potential-energy-rating': 'B', 'hot-water-cost-potential': '96', - 'mainheatcont-description': 'Programmer and room thermostat', 'solar-water-heating-flag': 'N', - 'unheated-corridor-length': '', 'building-reference-number': '6110075568', - 'current-energy-efficiency': '71', 'energy-consumption-current': '239', - 'environment-impact-current': '67', 'potential-energy-efficiency': '82', - 'energy-consumption-potential': '148', 'environment-impact-potential': '80', - 'fixed-lighting-outlets-count': '', 'low-energy-fixed-light-count': '', - 'co2-emiss-curr-per-floor-area': '40'} - ] + def test_cleaning_rules_energy(self, base_record): + base_record._prepared_epc = { + "energy-consumption-current": "150", + "co2-emissions-current": "32.5" } - record = EPCRecord( - epc_records=test_epc_records, - run_mode="newdata", - cleaning_data=cleaning_data - ) + base_record._apply_cleaning_rules() - expected_types = { - "uprn": int, - "walls_description": str, - "floor_description": str, - "lighting_description": str, - "roof_description": str, - "mainheat_description": str, - "hotwater_description": str, - "main_fuel": str, - "mechanical_ventilation": str, - "secondheat_description": str, - "windows_description": str, - "glazed_type": str, - "multi_glaze_proportion": float, - "low_energy_lighting": float, - "number_open_fireplaces": float, - "mainheatcont_description": str, - "solar_water_heating_flag": str, - "photo_supply": float, - "transaction_type": str, - "energy_tariff": str, - "extension_count": float, - "total_floor_area": float, - "floor_height": float, - "hot_water_energy_eff": str, - "floor_energy_eff": None, # THe input is NO DATA so we map to None - "windows_energy_eff": str, - "walls_energy_eff": str, - "sheating_energy_eff": None, - "roof_energy_eff": str, - "mainheat_energy_eff": str, - "mainheatc_energy_eff": str, - "lighting_energy_eff": str, - "lighting_cost_current": float, - "heating_cost_current": float, - "hot_water_cost_current": float, - "potential_energy_efficiency": float, - "environment_impact_potential": float, - "energy_consumption_potential": float, - "co2_emissions_potential": float, - "lodgement_date": str, - "current_energy_efficiency": int, - "energy_consumption_current": int, - "co2_emissions_current": float, - "number_habitable_rooms": float, - "number_heated_rooms": float, - "is_post_sap10": bool, + assert base_record._prepared_epc["energy-consumption-current"] == 150.0 + assert base_record._prepared_epc["co2-emissions-current"] == 32.5 + + def test_cleaning_rules_energy_anomaly(self, base_record): + base_record._prepared_epc = { + "energy-consumption-current": "INVALID", + "co2-emissions-current": "INVALID" } - for field, expected_type in expected_types.items(): - value = getattr(record, field) + base_record._apply_cleaning_rules() - if expected_type is None: - assert value is None, f"{field} expected to be None, got {value}" - continue + assert base_record._prepared_epc["energy-consumption-current"] == "INVALID" + assert base_record._prepared_epc["co2-emissions-current"] == "INVALID" - assert isinstance( - value, expected_type - ), f"{field} expected {expected_type}, got {type(value)}" + def test_cleaning_rules_mains_gas(self, base_record): + base_record._prepared_epc = { + "mains-gas-flag": "Y" + } + + base_record._apply_cleaning_rules() + + assert base_record._prepared_epc["mains-gas-flag"] is True + + def test_cleaning_rules_mains_gas_anomaly(self, base_record): + base_record._prepared_epc = { + "mains-gas-flag": "INVALID" + } + + base_record._apply_cleaning_rules() + + assert base_record._prepared_epc["mains-gas-flag"] is None + + def test_cleaning_rules_wind_turbine(self, base_record): + base_record._prepared_epc = { + "wind-turbine-count": "3" + } + + base_record._apply_cleaning_rules() + + assert base_record._prepared_epc["wind-turbine-count"] == 3 + + def test_cleaning_rules_extension_count(self, base_record): + base_record._prepared_epc = { + "extension-count": "2" + } + + base_record._apply_cleaning_rules() + + assert base_record._prepared_epc["extension-count"] == 2