mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
added testing for main fuel attributes class
This commit is contained in:
parent
8e7c39a823
commit
fc15cce5bb
3 changed files with 95 additions and 0 deletions
|
|
@ -108,6 +108,8 @@ def remove_punctuation(text: str) -> str:
|
|||
|
||||
text_without_punctuation = remove_double_spaces(text_without_punctuation)
|
||||
|
||||
text_without_punctuation = text_without_punctuation.strip()
|
||||
|
||||
return text_without_punctuation
|
||||
|
||||
|
||||
|
|
|
|||
56
epc_data/tests/test_data/test_main_fuel_attributes_cases.py
Normal file
56
epc_data/tests/test_data/test_main_fuel_attributes_cases.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
mainfuel_cases = [
|
||||
{'original_description': '', 'fuel_type': 'unknown', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'Electricity: electricity, unspecified tariff', 'fuel_type': 'electricity',
|
||||
'tariff_type': 'unspecified tariff', 'is_community': False, 'no_individual_heating_or_community_network': False,
|
||||
'complex_fuel_type': None},
|
||||
{'original_description': 'Gas: mains gas', 'fuel_type': 'mains gas', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'LPG (community)', 'fuel_type': 'lpg', 'tariff_type': None, 'is_community': True,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'LPG (not community)', 'fuel_type': 'lpg', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None}, {
|
||||
'original_description': 'To be used only when there is no heating/hot-water system or data is from a '
|
||||
'community network',
|
||||
'fuel_type': 'unknown', 'tariff_type': None, 'is_community': True,
|
||||
'no_individual_heating_or_community_network': True, 'complex_fuel_type': None},
|
||||
{'original_description': 'anthracite', 'fuel_type': 'anthracite', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'biogas (not community)', 'fuel_type': 'biogas', 'tariff_type': None,
|
||||
'is_community': False, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'biomass (community)', 'fuel_type': 'biomass', 'tariff_type': None, 'is_community': True,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'bottled LPG', 'fuel_type': 'lpg', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'dual fuel - mineral + wood', 'fuel_type': 'dual fuel mineral wood', 'tariff_type': None,
|
||||
'is_community': False, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'electricity (community)', 'fuel_type': 'electricity', 'tariff_type': None,
|
||||
'is_community': True, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'electricity (not community)', 'fuel_type': 'electricity', 'tariff_type': None,
|
||||
'is_community': False, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'from heat network data (community)', 'fuel_type': 'heat network', 'tariff_type': None,
|
||||
'is_community': True, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'heat from boilers using biodiesel from any biomass source (community)',
|
||||
'fuel_type': 'biodiesel', 'tariff_type': None, 'is_community': True,
|
||||
'no_individual_heating_or_community_network': False,
|
||||
'complex_fuel_type': 'heat from boilers using biodiesel from any biomass source'},
|
||||
{'original_description': 'house coal (not community)', 'fuel_type': 'house coal', 'tariff_type': None,
|
||||
'is_community': False, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'mains gas (community)', 'fuel_type': 'mains gas', 'tariff_type': None,
|
||||
'is_community': True, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'mains gas (not community)', 'fuel_type': 'mains gas', 'tariff_type': None,
|
||||
'is_community': False, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'oil (community)', 'fuel_type': 'oil', 'tariff_type': None, 'is_community': True,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'oil (not community)', 'fuel_type': 'oil', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'smokeless coal', 'fuel_type': 'smokeless coal', 'tariff_type': None,
|
||||
'is_community': False, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'waste combustion (community)', 'fuel_type': 'waste combustion', 'tariff_type': None,
|
||||
'is_community': True, 'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'waste combustion - this is for backwards compatibility only and should not be used',
|
||||
'fuel_type': 'waste combustion', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None},
|
||||
{'original_description': 'wood logs', 'fuel_type': 'wood logs', 'tariff_type': None, 'is_community': False,
|
||||
'no_individual_heating_or_community_network': False, 'complex_fuel_type': None}
|
||||
]
|
||||
37
epc_data/tests/test_mainfuel_attributes.py
Normal file
37
epc_data/tests/test_mainfuel_attributes.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import pytest
|
||||
from epc_data.attributes.MainFuelAttributes import MainFuelAttributes
|
||||
from epc_data.tests.test_data.test_main_fuel_attributes_cases import mainfuel_cases
|
||||
|
||||
|
||||
class TestMainHeatControlAttributes:
|
||||
|
||||
def test_init(self):
|
||||
# Test initialization with a valid description
|
||||
valid_description = 'mains gas (not community)'
|
||||
attr = MainFuelAttributes(valid_description)
|
||||
assert attr.description == 'mains gas not community'
|
||||
|
||||
# Test initialization with a description that contains none of the keywords
|
||||
with pytest.raises(ValueError):
|
||||
MainFuelAttributes('description without keywords')
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_case",
|
||||
mainfuel_cases
|
||||
)
|
||||
def test_process_mainheat(self, test_case):
|
||||
expected_result = test_case.copy()
|
||||
del expected_result["original_description"]
|
||||
result = MainFuelAttributes(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 fuel types",
|
||||
]
|
||||
|
||||
for description in invalid_descriptions:
|
||||
with pytest.raises(ValueError):
|
||||
MainFuelAttributes(description).process()
|
||||
Loading…
Add table
Reference in a new issue