""" TestGeometryFactory test and validate the city model structure geometric 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.geometry.helpers.geometry_helper import GeometryHelper from imports.usage_factory import UsageFactory from imports.construction_factory import ConstructionFactory class TestGeometryFactory(TestCase): """ Non-functional TestGeometryFactory Load testing """ def setUp(self) -> None: """ Test setup :return: None """ self._city = None self._example_path = (Path(__file__).parent / 'tests_data').resolve() def _get_citygml(self, file): file_path = (self._example_path / file).resolve() self._city = GeometryFactory('citygml', file_path).city self.assertIsNotNone(self._city, 'city is none') return self._city def _check_buildings(self, city): for building in city.buildings: self.assertIsNotNone(building.internal_zones, 'no internal zones created') for internal_zone in building.internal_zones: self.assertIsNotNone(internal_zone.usage_zones, 'usage zones are not defined') self.assertIsNotNone(internal_zone.thermal_zones, 'thermal zones are not defined') #self.assertIsNotNone(building.basement_heated, 'building basement_heated is none') #self.assertIsNotNone(building.attic_heated, 'building attic_heated is none') self.assertIsNotNone(building.average_storey_height, 'building average_storey_height is none') self.assertIsNotNone(building.storeys_above_ground, 'building storeys_above_ground is none') self.assertTrue(building.is_conditioned, 'building is_conditioned is not conditioned') def _check_usage_zone(self, usage_zone): self.assertIsNotNone(usage_zone.id, 'usage id is none') def _check_thermal_zones(self, thermal_zone): self.assertIsNotNone(thermal_zone.id, 'thermal_zone id is none') self.assertIsNone(thermal_zone.usage_zones, 'thermal_zone usage_zones is not none') self.assertIsNone(thermal_zone.thermal_control, 'thermal_zone thermal_control is not none') @staticmethod def _prepare_case_usage_first(city, input_key, construction_key, usage_key): if input_key == 'pluto': for building in city.buildings: building.function = GeometryHelper.function_from_pluto(building.function) elif input_key == 'hft': for building in city.buildings: building.function = GeometryHelper.function_from_hft(building.function) UsageFactory(usage_key, city).enrich() ConstructionFactory(construction_key, city).enrich() @staticmethod def _prepare_case_construction_first(city, input_key, construction_key, usage_key): if input_key == 'pluto': for building in city.buildings: building.function = GeometryHelper.function_from_pluto(building.function) elif input_key == 'hft': for building in city.buildings: building.function = GeometryHelper.function_from_hft(building.function) ConstructionFactory(construction_key, city).enrich() UsageFactory(usage_key, city).enrich() def test_enrichment(self): """ Test enrichment of the city with different order and all possible combinations :return: None """ file_1 = 'one_building_in_kelowna.gml' file_2 = 'pluto_building.gml' file_3 = 'C40_Final.gml' _construction_keys = ['nrel', 'nrcan'] _usage_keys = ['ca', 'comnet'] # todo: add 'hft' for construction_key in _construction_keys: for usage_key in _usage_keys: city = self._get_citygml(file_1) self.assertTrue(len(city.buildings) == 1) self._prepare_case_construction_first(city, 'hft', construction_key, usage_key) self._check_buildings(city) for building in city.buildings: for internal_zone in building.internal_zones: self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined') for usage_zone in internal_zone.usage_zones: self._check_usage_zone(usage_zone) for thermal_zone in internal_zone.thermal_zones: self._check_thermal_zones(thermal_zone) for construction_key in _construction_keys: for usage_key in _usage_keys: city = self._get_citygml(file_1) self.assertTrue(len(city.buildings) == 1) self._prepare_case_usage_first(city, 'hft', construction_key, usage_key) self._check_buildings(city) for building in city.buildings: for internal_zone in building.internal_zones: self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined') for usage_zone in internal_zone.usage_zones: self._check_usage_zone(usage_zone) for thermal_zone in internal_zone.thermal_zones: self._check_thermal_zones(thermal_zone) for construction_key in _construction_keys: for usage_key in _usage_keys: if usage_key != 'ca': city = self._get_citygml(file_2) self.assertTrue(len(city.buildings) == 1) self._prepare_case_construction_first(city, 'pluto', construction_key, usage_key) self._check_buildings(city) for building in city.buildings: for internal_zone in building.internal_zones: self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined') for usage_zone in internal_zone.usage_zones: self._check_usage_zone(usage_zone) for thermal_zone in internal_zone.thermal_zones: self._check_thermal_zones(thermal_zone) for construction_key in _construction_keys: for usage_key in _usage_keys: if usage_key != 'ca': city = self._get_citygml(file_2) self.assertTrue(len(city.buildings) == 1) self._prepare_case_usage_first(city, 'pluto', construction_key, usage_key) self._check_buildings(city) for building in city.buildings: for internal_zone in building.internal_zones: self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined') for usage_zone in internal_zone.usage_zones: self._check_usage_zone(usage_zone) for thermal_zone in internal_zone.thermal_zones: self._check_thermal_zones(thermal_zone) city = self._get_citygml(file_3) self.assertTrue(len(city.buildings) == 10)