Model/etl/epc_clean/tests/test_lighting_attributes.py
2023-10-05 15:09:50 +01:00

72 lines
3 KiB
Python

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 = [
{"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())
def test_regex_translations(self):
"""
Some of the regex translations were falling through the net, though we were pulling out the percentages
so we just make sure we're translating correctly
"""
init1 = LightingAttributes("Goleuadau ynni-isel mewn 17% o'r mannau gosod", [])
assert init1.description == 'low energy lighting in 17% of fixed outlets'
init2 = LightingAttributes("Goleuadau ynni-isel mewn 60% oGÇÖr mannau gosod", [])
assert init2.description == 'low energy lighting in 60% of fixed outlets'