mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
106 lines
4.4 KiB
Python
106 lines
4.4 KiB
Python
import pickle
|
|
import pytest
|
|
import os
|
|
from unittest.mock import Mock
|
|
from model_data.recommendations.FloorRecommendations import FloorRecommendations
|
|
|
|
|
|
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.pkl", "rb"
|
|
) as f:
|
|
return pickle.load(f)
|
|
|
|
@pytest.fixture
|
|
def mock_floor_rec_instance(self):
|
|
# Creating a mock instance of WallRecommendations with the necessary attributes
|
|
property_mock = Mock()
|
|
property_mock.full_sap_epc = {"lodgement-date": "2000-01-01"} # or any date you want
|
|
property_mock.data = {"construction-age-band": "1950"} # or any other data that fits your tests
|
|
|
|
uvalue_estimates_mock = Mock()
|
|
|
|
mock_wall_rec_instance = FloorRecommendations(property_mock, uvalue_estimates_mock)
|
|
return mock_wall_rec_instance
|
|
|
|
def test_init(self, input_properties, uvalue_estimates):
|
|
obj = FloorRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
|
|
assert obj
|
|
assert obj.property
|
|
assert obj.uvalue_estimates
|
|
|
|
def test_other_premises_below(self, input_properties, uvalue_estimates):
|
|
recommender = FloorRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
|
|
recommender.recommend()
|
|
assert recommender.property.floor["another_property_below"]
|
|
|
|
assert not recommender.recommendations
|
|
|
|
def test_suspended_no_insulation(self, input_properties, uvalue_estimates):
|
|
"""
|
|
For a suspended floor without insulation, we use the rdsap methogology to estimate a U-value for the floor
|
|
:return:
|
|
"""
|
|
recommender = FloorRecommendations(property_instance=input_properties[2], uvalue_estimates=uvalue_estimates)
|
|
assert recommender.estimated_u_value is None
|
|
recommender.recommend()
|
|
assert recommender.property.floor["is_suspended"]
|
|
assert recommender.estimated_u_value == 0.8766389420265843
|
|
assert recommender.recommendations
|
|
|
|
types = {part["type"] for x in recommender.recommendations for part in x["parts"]}
|
|
|
|
assert types == {"suspended_floor_insulation"}
|
|
|
|
def test_uvalue_0_12(self, input_properties, uvalue_estimates):
|
|
"""
|
|
This is a home that doesn't have a property below but it's highly performant already and therefore
|
|
does not need floor insulation
|
|
:return:
|
|
"""
|
|
recommender = FloorRecommendations(property_instance=input_properties[3], uvalue_estimates=uvalue_estimates)
|
|
assert recommender.estimated_u_value is None
|
|
recommender.recommend()
|
|
assert not recommender.property.floor["is_suspended"]
|
|
assert not recommender.property.floor["is_solid"]
|
|
assert recommender.estimated_u_value is None
|
|
assert not recommender.recommendations
|
|
|
|
def test_solid_no_insulation(self, input_properties, uvalue_estimates):
|
|
"""
|
|
:return:
|
|
"""
|
|
recommender = FloorRecommendations(property_instance=input_properties[4], uvalue_estimates=uvalue_estimates)
|
|
assert recommender.estimated_u_value is None
|
|
recommender.recommend()
|
|
assert not recommender.property.floor["is_suspended"]
|
|
assert recommender.property.floor["is_solid"]
|
|
assert recommender.estimated_u_value == 0.7361642182695053
|
|
assert recommender.recommendations
|
|
|
|
types = {part["type"] for x in recommender.recommendations for part in x["parts"]}
|
|
|
|
assert types == {"solid_floor_insulation"}
|
|
|
|
def test_another_dwelling_below(self, input_properties, uvalue_estimates):
|
|
"""
|
|
This is another description we see when there is a property below
|
|
"""
|
|
input_properties[6].floor
|
|
recommender = FloorRecommendations(property_instance=input_properties[6], uvalue_estimates=uvalue_estimates)
|
|
assert recommender.estimated_u_value is None
|
|
recommender.recommend()
|
|
assert not recommender.property.floor["is_suspended"]
|
|
assert not recommender.property.floor["is_solid"]
|
|
assert recommender.estimated_u_value is None
|
|
assert not recommender.recommendations
|