Added unit tests for heating controls

This commit is contained in:
Khalim Conn-Kowlessar 2023-06-14 16:54:38 +01:00
parent ddd557f20b
commit 6b2adcb58e
2 changed files with 46 additions and 4 deletions

View file

@ -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),

View file

@ -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()