Model/model_data/tests/test_wall_recommendations.py
2023-06-23 13:01:02 +01:00

78 lines
3.4 KiB
Python

import os
import pytest
import pickle
from model_data.recommendations.WallRecommendations import WallRecommendations
class TestWallRecommendations:
@pytest.fixture
def input_properties(self):
with open(
os.path.abspath(os.path.dirname(__file__)) + "/test_data/input_properties.pkl", "rb"
) as f:
return pickle.load(f)
@pytest.fixture
def uvalue_estimates(self):
with open(
os.path.abspath(os.path.dirname(__file__)) + "/test_data/uvalue_estimates_walls.pkl", "rb"
) as f:
return pickle.load(f)
def test_init(self, input_properties, uvalue_estimates):
obj = WallRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
assert obj
assert obj.property
assert obj.uvalue_estimates
assert obj.year_built == 2014
def test_uvalue_0_16(self, input_properties, uvalue_estimates):
"""
This tests the wall description Average thermal transmittance 0.16 W/m-¦K
The important data for this recommendation is:
- u value of 0.16
- property built in 2014
Since properties built after 1990 are typically built with insulation and this property
already has really good insulation, we do NOT recommend any measures for this property
"""
recommender = WallRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
assert recommender.property.walls["original_description"] == "Average thermal transmittance 0.16 W/m-¦K"
assert recommender.year_built == 2014
recommender.recommend()
# This should be empty
assert recommender.recommendations == []
def test_solid_brick_no_insulation(self, input_properties, uvalue_estimates):
"""
This tests a property with a wall description of Solid brick, as built, no insulation (assumed)
The property was built in 1930, right on the threshold for when cavity walls were introduced
However, we're told this property is solid brik so we assume no cavity.
We're also told that it has no insulation, so we will recommend internal/external wall insulation
This property is not in a conservation area, however it's a flat so we don't recommend external wall insulation
"""
recommender = WallRecommendations(property_instance=input_properties[1], uvalue_estimates=uvalue_estimates)
assert recommender.property.walls["original_description"] == "Solid brick, as built, no insulation (assumed)"
assert recommender.year_built == 1930
assert not recommender.ewi_valid
assert recommender.property.in_conservation_area == "not_in_conservation_area"
assert recommender.property.data["property-type"] == "Flat"
recommender.recommend()
# This should result in some recommendations, all of which should be insulation
assert recommender.recommendations
rec_types = {rec["type"] for rec in recommender.recommendations}
assert rec_types == {"internal_wall_insulation"}
# Check the recommendations provide a u value below the minimum
assert all(
rec["new_u_value"] < WallRecommendations.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE for rec in
recommender.recommendations
)
def test_nothing(self, input_properties, uvalue_estimates):
assert input_properties
assert uvalue_estimates