system_assignation/unittests/test_geometry_factory.py

133 lines
6.3 KiB
Python
Raw Normal View History

"""
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
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 _get_obj(self, file):
# todo: solve the incongruities between city and city_debug
file_path = (self._example_path / file).resolve()
2021-08-11 10:29:54 -04:00
self._city = GeometryFactory('obj', file_path).city
self.assertIsNotNone(self._city, 'city is none')
return self._city
2022-03-08 19:19:52 -05:00
def _check_buildings(self, city):
for building in city.buildings:
self.assertIsNotNone(building.name, 'building name is none')
self.assertIsNotNone(building.lod, 'building lod is none')
2022-03-08 19:19:52 -05:00
self.assertIsNotNone(building.type, 'building type is none')
self.assertIsNotNone(building.volume, 'building volume is none')
2022-03-08 19:19:52 -05:00
self.assertIsNotNone(building.detailed_polyhedron, 'building detailed polyhedron is none')
self.assertIsNotNone(building.simplified_polyhedron, 'building simplified polyhedron is none')
self.assertIsNotNone(building.surfaces, 'building surfaces is none')
2022-03-08 19:19:52 -05:00
self.assertIsNotNone(building.centroid, 'building centroid is none')
self.assertIsNotNone(building.max_height, 'building max_height is none')
self.assertEqual(len(building.external_temperature), 0, 'building external temperature is calculated')
self.assertEqual(len(building.global_horizontal), 0, 'building global horizontal is calculated')
self.assertEqual(len(building.diffuse), 0, 'building diffuse is calculated')
self.assertEqual(len(building.beam), 0, 'building beam is calculated')
self.assertIsNotNone(building.lower_corner, 'building lower corner is none')
self.assertEqual(len(building.sensors), 0, 'building sensors are assigned')
self.assertIsNotNone(building.internal_zones, 'no internal zones created')
2022-03-08 19:19:52 -05:00
self.assertIsNotNone(building.grounds, 'building grounds is none')
self.assertIsNotNone(building.walls, 'building walls is none')
self.assertIsNotNone(building.roofs, 'building roofs is none')
self.assertIsNone(building.usage_zones, 'usage zones are defined')
self.assertIsNone(building.thermal_zones, 'thermal zones are defined')
self.assertIsNone(building.basement_heated, 'building basement_heated is not none')
self.assertIsNone(building.attic_heated, 'building attic_heated is not none')
2022-03-08 19:19:52 -05:00
self.assertIsNone(building.terrains, 'building terrains is not none')
self.assertIsNotNone(building.year_of_construction, 'building year_of_construction is none')
self.assertIsNotNone(building.function, 'building function is none')
self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none')
2022-03-08 19:19:52 -05:00
self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground is not none')
self.assertEqual(len(building.heating), 0, 'building heating is not none')
self.assertEqual(len(building.cooling), 0, 'building cooling is not none')
self.assertIsNotNone(building.eave_height, 'building eave height is none')
self.assertIsNone(building.storeys, 'building storeys are defined')
self.assertIsNotNone(building.roof_type, 'building roof type is none')
self.assertIsNotNone(building.floor_area, 'building floor_area is none')
2022-03-08 19:19:52 -05:00
self.assertIsNone(building.households, 'building households is not none')
self.assertFalse(building.is_conditioned, 'building is_conditioned is conditioned')
def _check_surfaces(self, building):
for surface in building.surfaces:
self.assertIsNotNone(surface.name, 'surface name is none')
self.assertIsNotNone(surface.id, 'surface id is none')
self.assertIsNone(surface.swr, 'surface swr is not none')
self.assertIsNotNone(surface.lower_corner, 'surface envelope_lower_corner is none')
self.assertIsNotNone(surface.upper_corner, 'surface envelope_upper_corner is none')
self.assertIsNotNone(surface.area_below_ground, 'surface area_below_ground is none')
self.assertIsNotNone(surface.area_above_ground, 'surface area_above_ground is none')
self.assertIsNotNone(surface.azimuth, 'surface azimuth is none')
self.assertIsNotNone(surface.type, 'surface type is none')
self.assertIsNotNone(surface.inclination, 'surface inclination is none')
self.assertEqual(len(surface.global_irradiance), 0, 'global irradiance is calculated')
self.assertIsNotNone(surface.perimeter_polygon, 'surface perimeter_polygon is none')
self.assertIsNone(surface.holes_polygons, 'surface hole_polygons is not none')
self.assertIsNotNone(surface.solid_polygon, 'surface solid_polygon is none')
self.assertIsNone(surface.pv_system_installed, 'surface PV system installed is not none')
2022-03-08 19:19:52 -05:00
# citygml_classes
def test_import_citygml(self):
"""
2022-03-08 19:19:52 -05:00
Test city objects in the city
:return: None
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
2022-03-08 19:19:52 -05:00
self.assertTrue(len(city.buildings) == 1)
self._check_buildings(city)
for building in city.buildings:
2022-03-08 19:19:52 -05:00
self._check_surfaces(building)
# obj
def test_import_obj(self):
2021-08-27 12:51:30 -04:00
"""
Test obj import
"""
file = 'kelowna.obj'
city = self._get_obj(file)
self.assertIsNotNone(city, 'city is none')
2022-03-08 19:19:52 -05:00
self.assertTrue(len(city.buildings) == 1)
self._check_buildings(city)
for building in city.buildings:
2022-03-08 19:19:52 -05:00
self._check_surfaces(building)
# osm
def test_subway(self):
"""
Test subway parsing
:return:
"""
file_path = (self._example_path / 'subway.osm').resolve()
2021-09-23 09:17:23 -04:00
2021-08-27 12:51:30 -04:00
city = GeometryFactory('osm_subway', file_path).city
2021-09-23 09:17:23 -04:00
print(len(city.city_objects))
2021-08-27 12:51:30 -04:00
self.assertIsNotNone(city, 'subway entrances is none')
self.assertEqual(len(city.city_objects), 20, 'Wrong number of subway entrances')