From 11d26720c987de432b3566b99e5e8f25cf9e20eb Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 13 Jun 2023 13:13:28 +0100 Subject: [PATCH] completed tests --- Makefile | 4 +++ epc_data/requirements.txt | 2 +- epc_data/tests/test_floor_attributes.py | 35 ++++++++++++++++++++++++- epc_data/tests/test_roof_attributes.py | 13 +++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..7ba8d680 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: epc_data_test + +epc_data_test_attributes: + pytest --cov-report term-missing --cov=epc_data/attributes diff --git a/epc_data/requirements.txt b/epc_data/requirements.txt index 4d844987..6a8ff0d6 100644 --- a/epc_data/requirements.txt +++ b/epc_data/requirements.txt @@ -5,4 +5,4 @@ pandas mypy pytest mock -nltk \ No newline at end of file +pytest-cov \ No newline at end of file diff --git a/epc_data/tests/test_floor_attributes.py b/epc_data/tests/test_floor_attributes.py index 2e442667..0fd1bf2a 100644 --- a/epc_data/tests/test_floor_attributes.py +++ b/epc_data/tests/test_floor_attributes.py @@ -1,10 +1,25 @@ +import pytest from epc_data.tests.test_data.test_floor_attributes_cases import clean_floor_cases from epc_data.attributes.FloorAttributes import FloorAttributes class TestCleanFloor: - def test_clean_floor(self): + def test_init(self): + # Test initialization with a valid description + valid_description = 'Solid, limited insulation (assumed)' + floor_attr = FloorAttributes(valid_description) + assert floor_attr.description == valid_description.lower() + + # Test initialization with an empty description + with pytest.raises(ValueError): + FloorAttributes('') + + # Test initialization with a description that contains none of the keywords + with pytest.raises(ValueError): + FloorAttributes('description without keywords') + + def test_process_floor(self): for test_case in clean_floor_cases: result = FloorAttributes(test_case['original_description']).process() # Ensure the output ordering is correct @@ -12,3 +27,21 @@ class TestCleanFloor: expected_result["desc"] = test_case["original_description"] result["desc"] = test_case["original_description"] assert result == expected_result + + def test_invalid_description(self): + # Test that invalid descriptions raise a ValueError + invalid_descriptions = [ + "", + "invalid description", + "description with no known floor types or thermal transmittance", + ] + + for description in invalid_descriptions: + with pytest.raises(ValueError): + FloorAttributes(description).process() + + def test_process_with_invalid_description(self): + # Test that processing an invalid description raises a ValueError + invalid_description = 'description without keywords' + with pytest.raises(ValueError): + FloorAttributes(invalid_description) diff --git a/epc_data/tests/test_roof_attributes.py b/epc_data/tests/test_roof_attributes.py index ea7dbbc7..94e0ce82 100644 --- a/epc_data/tests/test_roof_attributes.py +++ b/epc_data/tests/test_roof_attributes.py @@ -15,6 +15,19 @@ else: class TestRoofAttributes: + def test_init(self): + # Test initialization with a valid description + valid_description = "(Another dwelling above)" + floor_attr = RoofAttributes(valid_description) + assert floor_attr.description == valid_description.lower() + + # Test initialization with an empty description + with pytest.raises(ValueError): + RoofAttributes('') + + with pytest.raises(ValueError): + RoofAttributes('description without keywords') + def test_clean_roof(self): result = RoofAttributes('Pitched, 270 mm loft insulation').process()