mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Adding tests but still got a bug
This commit is contained in:
parent
a7fbab377e
commit
3501bb8c5d
1 changed files with 88 additions and 1 deletions
|
|
@ -1,8 +1,13 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
import pytest
|
import pytest
|
||||||
import pickle
|
import pickle
|
||||||
from unittest.mock import Mock
|
import numpy as np
|
||||||
|
from unittest.mock import Mock, MagicMock
|
||||||
from model_data.recommendations.WallRecommendations import WallRecommendations
|
from model_data.recommendations.WallRecommendations import WallRecommendations
|
||||||
|
from model_data.analysis.UvalueEstimations import UvalueEstimations
|
||||||
|
from model_data.Property import Property
|
||||||
|
|
||||||
|
|
||||||
class TestWallRecommendations:
|
class TestWallRecommendations:
|
||||||
|
|
@ -180,3 +185,85 @@ class TestWallRecommendations:
|
||||||
mock_wall_rec_instance.recommendations = []
|
mock_wall_rec_instance.recommendations = []
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
mock_wall_rec_instance._is_diminishing_returns(0.2, 0.24)
|
mock_wall_rec_instance._is_diminishing_returns(0.2, 0.24)
|
||||||
|
|
||||||
|
|
||||||
|
class TestWallRecommendationsBase:
|
||||||
|
@pytest.fixture
|
||||||
|
def property_mock(self):
|
||||||
|
property_instance = MagicMock(spec=Property)
|
||||||
|
property_instance.full_sap_epc = {"lodgement-date": "1999-12-31"}
|
||||||
|
property_instance.in_conservation_area = "not_in_conservation_area"
|
||||||
|
return property_instance
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def uvalue_estimations_mock(self):
|
||||||
|
uvalue_estimations_mock = MagicMock(spec=UvalueEstimations)
|
||||||
|
|
||||||
|
uvalue_estimations_mock.walls = pd.DataFrame([
|
||||||
|
{
|
||||||
|
'local-authority': 'E09000012',
|
||||||
|
'property-type': 'Bungalow',
|
||||||
|
'walls-energy-eff': 'Very Good',
|
||||||
|
'walls-env-eff': 'Very Good',
|
||||||
|
'built-form': 'End-Terrace',
|
||||||
|
'number-habitable-rooms': '', 'number-heated-rooms': '', 'total-floor-area_group': 'Decile 1',
|
||||||
|
'median_thermal_transmittance': 0.15, 'n_samples': 1
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
uvalue_estimations_mock.walls_decile_data = {
|
||||||
|
'decile_labels': ['Decile 1', 'Decile 2', 'Decile 3', 'Decile 4', 'Decile 5', 'Decile 6', 'Decile 7',
|
||||||
|
'Decile 8', 'Decile 9', 'Decile 10'],
|
||||||
|
'decile_boundaries': np.array([11., 49., 52., 56., 63., 70., 74., 79.,
|
||||||
|
90., 103.8, 1936.])}
|
||||||
|
|
||||||
|
uvalue_estimations_mock.classify_decile_newvalues.return_value = "Decile 1"
|
||||||
|
return uvalue_estimations_mock
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def wall_recommendations_instance(self, property_mock, uvalue_estimations_mock):
|
||||||
|
wall_recommendations_instance = WallRecommendations(property_mock, uvalue_estimations_mock)
|
||||||
|
wall_recommendations_instance.uvalue_estimates.walls_decile_data = {
|
||||||
|
"decile_labels": MagicMock(),
|
||||||
|
"decile_boundaries": MagicMock()
|
||||||
|
}
|
||||||
|
uvalue_estimations_mock.classify_decile_newvalues.return_value = "Decile 1"
|
||||||
|
return wall_recommendations_instance
|
||||||
|
|
||||||
|
def test_ewi_valid_in_conservation_area(self, wall_recommendations_instance):
|
||||||
|
wall_recommendations_instance.property.in_conservation_area = "in_conversation_area"
|
||||||
|
assert wall_recommendations_instance.ewi_valid is False
|
||||||
|
|
||||||
|
def test_ewi_valid_is_flat(self, wall_recommendations_instance):
|
||||||
|
wall_recommendations_instance.property.data = {"property-type": "flat"}
|
||||||
|
assert wall_recommendations_instance.ewi_valid is False
|
||||||
|
|
||||||
|
def test_ewi_valid_not_in_conservation_area_and_not_flat(self, wall_recommendations_instance):
|
||||||
|
wall_recommendations_instance.property.in_conservation_area = "not_in_conversation_area"
|
||||||
|
wall_recommendations_instance.property.data = {"property-type": "house"}
|
||||||
|
assert wall_recommendations_instance.ewi_valid is True
|
||||||
|
|
||||||
|
def test_get_walls_uvalue_estimate(self, wall_recommendations_instance, uvalue_estimations_mock):
|
||||||
|
wall_recommendations_instance.uvalue_estimates = uvalue_estimations_mock
|
||||||
|
wall_recommendations_instance.property.data = {
|
||||||
|
"local-authority": "E09000012",
|
||||||
|
"property-type": "Bungalow",
|
||||||
|
"built-form": "End-Terrace",
|
||||||
|
"walls-energy-eff": "Very Good",
|
||||||
|
"walls-env-eff": "Very Good",
|
||||||
|
"total-floor-area": 10,
|
||||||
|
"number-habitable-rooms": "",
|
||||||
|
"number-heated-rooms": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
assert wall_recommendations_instance._get_walls_uvalue_estimate() == 0.2
|
||||||
|
|
||||||
|
def test_recommend_without_u_value(self, wall_recommendations_instance):
|
||||||
|
wall_recommendations_instance.property.walls = {
|
||||||
|
"thermal_transmittance": None,
|
||||||
|
"is_solid_brick": False,
|
||||||
|
"is_cavity_wall": False,
|
||||||
|
"insulation_thickness": "none"
|
||||||
|
}
|
||||||
|
with pytest.raises(NotImplementedError):
|
||||||
|
wall_recommendations_instance.recommend()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue