import pytest import pickle from epc_data.EpcClean import EpcClean from pathlib import Path # For local testing if __file__ == "": input_data_path = Path("./epc_data/tests/test_data/EpcClean_inputs.obj") else: current_file_path = Path(__file__) input_data_path = current_file_path.parent / 'test_data' / 'EpcClean_inputs.obj' # # @pytest.fixture # def data(): # print("WOW") # print(input_data_path) # with open(input_data_path, 'rb') as f: # data = pickle.load(f) # return data # # # def test_clean(data): # epc = EpcClean(data) # epc.clean() # assert len(epc.cleaned["roof-description"]) == len(epc.unique_vals["roof-description"]) # # # def test_clean_roof(data): # epc = EpcClean(data) # result = epc.clean_roof('Pitched, 270 mm loft insulation') # # # change the expected output based on your requirement # expected_output = { # "is_pitched": True, # "is_roof_room": False, # "has_loft": True, # "insulation_thickness": 270, # "has_dwelling_above": False, # "assumed": False, # "is_flat": False, # "thermal_transmittence": None, # "thermal_transmittence_unit": None # } # # assert result == expected_output # # # def test_clean_roof_with_dwelling_above(data): # epc = EpcClean(data) # result = epc.clean_roof('(another dwelling above)') # # expected_output = { # "is_pitched": False, # "is_roof_room": False, # "has_loft": False, # "insulation_thickness": 0, # "has_dwelling_above": True, # "assumed": False, # "is_flat": False, # "is_thatched": False, # "thermal_transmittence": None, # "thermal_transmittence_unit": None, # } # # assert result == expected_output class TestEpcClean: @pytest.fixture(autouse=True) def load_data(self): with open(input_data_path, "rb") as file: self.data = pickle.load(file) self.ec = EpcClean(self.data) def test_clean(self): self.ec.clean() assert len(self.ec.cleaned["roof-description"]) == len(self.ec.unique_vals["roof-description"]) def test__init_empty_cleaned_obj(self): self.ec._init_empty_cleaned_obj() assert all([len(values) == 0 for values in self.ec.cleaned.values()]) def test__search_split_roof_description(self): assert self.ec._search_split_roof_description("insulated") == "average" assert self.ec._search_split_roof_description("limited") == "below average" with pytest.raises(NotImplementedError): self.ec._search_split_roof_description("unknown") def test__find_insulation_thickness(self): assert self.ec._find_insulation_thickness("no insulation", False, False, False) == 0 def test__extract_thermal_transmittence(self): description = "U-value of 2.3 w/m-¦k" assert self.ec._extract_thermal_transmittence(description) == (2.3, "w/m-¦k") def test_clean_roof(self): result = self.ec.clean_roof('Pitched, 270 mm loft insulation') # change the expected output based on your requirement expected_output = { "is_pitched": True, "is_roof_room": False, "has_loft": True, "insulation_thickness": 270, "has_dwelling_above": False, "assumed": False, "is_flat": False, "thermal_transmittence": None, "thermal_transmittence_unit": None } assert result == expected_output def test_clean_roof_with_dwelling_above(self): result = self.ec.clean_roof('(another dwelling above)') expected_output = { "is_pitched": False, "is_roof_room": False, "has_loft": False, "insulation_thickness": 0, "has_dwelling_above": True, "assumed": False, "is_flat": False, "is_thatched": False, "thermal_transmittence": None, "thermal_transmittence_unit": None, } assert result == expected_output