Add unit tests
This commit is contained in:
parent
24546a08d4
commit
2e809601fc
@ -29,7 +29,6 @@ class CostBase:
|
|||||||
if not self._archetype:
|
if not self._archetype:
|
||||||
raise KeyError(f'archetype not found for function {building.function}')
|
raise KeyError(f'archetype not found for function {building.function}')
|
||||||
|
|
||||||
|
|
||||||
self._rng = range(configuration.number_of_years)
|
self._rng = range(configuration.number_of_years)
|
||||||
|
|
||||||
def calculate(self):
|
def calculate(self):
|
||||||
|
1
tests/data/test.geojson
Normal file
1
tests/data/test.geojson
Normal file
File diff suppressed because one or more lines are too long
2
tests/output/.gitignore
vendored
Normal file
2
tests/output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
71
tests/unit_tests.py
Normal file
71
tests/unit_tests.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import glob
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||||
|
from hub.exports.exports_factory import ExportsFactory
|
||||||
|
from hub.imports.construction_factory import ConstructionFactory
|
||||||
|
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
||||||
|
from hub.imports.geometry_factory import GeometryFactory
|
||||||
|
from hub.imports.results_factory import ResultFactory
|
||||||
|
from hub.imports.usage_factory import UsageFactory
|
||||||
|
from hub.helpers.dictionaries import Dictionaries
|
||||||
|
|
||||||
|
from costs.cost import Cost
|
||||||
|
from costs.constants import SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV, SYSTEM_RETROFIT_AND_PV
|
||||||
|
|
||||||
|
|
||||||
|
class UnitTests(TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
city_file = "./data/test.geojson"
|
||||||
|
output_path = Path('./output/').resolve()
|
||||||
|
city = GeometryFactory('geojson',
|
||||||
|
city_file,
|
||||||
|
height_field='citygml_me',
|
||||||
|
year_of_construction_field='ANNEE_CONS',
|
||||||
|
function_field='CODE_UTILI',
|
||||||
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
||||||
|
ConstructionFactory('nrcan', city).enrich()
|
||||||
|
UsageFactory('nrcan', city).enrich()
|
||||||
|
ExportsFactory('sra', city, output_path).export()
|
||||||
|
sra_file = str((output_path / f'{city.name}_sra.xml').resolve())
|
||||||
|
subprocess.run(['/usr/local/bin/sra', sra_file])
|
||||||
|
ResultFactory('sra', city, output_path).enrich()
|
||||||
|
|
||||||
|
for building in city.buildings:
|
||||||
|
building.energy_systems_archetype_name = 'system 1 gas pv'
|
||||||
|
EnergySystemsFactory('montreal_custom', city).enrich()
|
||||||
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, output_path).export()
|
||||||
|
_insel_files = glob.glob(f'{output_path}/*.insel')
|
||||||
|
for insel_file in _insel_files:
|
||||||
|
subprocess.run(['insel', str(insel_file)], stdout=subprocess.DEVNULL)
|
||||||
|
ResultFactory('insel_monthly_energy_balance', city, output_path).enrich()
|
||||||
|
self._city = city
|
||||||
|
|
||||||
|
def test_current_status(self):
|
||||||
|
for building in self._city.buildings:
|
||||||
|
result = Cost(building).life_cycle
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def test_scenario_1(self):
|
||||||
|
for building in self._city.buildings:
|
||||||
|
result = Cost(building, retrofit_scenario=SKIN_RETROFIT).life_cycle
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def test_scenario_2(self):
|
||||||
|
for building in self._city.buildings:
|
||||||
|
result = Cost(building, retrofit_scenario=SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV).life_cycle
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def test_scenario_3(self):
|
||||||
|
for building in self._city.buildings:
|
||||||
|
result = Cost(building, retrofit_scenario=SYSTEM_RETROFIT_AND_PV).life_cycle
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
files = glob.glob('output/[!.]*')
|
||||||
|
for file in files:
|
||||||
|
os.unlink(file)
|
Loading…
Reference in New Issue
Block a user