From a62ddf4ddc35c1242a97024011642309b63fda9c Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 27 Jun 2023 11:01:43 +0100 Subject: [PATCH] Fixed existing unit tests --- model_data/tests/test_wall_recommendations.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/model_data/tests/test_wall_recommendations.py b/model_data/tests/test_wall_recommendations.py index 8d0eb4d1..6ba4729f 100644 --- a/model_data/tests/test_wall_recommendations.py +++ b/model_data/tests/test_wall_recommendations.py @@ -8,6 +8,7 @@ from unittest.mock import Mock, MagicMock from model_data.recommendations.WallRecommendations import WallRecommendations from model_data.analysis.UvalueEstimations import UvalueEstimations from model_data.Property import Property +from model_data.recommendations.recommendation_utils import is_diminishing_returns class TestWallRecommendations: @@ -80,7 +81,7 @@ class TestWallRecommendations: # This should result in some recommendations, all of which should be internal insulation assert recommender.recommendations - rec_types = {rec["type"] for rec in recommender.recommendations} + rec_types = {part["type"] for rec in recommender.recommendations for part in rec["parts"]} assert rec_types == {"internal_wall_insulation"} # Check the recommendations provide a u value below the minimum @@ -119,7 +120,7 @@ class TestWallRecommendations: assert recommender.recommendations assert recommender.estimated_u_value == 0.45 - rec_types = {rec["type"] for rec in recommender.recommendations} + rec_types = {part["type"] for rec in recommender.recommendations for part in rec["parts"]} assert rec_types == {"internal_wall_insulation"} # Check the recommendations provide a u value below the minimum @@ -131,59 +132,58 @@ class TestWallRecommendations: for rec in recommender.recommendations: assert rec["new_u_value"] < 0.3 - def test_is_diminishing_returns_no_recommendations(self, mock_wall_rec_instance): + def test_is_diminishing_returns_no_recommendations(self): # We have no recommendations but the new u value is below the diminishing returns threshold # however since there are no recommendaions yet, we should include it and say # it is NOT diminishing - mock_wall_rec_instance.recommendations = [] new_u_value = 0.24 assert new_u_value < WallRecommendations.DIMINISHING_RETURNS_U_VALUE - assert not mock_wall_rec_instance._is_diminishing_returns(new_u_value, None) + assert not is_diminishing_returns([], new_u_value, None, WallRecommendations.DIMINISHING_RETURNS_U_VALUE) - def test_is_diminishing_returns_diminishing(self, mock_wall_rec_instance): + def test_is_diminishing_returns_diminishing(self): # We have a recommendation already and the new u value falls below the diminishing returns # threshold and is also lower than the lowest selected u value, so we should say this IS # diminishing returns - mock_wall_rec_instance.recommendations = [Mock()] new_u_value = 0.2 lowest_selected_u_value = 0.23 assert new_u_value < WallRecommendations.DIMINISHING_RETURNS_U_VALUE - assert mock_wall_rec_instance._is_diminishing_returns(new_u_value, lowest_selected_u_value) + assert is_diminishing_returns([Mock()], new_u_value, lowest_selected_u_value, + WallRecommendations.DIMINISHING_RETURNS_U_VALUE) - def test_is_diminishing_returns_is_diminishing(self, mock_wall_rec_instance): + def test_is_diminishing_returns_is_diminishing(self): # We have a recommendation already and the new u value falls below the diminishing returns # threshold and it's lower than the lowest selected u value, so we should say this IS DIMINISHIN - mock_wall_rec_instance.recommendations = [Mock()] new_u_value = 0.24 lowest_selected_u_value = 0.26 assert new_u_value < WallRecommendations.DIMINISHING_RETURNS_U_VALUE - assert mock_wall_rec_instance._is_diminishing_returns(new_u_value, lowest_selected_u_value) + assert is_diminishing_returns([Mock()], new_u_value, lowest_selected_u_value, + WallRecommendations.DIMINISHING_RETURNS_U_VALUE) - def test_is_diminishing_returns_not_diminishing(self, mock_wall_rec_instance): + def test_is_diminishing_returns_not_diminishing(self): # We have a recommendation already and the new u value falls below the diminishing returns # threshold however it's higher than the lowest selected u value, so we should say this is NOT # diminishing returns - mock_wall_rec_instance.recommendations = [Mock()] new_u_value = 0.24 lowest_selected_u_value = 0.22 assert new_u_value < WallRecommendations.DIMINISHING_RETURNS_U_VALUE - assert not mock_wall_rec_instance._is_diminishing_returns(new_u_value, lowest_selected_u_value) + assert not is_diminishing_returns([Mock()], new_u_value, lowest_selected_u_value, + WallRecommendations.DIMINISHING_RETURNS_U_VALUE) def test_is_diminishing_returns_error_in_recommendations(self, mock_wall_rec_instance): # Testing case where there's an error in recommendations mock_wall_rec_instance.recommendations = [] with pytest.raises(ValueError): - mock_wall_rec_instance._is_diminishing_returns(0.2, 0.24) + is_diminishing_returns([], 0.2, 0.24, 0.25) class TestWallRecommendationsBase: