Model/etl/epc_clean/tests/test_mainheat_controls_attributes.py
2026-01-22 22:56:58 +00:00

71 lines
3 KiB
Python

import pytest
from etl.epc_clean.epc_attributes.MainheatControlAttributes import MainheatControlAttributes
from etl.epc_clean.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 a description that contains none of the keywords
with pytest.raises(ValueError):
MainheatControlAttributes('description without keywords')
def test_empty_str(self):
assert MainheatControlAttributes("").process() == {
'thermostatic_control': False, 'charging_system': False, 'switch_system': False, 'no_control': False,
'dhw_control': False, 'community_heating': False, 'multiple_room_thermostats': False,
'auxiliary_systems': False, 'trvs': False, 'rate_control': False
}
assert set(list(MainheatControlAttributes("").process().values())) == {False}
@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()
# Some of the expected_result test data was produced before some attributes were added to the code
# base so we need to filter out some of the keys. The test is still valid
result = {k: v for k, v in result.items() if v}
expected_result = {k: v for k, v in expected_result.items() if v}
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 data_types",
]
for description in invalid_descriptions:
with pytest.raises(ValueError):
MainheatControlAttributes(description).process()
def test_process_with_no_data(self):
# Create an instance of MainheatControlAttributes with no description
attributes = MainheatControlAttributes(description="")
# Call the process method
result = attributes.process()
# Assert that the result matches the expected dictionary
assert result == {
"thermostatic_control": False,
"charging_system": False,
"switch_system": False,
"no_control": False,
"dhw_control": False,
"community_heating": False,
"multiple_room_thermostats": False,
"auxiliary_systems": False,
"trvs": False,
"rate_control": False
}