Model/etl/epc_clean/tests/test_mainheat_attributes.py
2023-10-05 15:09:50 +01:00

48 lines
1.9 KiB
Python

import pytest
from model_data.epc_attributes.MainheatAttributes import MainHeatAttributes
from model_data.tests.test_data.test_mainheat_attributes_cases import mainheat_cases
class TestMainHeatAttributes:
def test_init(self):
# Test initialization with a valid description
valid_description = 'Room heaters, electric, Room heaters, mains gas'
floor_attr = MainHeatAttributes(valid_description)
assert floor_attr.description == valid_description.lower()
# Test initialization with an empty description
with pytest.raises(ValueError):
MainHeatAttributes('')
# Test initialization with a description that contains none of the keywords
with pytest.raises(ValueError):
MainHeatAttributes('description without keywords')
@pytest.mark.parametrize(
"test_case",
mainheat_cases
)
def test_process_mainheat(self, test_case):
expected_result = test_case.copy()
del expected_result["original_description"]
result = MainHeatAttributes(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 data_types",
]
for description in invalid_descriptions:
with pytest.raises(ValueError):
MainHeatAttributes(description).process()