diff --git a/epc_data/EpcClean.py b/epc_data/EpcClean.py index 7a520264..206697ee 100644 --- a/epc_data/EpcClean.py +++ b/epc_data/EpcClean.py @@ -1,13 +1,13 @@ from typing import List, Dict, Any from collections import Counter -from epc_data.cleaning.Roof import CleanRoof -from epc_data.cleaning.Floor import CleanFloor +from epc_data.attributes.RoofAttributes import RoofAttributes +from epc_data.attributes.FloorAttributes import FloorAttributes class EpcClean: """ - Container for methods which we utilise for cleaning EPC data + Container for methods which we utilise for attributes EPC data """ CLEANING_FIELDS: List[str] = [ @@ -36,9 +36,9 @@ class EpcClean: for field in self.CLEANING_FIELDS: self.unique_vals[field] = Counter([v[field] for v in self.data]) - self.clean_wrapper(field="roof-description", cleaning_cls=CleanRoof) + self.clean_wrapper(field="roof-description", cleaning_cls=RoofAttributes) - # self.clean_wrapper(field="floor-description", cleaning_cls=CleanFloor) + self.clean_wrapper(field="floor-description", cleaning_cls=FloorAttributes) def _init_empty_cleaned_obj(self) -> None: """ diff --git a/epc_data/app.py b/epc_data/app.py index 7e543b2d..4ed726c0 100644 --- a/epc_data/app.py +++ b/epc_data/app.py @@ -40,11 +40,11 @@ def handler(): cleaner.clean() # For testing: - from epc_data.cleaning.Floor import CleanFloor + from epc_data.attributes.FloorAttributes import FloorAttributes descriptions = {x["floor-description"] for x in data} out = [] for description in descriptions: - res = CleanFloor(description).clean() + res = FloorAttributes(description).clean() out.append( { "original_description": description, diff --git a/epc_data/cleaning/Floor.py b/epc_data/attributes/FloorAttributes.py similarity index 97% rename from epc_data/cleaning/Floor.py rename to epc_data/attributes/FloorAttributes.py index 1dd165ab..233aa1fa 100644 --- a/epc_data/cleaning/Floor.py +++ b/epc_data/attributes/FloorAttributes.py @@ -1,8 +1,8 @@ from typing import Dict, Union, Optional -from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description +from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description -class CleanFloor: +class FloorAttributes: def __init__(self, description: str): """ diff --git a/epc_data/cleaning/Roof.py b/epc_data/attributes/RoofAttributes.py similarity index 98% rename from epc_data/cleaning/Roof.py rename to epc_data/attributes/RoofAttributes.py index da620a01..8e7da058 100644 --- a/epc_data/cleaning/Roof.py +++ b/epc_data/attributes/RoofAttributes.py @@ -1,8 +1,8 @@ from typing import Dict, Union, Optional -from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description +from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description -class CleanRoof: +class RoofAttributes: def __init__(self, description): """ diff --git a/epc_data/cleaning/cleaning_utils.py b/epc_data/attributes/attribute_utils.py similarity index 100% rename from epc_data/cleaning/cleaning_utils.py rename to epc_data/attributes/attribute_utils.py diff --git a/epc_data/tests/test_cleaning_utils.py b/epc_data/tests/test_attribute_utils.py similarity index 84% rename from epc_data/tests/test_cleaning_utils.py rename to epc_data/tests/test_attribute_utils.py index d7d867ac..7aeee042 100644 --- a/epc_data/tests/test_cleaning_utils.py +++ b/epc_data/tests/test_attribute_utils.py @@ -1,5 +1,5 @@ import pytest -from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description +from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description def test__extract_thermal_transmittence(): @@ -12,6 +12,6 @@ def test__search_split_roof_description(): assert search_split_description("limited") == "below average" assert search_split_description("no insulation") == "none" assert search_split_description("limited insulation") == "below average" - + with pytest.raises(NotImplementedError): search_split_description("unknown") diff --git a/epc_data/tests/test_data/EpcClean_test_floor_cases.py b/epc_data/tests/test_data/test_floor_attributes_cases.py similarity index 100% rename from epc_data/tests/test_data/EpcClean_test_floor_cases.py rename to epc_data/tests/test_data/test_floor_attributes_cases.py diff --git a/epc_data/tests/test_data/EpcClean_test_roof_cases.py b/epc_data/tests/test_data/test_roof_attributes_cases.py similarity index 100% rename from epc_data/tests/test_data/EpcClean_test_roof_cases.py rename to epc_data/tests/test_data/test_roof_attributes_cases.py diff --git a/epc_data/tests/test_clean_floor.py b/epc_data/tests/test_floor_attributes.py similarity index 72% rename from epc_data/tests/test_clean_floor.py rename to epc_data/tests/test_floor_attributes.py index 0c55b615..2034bffa 100644 --- a/epc_data/tests/test_clean_floor.py +++ b/epc_data/tests/test_floor_attributes.py @@ -1,62 +1,62 @@ import pytest -from epc_data.tests.test_data.EpcClean_test_floor_cases import clean_floor_cases -from epc_data.cleaning.Floor import CleanFloor +from epc_data.tests.test_data.test_floor_attributes_cases import clean_floor_cases +from epc_data.attributes.FloorAttributes import FloorAttributes from unittest.mock import patch class TestEpcClean: class TestCleanFloor: - @patch('epc_data.cleaning.cleaning_utils.search_split_description') + @patch('epc_data.attributes.attribute_utils.search_split_description') def test_find_insulation_thickness_to_unheated_space(self, mock_search_split_description): # Set up the mock to return a specific value mock_search_split_description.return_value = 'average' # clean_floor = CleanFloor('description to unheated space') - insulation_thickness = CleanFloor._find_insulation_thickness( + insulation_thickness = FloorAttributes._find_insulation_thickness( 'to unheated space, insulated', True, False, False, False ) assert insulation_thickness == 'average' - @patch('epc_data.cleaning.cleaning_utils.search_split_description') + @patch('epc_data.attributes.attribute_utils.search_split_description') def test_find_insulation_thickness_to_external_air(self, mock_search_split_description): # Set up the mock to return a specific value mock_search_split_description.return_value = 'below average' # clean_floor = CleanFloor('To external air, limited insulation') - insulation_thickness = CleanFloor._find_insulation_thickness( + insulation_thickness = FloorAttributes._find_insulation_thickness( 'to external air, limited insulation', False, True, False, False ) assert insulation_thickness == 'below average' - @patch('epc_data.cleaning.cleaning_utils.search_split_description') + @patch('epc_data.attributes.attribute_utils.search_split_description') def test_find_insulation_thickness_is_suspended(self, mock_search_split_description): # Set up the mock to return a specific value mock_search_split_description.return_value = 'none' # clean_floor = CleanFloor('description suspended') - insulation_thickness = CleanFloor._find_insulation_thickness( + insulation_thickness = FloorAttributes._find_insulation_thickness( 'suspended, no insulation', False, False, True, False ) assert insulation_thickness == 'none' - @patch('epc_data.cleaning.cleaning_utils.search_split_description') + @patch('epc_data.attributes.attribute_utils.search_split_description') def test_find_insulation_thickness_is_solid(self, mock_search_split_description): # Set up the mock to return a specific value mock_search_split_description.return_value = 'none' # clean_floor = CleanFloor('description solid') - insulation_thickness = CleanFloor._find_insulation_thickness( + insulation_thickness = FloorAttributes._find_insulation_thickness( 'solid, no insulation (assumed)', False, False, False, True ) assert insulation_thickness == 'none' def test_find_insulation_thickness_not_handled(self): - clean_floor = CleanFloor('description not handled') + clean_floor = FloorAttributes('description not handled') with pytest.raises(NotImplementedError): clean_floor._find_insulation_thickness( 'description not handled', False, False, False, False @@ -64,7 +64,7 @@ class TestEpcClean: def test_clean_floor(self): for test_case in clean_floor_cases: - result = CleanFloor(test_case['original_description']).clean() + result = FloorAttributes(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"] diff --git a/epc_data/tests/test_clean_roof.py b/epc_data/tests/test_roof_attributes.py similarity index 84% rename from epc_data/tests/test_clean_roof.py rename to epc_data/tests/test_roof_attributes.py index e802dc75..ef550b75 100644 --- a/epc_data/tests/test_clean_roof.py +++ b/epc_data/tests/test_roof_attributes.py @@ -2,8 +2,8 @@ import pytest import pickle from epc_data.EpcClean import EpcClean from pathlib import Path -from epc_data.tests.test_data.EpcClean_test_roof_cases import clean_roof_test_cases -from epc_data.cleaning.Roof import CleanRoof +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__ == "": @@ -33,10 +33,10 @@ class TestEpcClean: assert all([len(values) == 0 for values in self.cleaner.cleaned.values()]) def test__find_insulation_thickness(self): - assert CleanRoof._find_insulation_thickness("no insulation", False, False, False) == 0 + assert RoofAttributes._find_insulation_thickness("no insulation", False, False, False) == 0 def test_clean_roof(self): - result = CleanRoof('Pitched, 270 mm loft insulation').clean() + result = RoofAttributes('Pitched, 270 mm loft insulation').clean() # change the expected output based on your requirement expected_output = { @@ -57,7 +57,7 @@ class TestEpcClean: assert result == expected_output for test_case in clean_roof_test_cases: - result = CleanRoof(test_case['original_description']).clean() + 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"] @@ -65,7 +65,7 @@ class TestEpcClean: assert result == expected_result def test_clean_roof_with_dwelling_above(self): - result = CleanRoof('(another dwelling above)').clean() + result = RoofAttributes('(another dwelling above)').clean() expected_output = { "is_valid": True,