diff --git a/.coveragerc b/.coveragerc index a220497a..62a3ede8 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,12 +2,8 @@ omit = *__init__* */tests/* - model_data/temp_inputs.py - model_data/config.py - model_data/__init__.py - model_data/app.py - model_data/plotting/* recommendations/rdsap_tables.py - model_data/simulation_system/* - model_data/cleaner_app.py + */config.py + */app.py + */settings.py backend/app/* \ No newline at end of file diff --git a/backend/tests/test_property.py b/backend/tests/test_property.py index 8d392bab..8b452db7 100644 --- a/backend/tests/test_property.py +++ b/backend/tests/test_property.py @@ -1,10 +1,8 @@ import pytest -import pandas as pd from unittest.mock import Mock from epc_api.client import EpcClient from backend.Property import Property -from open_uprn.OpenUprnClient import OpenUprnClient -from model_data.EpcClean import EpcClean +from etl.epc_clean.EpcClean import EpcClean # Define some test data mock_epc_response = { @@ -130,7 +128,7 @@ mock_epc_response_dupe = { class TestProperty: @pytest.fixture(autouse=True) - def property_instance(self, mock_epc_client, mock_open_uprn_client, mock_cleaner): + def property_instance(self, mock_epc_client, mock_cleaner): property_instance = Property(1, "AB12CD", "Test Address", epc_client=mock_epc_client) return property_instance @@ -141,29 +139,18 @@ class TestProperty: @pytest.fixture def mock_epc_client(self): - mock_epc_client = Mock(spec=EpcClient()) + mock_epc_client = Mock(spec=EpcClient(auth_token="mocked_auth_token")) mock_epc_client.domestic.search.return_value = mock_epc_response.copy() mock_epc_client.auth_token = "mocked_auth_token" return mock_epc_client @pytest.fixture def mock_epc_client_dupe_data(self): - mock_epc_client_dupe_data = Mock(spec=EpcClient()) + mock_epc_client_dupe_data = Mock(spec=EpcClient(auth_token="mocked_auth_token")) mock_epc_client_dupe_data.domestic.search.return_value = mock_epc_response_dupe.copy() mock_epc_client_dupe_data.auth_token = "mocked_auth_token" return mock_epc_client_dupe_data - @pytest.fixture - def mock_open_uprn_client(self): - mock_open_uprn_client = Mock(spec=OpenUprnClient(path=None, uprns=[12345])) - mock_open_uprn_client.data = pd.DataFrame( - [ - {"UPRN": 12345, "longitude": 1.2345, "latitude": 2.3456}, - {"UPRN": 12346, "longitude": 3.4567, "latitude": 4.5678} - ] - ) - return mock_open_uprn_client - @pytest.fixture def mock_cleaner(self): lighting_averages = [ @@ -201,10 +188,10 @@ class TestProperty: # Should be mocked auth token assert inst1.epc_client.auth_token == "mocked_auth_token" - inst2 = Property(3, "AB12CD", "Test Address") + inst2 = Property(3, "AB12CD", "Test Address", epc_client=mock_epc_client) assert inst2.epc_client.auth_token - inst3 = Property(4, "AB12CD", "Test Address", data={"some": "data"}) + inst3 = Property(4, "AB12CD", "Test Address", data={"some": "data"}, epc_client=mock_epc_client) assert inst3.data == {"some": "data"} data = inst3.search_address_epc() diff --git a/etl/epc_clean/EpcClean.py b/etl/epc_clean/EpcClean.py index 9d3c4d74..90de132c 100644 --- a/etl/epc_clean/EpcClean.py +++ b/etl/epc_clean/EpcClean.py @@ -4,16 +4,16 @@ from collections import defaultdict import pandas as pd -from model_data.utils import correct_spelling -from model_data.epc_attributes.FloorAttributes import FloorAttributes -from model_data.epc_attributes.HotWaterAttributes import HotWaterAttributes -from model_data.epc_attributes.MainFuelAttributes import MainFuelAttributes -from model_data.epc_attributes.MainheatAttributes import MainHeatAttributes -from model_data.epc_attributes.MainheatControlAttributes import MainheatControlAttributes -from model_data.epc_attributes.RoofAttributes import RoofAttributes -from model_data.epc_attributes.WallAttributes import WallAttributes -from model_data.epc_attributes.WindowAttributes import WindowAttributes -from model_data.epc_attributes.LightingAttributes import LightingAttributes +from etl.epc_clean.utils import correct_spelling +from etl.epc_clean.epc_attributes.FloorAttributes import FloorAttributes +from etl.epc_clean.epc_attributes.HotWaterAttributes import HotWaterAttributes +from etl.epc_clean.epc_attributes.MainFuelAttributes import MainFuelAttributes +from etl.epc_clean.epc_attributes.MainheatAttributes import MainHeatAttributes +from etl.epc_clean.epc_attributes.MainheatControlAttributes import MainheatControlAttributes +from etl.epc_clean.epc_attributes.RoofAttributes import RoofAttributes +from etl.epc_clean.epc_attributes.WallAttributes import WallAttributes +from etl.epc_clean.epc_attributes.WindowAttributes import WindowAttributes +from etl.epc_clean.epc_attributes.LightingAttributes import LightingAttributes class EpcClean: diff --git a/etl/epc_clean/epc_attributes/FloorAttributes.py b/etl/epc_clean/epc_attributes/FloorAttributes.py index 847b183a..6631b4d5 100644 --- a/etl/epc_clean/epc_attributes/FloorAttributes.py +++ b/etl/epc_clean/epc_attributes/FloorAttributes.py @@ -1,7 +1,7 @@ import re from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import extract_thermal_transmittance, extract_component_types +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import extract_thermal_transmittance, extract_component_types class FloorAttributes(Definitions): diff --git a/etl/epc_clean/epc_attributes/HotWaterAttributes.py b/etl/epc_clean/epc_attributes/HotWaterAttributes.py index c7353ab2..e8bce0bb 100644 --- a/etl/epc_clean/epc_attributes/HotWaterAttributes.py +++ b/etl/epc_clean/epc_attributes/HotWaterAttributes.py @@ -1,6 +1,6 @@ from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import clean_description, find_keyword +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import clean_description, find_keyword class HotWaterAttributes(Definitions): diff --git a/etl/epc_clean/epc_attributes/LightingAttributes.py b/etl/epc_clean/epc_attributes/LightingAttributes.py index 83e9ef5f..0fe3db16 100644 --- a/etl/epc_clean/epc_attributes/LightingAttributes.py +++ b/etl/epc_clean/epc_attributes/LightingAttributes.py @@ -1,6 +1,6 @@ import re -from model_data.epc_attributes.attribute_utils import clean_description -from model_data.utils import correct_spelling +from etl.epc_clean.epc_attributes.attribute_utils import clean_description +from etl.epc_clean.utils import correct_spelling class LightingAttributes: @@ -27,7 +27,7 @@ class LightingAttributes: lel_match2 = re.search(r"goleuadau ynni-isel mewn (\d+)%? o'r mannau gosod", self.description) if lel_match is not None or lel_match2 is not None: - + # Perform the actual translation percentage = lel_match.group(1) if lel_match is not None else lel_match2.group(1) self.description = f"low energy lighting in {percentage}% of fixed outlets" diff --git a/etl/epc_clean/epc_attributes/MainFuelAttributes.py b/etl/epc_clean/epc_attributes/MainFuelAttributes.py index 35059865..72b86482 100644 --- a/etl/epc_clean/epc_attributes/MainFuelAttributes.py +++ b/etl/epc_clean/epc_attributes/MainFuelAttributes.py @@ -1,6 +1,6 @@ from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import clean_description, remove_punctuation, find_keyword +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import clean_description, remove_punctuation, find_keyword class MainFuelAttributes(Definitions): diff --git a/etl/epc_clean/epc_attributes/MainheatAttributes.py b/etl/epc_clean/epc_attributes/MainheatAttributes.py index 9471ee1d..e21f0d37 100644 --- a/etl/epc_clean/epc_attributes/MainheatAttributes.py +++ b/etl/epc_clean/epc_attributes/MainheatAttributes.py @@ -1,5 +1,5 @@ -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import clean_description, process_part, switch_chars +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import clean_description, process_part, switch_chars from typing import Dict, Union diff --git a/etl/epc_clean/epc_attributes/MainheatControlAttributes.py b/etl/epc_clean/epc_attributes/MainheatControlAttributes.py index 64f5afba..23f39d08 100644 --- a/etl/epc_clean/epc_attributes/MainheatControlAttributes.py +++ b/etl/epc_clean/epc_attributes/MainheatControlAttributes.py @@ -1,6 +1,6 @@ from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import clean_description, find_keyword +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import clean_description, find_keyword class MainheatControlAttributes(Definitions): diff --git a/etl/epc_clean/epc_attributes/RoofAttributes.py b/etl/epc_clean/epc_attributes/RoofAttributes.py index c83ad98a..9e400235 100644 --- a/etl/epc_clean/epc_attributes/RoofAttributes.py +++ b/etl/epc_clean/epc_attributes/RoofAttributes.py @@ -1,7 +1,7 @@ import re from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import extract_component_types, extract_thermal_transmittance +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import extract_component_types, extract_thermal_transmittance class RoofAttributes(Definitions): diff --git a/etl/epc_clean/epc_attributes/WallAttributes.py b/etl/epc_clean/epc_attributes/WallAttributes.py index e2f7be07..03fe6d67 100644 --- a/etl/epc_clean/epc_attributes/WallAttributes.py +++ b/etl/epc_clean/epc_attributes/WallAttributes.py @@ -1,7 +1,7 @@ import re from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import ( +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import ( extract_component_types, extract_thermal_transmittance ) diff --git a/etl/epc_clean/epc_attributes/WindowAttributes.py b/etl/epc_clean/epc_attributes/WindowAttributes.py index 361df4d9..e962cd31 100644 --- a/etl/epc_clean/epc_attributes/WindowAttributes.py +++ b/etl/epc_clean/epc_attributes/WindowAttributes.py @@ -1,6 +1,6 @@ from typing import Dict, Union -from model_data.BaseUtility import Definitions -from model_data.epc_attributes.attribute_utils import clean_description +from BaseUtility import Definitions +from etl.epc_clean.epc_attributes.attribute_utils import clean_description class WindowAttributes(Definitions): diff --git a/etl/epc_clean/tests/test_epc_clean.py b/etl/epc_clean/tests/test_epc_clean.py index eaa51cb1..a92fe12f 100644 --- a/etl/epc_clean/tests/test_epc_clean.py +++ b/etl/epc_clean/tests/test_epc_clean.py @@ -1,6 +1,6 @@ import pytest import pickle -from model_data.EpcClean import EpcClean +from etl.epc_clean.EpcClean import EpcClean from pathlib import Path # For local testing diff --git a/etl/epc_clean/tests/test_floor_attributes.py b/etl/epc_clean/tests/test_floor_attributes.py index 4b3b2c85..fc60c343 100644 --- a/etl/epc_clean/tests/test_floor_attributes.py +++ b/etl/epc_clean/tests/test_floor_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.tests.test_data.test_floor_attributes_cases import clean_floor_cases -from model_data.epc_attributes.FloorAttributes import FloorAttributes +from etl.epc_clean.tests.test_data.test_floor_attributes_cases import clean_floor_cases +from etl.epc_clean.epc_attributes.FloorAttributes import FloorAttributes class TestCleanFloor: diff --git a/etl/epc_clean/tests/test_hotwater_attributes.py b/etl/epc_clean/tests/test_hotwater_attributes.py index 2df31c51..2809b805 100644 --- a/etl/epc_clean/tests/test_hotwater_attributes.py +++ b/etl/epc_clean/tests/test_hotwater_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.epc_attributes.HotWaterAttributes import HotWaterAttributes -from model_data.tests.test_data.test_hot_water_attributes_cases import hotwater_cases +from etl.epc_clean.epc_attributes.HotWaterAttributes import HotWaterAttributes +from etl.epc_clean.tests.test_data.test_hot_water_attributes_cases import hotwater_cases class TestHotWaterAttributes: diff --git a/etl/epc_clean/tests/test_lighting_attributes.py b/etl/epc_clean/tests/test_lighting_attributes.py index 38219e86..f3c23e8f 100644 --- a/etl/epc_clean/tests/test_lighting_attributes.py +++ b/etl/epc_clean/tests/test_lighting_attributes.py @@ -1,7 +1,7 @@ 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 +from etl.epc_clean.tests.test_data.test_lighting_attributes_cases import test_cases +from etl.epc_clean.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. diff --git a/etl/epc_clean/tests/test_mainfuel_attributes.py b/etl/epc_clean/tests/test_mainfuel_attributes.py index cf23cb9f..bface6e2 100644 --- a/etl/epc_clean/tests/test_mainfuel_attributes.py +++ b/etl/epc_clean/tests/test_mainfuel_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.epc_attributes.MainFuelAttributes import MainFuelAttributes -from model_data.tests.test_data.test_main_fuel_attributes_cases import mainfuel_cases +from etl.epc_clean.epc_attributes.MainFuelAttributes import MainFuelAttributes +from etl.epc_clean.tests.test_data.test_main_fuel_attributes_cases import mainfuel_cases class TestMainHeatControlAttributes: diff --git a/etl/epc_clean/tests/test_mainheat_attributes.py b/etl/epc_clean/tests/test_mainheat_attributes.py index 7f70ec6b..f175e821 100644 --- a/etl/epc_clean/tests/test_mainheat_attributes.py +++ b/etl/epc_clean/tests/test_mainheat_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.epc_attributes.MainheatAttributes import MainHeatAttributes -from model_data.tests.test_data.test_mainheat_attributes_cases import mainheat_cases +from etl.epc_clean.epc_attributes.MainheatAttributes import MainHeatAttributes +from etl.epc_clean.tests.test_data.test_mainheat_attributes_cases import mainheat_cases class TestMainHeatAttributes: diff --git a/etl/epc_clean/tests/test_mainheat_controls_attributes.py b/etl/epc_clean/tests/test_mainheat_controls_attributes.py index 3570bafe..7b114107 100644 --- a/etl/epc_clean/tests/test_mainheat_controls_attributes.py +++ b/etl/epc_clean/tests/test_mainheat_controls_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.epc_attributes.MainheatControlAttributes import MainheatControlAttributes -from model_data.tests.test_data.test_mainheat_control_attributes_cases import mainheat_control_cases +from etl.epc_clean.epc_attributes.MainheatControlAttributes import MainheatControlAttributes +from etl.epc_clean.tests.test_data.test_mainheat_control_attributes_cases import mainheat_control_cases class TestMainHeatControlAttributes: diff --git a/etl/epc_clean/tests/test_roof_attributes.py b/etl/epc_clean/tests/test_roof_attributes.py index 5b010d90..54b59f1a 100644 --- a/etl/epc_clean/tests/test_roof_attributes.py +++ b/etl/epc_clean/tests/test_roof_attributes.py @@ -1,7 +1,7 @@ import pytest from pathlib import Path -from model_data.tests.test_data.test_roof_attributes_cases import clean_roof_test_cases -from model_data.epc_attributes.RoofAttributes import RoofAttributes +from etl.epc_clean.tests.test_data.test_roof_attributes_cases import clean_roof_test_cases +from etl.epc_clean.epc_attributes.RoofAttributes import RoofAttributes # For local testing if __file__ == "": diff --git a/etl/epc_clean/tests/test_utils.py b/etl/epc_clean/tests/test_utils.py index 224471b8..eb813031 100644 --- a/etl/epc_clean/tests/test_utils.py +++ b/etl/epc_clean/tests/test_utils.py @@ -1,4 +1,4 @@ -from model_data.utils import is_percentage_or_number, correct_spelling +from etl.epc_clean.utils import is_percentage_or_number, correct_spelling class TestUtils: diff --git a/etl/epc_clean/tests/test_wall_attributes.py b/etl/epc_clean/tests/test_wall_attributes.py index c8d5eb24..01a60615 100644 --- a/etl/epc_clean/tests/test_wall_attributes.py +++ b/etl/epc_clean/tests/test_wall_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.epc_attributes.WallAttributes import WallAttributes -from model_data.tests.test_data.test_wall_attributes_cases import wall_cases +from etl.epc_clean.epc_attributes.WallAttributes import WallAttributes +from etl.epc_clean.tests.test_data.test_wall_attributes_cases import wall_cases class TestWallAttributes: diff --git a/etl/epc_clean/tests/test_window_attributes.py b/etl/epc_clean/tests/test_window_attributes.py index 137c2313..46ebde45 100644 --- a/etl/epc_clean/tests/test_window_attributes.py +++ b/etl/epc_clean/tests/test_window_attributes.py @@ -1,6 +1,6 @@ import pytest -from model_data.epc_attributes.WindowAttributes import WindowAttributes -from model_data.tests.test_data.test_window_attributes_cases import windows_cases +from etl.epc_clean.epc_attributes.WindowAttributes import WindowAttributes +from etl.epc_clean.tests.test_data.test_window_attributes_cases import windows_cases class TestWindowAttributes: diff --git a/etl/land_registry/tests/test_land_registry_client.py b/etl/land_registry/tests/test_land_registry_client.py index 97a30641..c03a32fc 100644 --- a/etl/land_registry/tests/test_land_registry_client.py +++ b/etl/land_registry/tests/test_land_registry_client.py @@ -1,6 +1,6 @@ import pandas as pd from unittest.mock import patch, call -from model_data.LandRegistryClient import LandRegistryClient +from etl.land_registry.LandRegistryClient import LandRegistryClient class TestLandRegistryClient: diff --git a/etl/spatial/tests/test_borehole_client.py b/etl/spatial/tests/test_borehole_client.py index f49733dd..38bf4495 100644 --- a/etl/spatial/tests/test_borehole_client.py +++ b/etl/spatial/tests/test_borehole_client.py @@ -1,5 +1,5 @@ import pytest -from model_data.BoreholeClient import BoreholeClient +from etl.spatial.BoreholeClient import BoreholeClient @pytest.fixture diff --git a/pytest.ini b/pytest.ini index 401ecc0f..b2453c82 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,4 @@ [pytest] pythonpath = . -addopts = --cov-report term-missing --cov=model_data --cov=recommendations -testpaths = model_data/tests recommendations/tests backend/tests +addopts = --cov-report term-missing --cov=etl --cov=recommendations --cov=backend +testpaths = etl/*/tests recommendations/tests backend/tests diff --git a/recommendations/FloorRecommendations.py b/recommendations/FloorRecommendations.py index a19cf1a8..be32a0fb 100644 --- a/recommendations/FloorRecommendations.py +++ b/recommendations/FloorRecommendations.py @@ -1,6 +1,6 @@ import math from typing import List -from model_data.BaseUtility import Definitions +from BaseUtility import Definitions from datatypes.enums import QuantityUnits from backend.Property import Property from recommendations.recommendation_utils import ( diff --git a/recommendations/WallRecommendations.py b/recommendations/WallRecommendations.py index d99f794f..942dc8fa 100644 --- a/recommendations/WallRecommendations.py +++ b/recommendations/WallRecommendations.py @@ -4,7 +4,7 @@ from typing import List from datatypes.enums import QuantityUnits from backend.Property import Property -from model_data.BaseUtility import Definitions +from BaseUtility import Definitions from recommendations.recommendation_utils import ( r_value_per_mm_to_u_value, calculate_u_value_uplift, is_diminishing_returns, update_lowest_selected_u_value, get_recommended_part, get_wall_u_value