hub/non_functional_tests/test_exports.py

77 lines
3.0 KiB
Python
Raw Normal View History

"""
TestExports test and validate the city export formats
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from unittest import TestCase
import pandas as pd
from imports.geometry_factory import GeometryFactory
from imports.construction_factory import ConstructionFactory
from imports.schedules_factory import SchedulesFactory
from imports.usage_factory import UsageFactory
from exports.exports_factory import ExportsFactory
import helpers.constants as cte
from city_model_structure.city import City
class TestExports(TestCase):
"""
TestExports class contains the unittest for export functionality
"""
def setUp(self) -> None:
"""
Test setup
:return: None
"""
self._city = None
self._complete_city = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
self._output_path = (Path(__file__).parent / 'tests_outputs').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_complete_city(self, from_pickle):
if self._complete_city is None:
if from_pickle:
file_path = (self._example_path / 'ConcordiaSWGcampus.pickle').resolve()
self._complete_city = City.load(file_path)
else:
file_path = (self._example_path / 'one_building_in_kelowna.gml').resolve()
self._complete_city = self._get_citygml(file_path)
ConstructionFactory('ca', self._complete_city).enrich()
UsageFactory('ca', self._complete_city).enrich()
SchedulesFactory('comnet', self._complete_city).enrich()
cli = 'C:\\Users\\Pilar\\PycharmProjects\\monthlyenergybalance\\tests_data\\weather\\inseldb_Summerland.cli'
self._complete_city.climate_file = Path(cli)
self._complete_city.climate_reference_city = 'Summerland'
dummy_measures = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
for building in self._complete_city.buildings:
building.heating[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures})
building.cooling[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures})
building.heating[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]})
building.cooling[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]})
return self._complete_city
def _export(self, export_type, from_pickle=False):
self._complete_city = self._get_complete_city(from_pickle)
ExportsFactory(export_type, self._complete_city, self._output_path).export()
def test_obj_export(self):
self._export('obj', True)
def test_stl_export(self):
self._export('stl', True)
def test_energy_ade_export(self):
self._export('energy_ade')
def test_sra_export(self):
self._export('sra')