diff --git a/model_data/epc_attributes/LightingAttributes.py b/model_data/epc_attributes/LightingAttributes.py index 7ce8b4d5..40123036 100644 --- a/model_data/epc_attributes/LightingAttributes.py +++ b/model_data/epc_attributes/LightingAttributes.py @@ -32,4 +32,4 @@ class LightingAttributes: "low_energy_proportion": proportion } - return {"low_energy_proportion": 0} + raise NotImplementedError("Not handled this case - investigate me") diff --git a/model_data/tests/test_data/test_lighting_attributes_cases.py b/model_data/tests/test_data/test_lighting_attributes_cases.py index 7733ff2e..57418aa1 100644 --- a/model_data/tests/test_data/test_lighting_attributes_cases.py +++ b/model_data/tests/test_data/test_lighting_attributes_cases.py @@ -25,9 +25,9 @@ test_cases = [ {'original_description': 'Low energy lighting in 51% of fixed outlets', 'low_energy_proportion': 0.51}, {'original_description': 'Low energy lighting in 99% of fixed outlets', 'low_energy_proportion': 0.99}, {'original_description': 'Low energy lighting in 100% of fixed outlets', 'low_energy_proportion': 1.0}, - {'original_description': 'Good lighting efficiency', 'low_energy_proportion': 98.16666666666667}, - {'original_description': 'Below average lighting efficiency', 'low_energy_proportion': 0.0}, - {'original_description': 'Excelent lighting efficiency', 'low_energy_proportion': 0}, + {'original_description': 'Good lighting efficiency', 'low_energy_proportion': 0.75}, + {'original_description': 'Below average lighting efficiency', 'low_energy_proportion': 0.25}, + {'original_description': 'Excellent lighting efficiency', 'low_energy_proportion': 1.0}, {'original_description': 'Low energy lighting in 2% of fixed outlets', 'low_energy_proportion': 0.02}, {'original_description': 'No Low energy lighting', 'low_energy_proportion': 0} ] diff --git a/model_data/tests/test_lighting_attributes.py b/model_data/tests/test_lighting_attributes.py new file mode 100644 index 00000000..64044abd --- /dev/null +++ b/model_data/tests/test_lighting_attributes.py @@ -0,0 +1,60 @@ +import pandas as pd +import pytest +from model_data.tests.test_data.test_lighting_attributes_cases import test_cases +from model_data.epc_attributes.LightingAttributes import LightingAttributes + +# An example averages dataset to use in tests. It is a dictionary where the key is a lighting description and the +# value is the expected proportion. +averages = pd.DataFrame( + [ + {"lighting-description": "good lighting efficiency", "low-energy-lighting": 0.75}, + {"lighting-description": "excellent lighting efficiency", "low-energy-lighting": 1.0}, + {"lighting-description": "below average lighting efficiency", "low-energy-lighting": 0.25} + ] +) + + +class TestLightingAttributes: + def test_no_lighting(self): + lighting = LightingAttributes("no low energy lighting", averages) + result = lighting.process() + assert result == {"low_energy_proportion": 0} + + def test_all_outlets(self): + lighting = LightingAttributes("Low energy lighting in all fixed outlets", averages) + result = lighting.process() + assert result == {"low_energy_proportion": 1} + + def test_good_efficiency(self): + lighting = LightingAttributes("Good lighting efficiency", averages) + result = lighting.process() + assert result == {"low_energy_proportion": 0.75} + + def test_excellent_efficiency(self): + lighting = LightingAttributes("Excellent lighting efficiency", averages) + result = lighting.process() + assert result == {"low_energy_proportion": 1} + + def test_below_average_efficiency(self): + lighting = LightingAttributes("Below average lighting efficiency", averages) + result = lighting.process() + assert result == {"low_energy_proportion": 0.25} + + def test_percentage(self): + lighting = LightingAttributes("Low energy lighting in 50% of fixed outlets", averages) + result = lighting.process() + assert result == {"low_energy_proportion": 0.5} + + def test_unknown_description(self): + with pytest.raises(NotImplementedError): + LightingAttributes("This is an unknown description", averages).process() + + @pytest.mark.parametrize( + "test_case", + test_cases + ) + def test_process_mainheat(self, test_case): + expected_result = test_case.copy() + del expected_result["original_description"] + result = LightingAttributes(test_case['original_description'], averages).process() + assert sorted(result.items()) == sorted(expected_result.items())