hub/tests/test_weather_factory.py

55 lines
2.3 KiB
Python

"""
TestWeatherFactory test and validate the city model structure weather parameters
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from unittest import TestCase
from imports.geometry_factory import GeometryFactory
from imports.weather_factory import WeatherFactory
import helpers.constants as cte
class TestWeatherFactory(TestCase):
"""
TestWeatherFactory TestCase
"""
def setUp(self) -> None:
"""
Configure test environment
:return:
"""
self._city_gml = None
self._city_with_weather = None
self._city_name = 'new_york_city'
self._example_path = (Path(__file__).parent.parent / 'data' / 'weather').resolve()
def _get_citygml(self, file_path):
self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml
def test_weather_xls(self):
file_path = (Path(__file__).parent / 'tests_data' / 'iso_52016_1_2017_lod2.gml').resolve()
city_with_weather = self._get_citygml(file_path)
WeatherFactory('xls', city_with_weather, base_path=self._example_path).enrich()
for building in city_with_weather.buildings:
values = building.external_temperature[cte.HOUR][['iso52016']]
self.assertFalse(values.empty, 'wrong value external_temperature')
values = building.global_horizontal[cte.HOUR][['iso52016']]
self.assertFalse(values.empty, 'wrong value global horizontal')
def test_weather_epw(self):
file_path = (Path(__file__).parent / 'tests_data' / 'one_building_in_kelowna.gml').resolve()
city_with_weather = self._get_citygml(file_path)
_file_name = 'CAN_BC_Summerland.717680_CWEC.epw'
print(len(city_with_weather.buildings))
WeatherFactory('epw', city_with_weather, base_path=self._example_path, file_name=_file_name).enrich()
print(len(city_with_weather.buildings))
for building in city_with_weather.buildings:
values = building.external_temperature[cte.HOUR][['epw']]
self.assertFalse(values.empty, 'wrong value external_temperature')
values = building.global_horizontal[cte.HOUR][['epw']]
self.assertFalse(values.empty, 'wrong value global horizontal')