mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
added solar etl client unit tests
This commit is contained in:
parent
7740c31874
commit
9c94123366
3 changed files with 86 additions and 2 deletions
2
.idea/Model.iml
generated
2
.idea/Model.iml
generated
|
|
@ -7,7 +7,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/open_uprn" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/recommendations" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (backend)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (model_data)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyNamespacePackagesService">
|
||||
|
|
|
|||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
|
@ -3,7 +3,7 @@
|
|||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.10 (backend)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (backend)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (model_data)" project-jdk-type="Python SDK" />
|
||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,92 @@
|
|||
import unittest
|
||||
import pandas as pd
|
||||
from etl.solar.SolarPhotoSupply import SolarPhotoSupply
|
||||
|
||||
|
||||
class TestSolarPhotoSupply(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# Mock data for photo_supply_lookup and floor_area_decile_thresholds
|
||||
self.photo_supply_lookup = pd.DataFrame({
|
||||
"tenure": ["leasehold", "freehold"],
|
||||
"built_form": ["detached", "semi-detached"],
|
||||
"property_type": ["house", "flat"],
|
||||
"construction_age_band": ["pre-1900", "1900-1929"],
|
||||
"is_flat": [False, True],
|
||||
"is_pitched": [True, False],
|
||||
"is_roof_room": [False, True],
|
||||
"floor_area_decile": [0, 1],
|
||||
"photo_supply": [100, 200]
|
||||
})
|
||||
|
||||
self.floor_area_decile_thresholds = pd.DataFrame({
|
||||
"floor_area_decile_thresholds": [50, 100]
|
||||
})
|
||||
|
||||
self.solar_photo_supply = SolarPhotoSupply([], {})
|
||||
|
||||
def test_correct_filtering(self):
|
||||
result = self.solar_photo_supply.filter_photo_supply_lookup(
|
||||
self.photo_supply_lookup,
|
||||
self.floor_area_decile_thresholds,
|
||||
"leasehold",
|
||||
"detached",
|
||||
"house",
|
||||
"pre-1900",
|
||||
False,
|
||||
True,
|
||||
False,
|
||||
45
|
||||
)
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assertEqual(result.iloc[0]["photo_supply"], 100)
|
||||
|
||||
def test_no_matches(self):
|
||||
with self.assertRaises(ValueError):
|
||||
self.solar_photo_supply.filter_photo_supply_lookup(
|
||||
self.photo_supply_lookup,
|
||||
self.floor_area_decile_thresholds,
|
||||
"leasehold",
|
||||
"unknown",
|
||||
"house",
|
||||
"pre-1900",
|
||||
False,
|
||||
True,
|
||||
False,
|
||||
45
|
||||
)
|
||||
|
||||
def test_floor_area_decile_matching(self):
|
||||
result = self.solar_photo_supply.filter_photo_supply_lookup(
|
||||
self.photo_supply_lookup,
|
||||
self.floor_area_decile_thresholds,
|
||||
"freehold",
|
||||
"semi-detached",
|
||||
"flat",
|
||||
"1900-1929",
|
||||
True,
|
||||
False,
|
||||
True,
|
||||
60
|
||||
)
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assertEqual(result.iloc[0]["photo_supply"], 200)
|
||||
|
||||
def test_invalid_parameters(self):
|
||||
with self.assertRaises(AttributeError):
|
||||
self.solar_photo_supply.filter_photo_supply_lookup(
|
||||
self.photo_supply_lookup,
|
||||
self.floor_area_decile_thresholds,
|
||||
123, # Invalid type for tenure
|
||||
"detached",
|
||||
"house",
|
||||
"pre-1900",
|
||||
False,
|
||||
True,
|
||||
False,
|
||||
45
|
||||
)
|
||||
|
||||
def test_classify_floor_area(self):
|
||||
# Setup
|
||||
thresholds = [10, 20, 30, 40, 50]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue