mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Added unit testing
This commit is contained in:
parent
c4e3948d39
commit
f22cf79dfa
10 changed files with 170 additions and 5 deletions
2
.idea/Model.iml
generated
2
.idea/Model.iml
generated
|
|
@ -2,7 +2,7 @@
|
|||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (hestia-data)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (hestia-data)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
|
|
@ -1,4 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (hestia-data)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (hestia-data)" project-jdk-type="Python SDK" />
|
||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -2,6 +2,8 @@ import re
|
|||
from typing import List, Dict, Any, Union, Tuple
|
||||
from collections import Counter
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class EpcClean:
|
||||
"""
|
||||
|
|
@ -39,8 +41,12 @@ class EpcClean:
|
|||
|
||||
for description in self.unique_vals["roof-description"].keys():
|
||||
self.cleaned["roof-description"].append(
|
||||
{"original": description, "cleaned": self.clean_roof(description)}
|
||||
{
|
||||
"original_description": description,
|
||||
**self.clean_roof(description)
|
||||
}
|
||||
)
|
||||
df = pd.DataFrame(self.cleaned["roof-description"])
|
||||
|
||||
def _init_empty_cleaned_obj(self) -> None:
|
||||
"""
|
||||
|
|
@ -181,8 +187,10 @@ class EpcClean:
|
|||
insulation_thickness = self._find_insulation_thickness(
|
||||
description_lower, is_pitched, is_roof_room, is_flat
|
||||
)
|
||||
elif description_lower == "pitched":
|
||||
thermal_transmittence, thermal_transmittence_unit, insulation_thickness = None, None, None
|
||||
else:
|
||||
raise NotImplementedError("Not handles this")
|
||||
raise NotImplementedError("Not handled this")
|
||||
|
||||
attributes = {
|
||||
"is_pitched": is_pitched,
|
||||
|
|
|
|||
|
|
@ -33,3 +33,17 @@ To install project dependencies navigate to /epc_data and run
|
|||
```commandline
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
If you are not in a virtual environment, activate it with
|
||||
|
||||
```commandline
|
||||
conda activate envName
|
||||
```
|
||||
|
||||
Then run
|
||||
|
||||
```commandline
|
||||
python -m pytest
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import pickle
|
||||
|
||||
from tqdm import tqdm
|
||||
|
||||
from epc_data.temp_inputs import input_data
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ epc-api-python
|
|||
python-dotenv
|
||||
tqdm
|
||||
pandas
|
||||
mypy
|
||||
mypy
|
||||
pytest
|
||||
0
epc_data/tests/__init__.py
Normal file
0
epc_data/tests/__init__.py
Normal file
132
epc_data/tests/test_EpcClean.py
Normal file
132
epc_data/tests/test_EpcClean.py
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
import pytest
|
||||
import pickle
|
||||
from epc_data.EpcClean import EpcClean
|
||||
from pathlib import Path
|
||||
|
||||
# For local testing
|
||||
if __file__ == "<input>":
|
||||
input_data_path = Path("./epc_data/tests/test_data/EpcClean_inputs.obj")
|
||||
else:
|
||||
current_file_path = Path(__file__)
|
||||
input_data_path = current_file_path.parent / 'test_data' / 'EpcClean_inputs.obj'
|
||||
|
||||
|
||||
#
|
||||
# @pytest.fixture
|
||||
# def data():
|
||||
# print("WOW")
|
||||
# print(input_data_path)
|
||||
# with open(input_data_path, 'rb') as f:
|
||||
# data = pickle.load(f)
|
||||
# return data
|
||||
#
|
||||
#
|
||||
# def test_clean(data):
|
||||
# epc = EpcClean(data)
|
||||
# epc.clean()
|
||||
# assert len(epc.cleaned["roof-description"]) == len(epc.unique_vals["roof-description"])
|
||||
#
|
||||
#
|
||||
# def test_clean_roof(data):
|
||||
# epc = EpcClean(data)
|
||||
# result = epc.clean_roof('Pitched, 270 mm loft insulation')
|
||||
#
|
||||
# # change the expected output based on your requirement
|
||||
# expected_output = {
|
||||
# "is_pitched": True,
|
||||
# "is_roof_room": False,
|
||||
# "has_loft": True,
|
||||
# "insulation_thickness": 270,
|
||||
# "has_dwelling_above": False,
|
||||
# "assumed": False,
|
||||
# "is_flat": False,
|
||||
# "thermal_transmittence": None,
|
||||
# "thermal_transmittence_unit": None
|
||||
# }
|
||||
#
|
||||
# assert result == expected_output
|
||||
#
|
||||
#
|
||||
# def test_clean_roof_with_dwelling_above(data):
|
||||
# epc = EpcClean(data)
|
||||
# result = epc.clean_roof('(another dwelling above)')
|
||||
#
|
||||
# expected_output = {
|
||||
# "is_pitched": False,
|
||||
# "is_roof_room": False,
|
||||
# "has_loft": False,
|
||||
# "insulation_thickness": 0,
|
||||
# "has_dwelling_above": True,
|
||||
# "assumed": False,
|
||||
# "is_flat": False,
|
||||
# "is_thatched": False,
|
||||
# "thermal_transmittence": None,
|
||||
# "thermal_transmittence_unit": None,
|
||||
# }
|
||||
#
|
||||
# assert result == expected_output
|
||||
|
||||
|
||||
class TestEpcClean:
|
||||
@pytest.fixture(autouse=True)
|
||||
def load_data(self):
|
||||
with open(input_data_path, "rb") as file:
|
||||
self.data = pickle.load(file)
|
||||
self.ec = EpcClean(self.data)
|
||||
|
||||
def test_clean(self):
|
||||
self.ec.clean()
|
||||
assert len(self.ec.cleaned["roof-description"]) == len(self.ec.unique_vals["roof-description"])
|
||||
|
||||
def test__init_empty_cleaned_obj(self):
|
||||
self.ec._init_empty_cleaned_obj()
|
||||
assert all([len(values) == 0 for values in self.ec.cleaned.values()])
|
||||
|
||||
def test__search_split_roof_description(self):
|
||||
assert self.ec._search_split_roof_description("insulated") == "average"
|
||||
assert self.ec._search_split_roof_description("limited") == "below average"
|
||||
with pytest.raises(NotImplementedError):
|
||||
self.ec._search_split_roof_description("unknown")
|
||||
|
||||
def test__find_insulation_thickness(self):
|
||||
assert self.ec._find_insulation_thickness("no insulation", False, False, False) == 0
|
||||
|
||||
def test__extract_thermal_transmittence(self):
|
||||
description = "U-value of 2.3 w/m-¦k"
|
||||
assert self.ec._extract_thermal_transmittence(description) == (2.3, "w/m-¦k")
|
||||
|
||||
def test_clean_roof(self):
|
||||
result = self.ec.clean_roof('Pitched, 270 mm loft insulation')
|
||||
|
||||
# change the expected output based on your requirement
|
||||
expected_output = {
|
||||
"is_pitched": True,
|
||||
"is_roof_room": False,
|
||||
"has_loft": True,
|
||||
"insulation_thickness": 270,
|
||||
"has_dwelling_above": False,
|
||||
"assumed": False,
|
||||
"is_flat": False,
|
||||
"thermal_transmittence": None,
|
||||
"thermal_transmittence_unit": None
|
||||
}
|
||||
|
||||
assert result == expected_output
|
||||
|
||||
def test_clean_roof_with_dwelling_above(self):
|
||||
result = self.ec.clean_roof('(another dwelling above)')
|
||||
|
||||
expected_output = {
|
||||
"is_pitched": False,
|
||||
"is_roof_room": False,
|
||||
"has_loft": False,
|
||||
"insulation_thickness": 0,
|
||||
"has_dwelling_above": True,
|
||||
"assumed": False,
|
||||
"is_flat": False,
|
||||
"is_thatched": False,
|
||||
"thermal_transmittence": None,
|
||||
"thermal_transmittence_unit": None,
|
||||
}
|
||||
|
||||
assert result == expected_output
|
||||
BIN
epc_data/tests/test_data/EpcClean_inputs.obj
Normal file
BIN
epc_data/tests/test_data/EpcClean_inputs.obj
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue