diff --git a/epc_data/attributes/MainheatControlAttributes.py b/epc_data/attributes/MainheatControlAttributes.py index 245d274d..be792c0b 100644 --- a/epc_data/attributes/MainheatControlAttributes.py +++ b/epc_data/attributes/MainheatControlAttributes.py @@ -68,9 +68,7 @@ class MainheatControlAttributes: def __init__(self, description: str): self.description: str = clean_description(description.lower()) - self.nodata = not description or any(keyword in self.description for keyword in self.NO_CONTROL_SYSTEM_KEYWORDS) - - if not self.nodata and not any( + if not any( self._keyword_in_description(keywords) for keywords in [ self.THERMOSTATIC_CONTROL_KEYWORDS, @@ -78,7 +76,8 @@ class MainheatControlAttributes: self.SWITCH_SYSTEM_KEYWORDS, self.DHW_CONTROL_KEYWORDS, self.COMMUNITY_HEATING_KEYWORDS, - self.TRVS_KEYWORDS + self.TRVS_KEYWORDS, + self.NO_CONTROL_SYSTEM_KEYWORDS ] ): raise ValueError('Invalid description') @@ -87,6 +86,7 @@ class MainheatControlAttributes: return any(keyword in self.description for keyword in keywords) def process(self) -> Dict[str, Union[str, bool]]: + result: Dict[str, Union[str, bool]] = { "thermostatic_control": self._find_keyword(self.THERMOSTATIC_CONTROL_KEYWORDS), "charging_system": self._find_keyword(self.CHARGING_SYSTEM_KEYWORDS), diff --git a/epc_data/tests/test_mainheat_controls_attributes.py b/epc_data/tests/test_mainheat_controls_attributes.py new file mode 100644 index 00000000..6a0def34 --- /dev/null +++ b/epc_data/tests/test_mainheat_controls_attributes.py @@ -0,0 +1,42 @@ +import pytest +from epc_data.attributes.MainheatControlAttributes import MainheatControlAttributes +from epc_data.tests.test_data.test_mainheat_control_attributes_cases import mainheat_control_cases + + +class TestMainHeatControlAttributes: + + def test_init(self): + # Test initialization with a valid description + valid_description = 'Flat rate charging, no thermostatic control of room temperature' + attr = MainheatControlAttributes(valid_description) + assert attr.description == valid_description.lower() + + # Test initialization with an empty description + with pytest.raises(ValueError): + MainheatControlAttributes('') + + # Test initialization with a description that contains none of the keywords + with pytest.raises(ValueError): + MainheatControlAttributes('description without keywords') + + @pytest.mark.parametrize( + "test_case", + mainheat_control_cases + ) + def test_process_mainheat(self, test_case): + expected_result = test_case.copy() + del expected_result["original_description"] + result = MainheatControlAttributes(test_case['original_description']).process() + assert sorted(result.items()) == sorted(expected_result.items()) + + def test_invalid_description(self): + # Test that invalid descriptions raise a ValueError + invalid_descriptions = [ + "", + "invalid description", + "description with no known heating control types", + ] + + for description in invalid_descriptions: + with pytest.raises(ValueError): + MainheatControlAttributes(description).process()