Model/epc_data/tests/test_roof_attributes.py
2023-06-09 09:40:53 +01:00

85 lines
2.9 KiB
Python

import pytest
import pickle
from epc_data.EpcClean import EpcClean
from pathlib import Path
from epc_data.tests.test_data.test_roof_attributes_cases import clean_roof_test_cases
from epc_data.attributes.RoofAttributes import RoofAttributes
# For local testing
if __file__ == "<input>":
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'
class TestEpcClean:
@staticmethod
def load_data(path):
with open(path, "rb") as file:
return pickle.load(file)
@pytest.fixture(autouse=True)
def setup_class(self):
self.cleaner = EpcClean(self.load_data(input_data_path))
def test_clean(self):
self.cleaner.clean()
assert len(self.cleaner.cleaned["roof-description"]) == len(self.cleaner.unique_vals["roof-description"])
def test__init_empty_cleaned_obj(self):
self.cleaner._init_empty_cleaned_obj()
assert all([len(values) == 0 for values in self.cleaner.cleaned.values()])
def test__find_insulation_thickness(self):
assert RoofAttributes._find_insulation_thickness("no insulation", False, False, False) == 0
def test_clean_roof(self):
result = RoofAttributes('Pitched, 270 mm loft insulation').clean()
# change the expected output based on your requirement
expected_output = {
"is_valid": True,
"at_rafters": False,
"is_pitched": True,
"is_roof_room": False,
"has_loft": True,
"insulation_thickness": 270,
"has_dwelling_above": False,
"assumed": False,
"is_flat": False,
"is_thatched": False,
"thermal_transmittence": None,
"thermal_transmittence_unit": None
}
assert result == expected_output
for test_case in clean_roof_test_cases:
result = RoofAttributes(test_case['original_description']).clean()
# Ensure the output ordering is correct
expected_result = {key: test_case[key] for key in result.keys()}
expected_result["desc"] = test_case["original_description"]
result["desc"] = test_case["original_description"]
assert result == expected_result
def test_clean_roof_with_dwelling_above(self):
result = RoofAttributes('(another dwelling above)').clean()
expected_output = {
"is_valid": True,
"at_rafters": False,
"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