From ceb9a0afb21ef35ce9afcecc91499883c0482389 Mon Sep 17 00:00:00 2001 From: PH Tools Date: Thu, 2 Nov 2023 21:31:13 +0100 Subject: [PATCH] add tests --- PHX/from_WUFI_XML/phx_schemas.py | 2 +- PHX/from_WUFI_XML/wufi_file_schema.py | 3 ++- .../test_geometry/test_polygons.py | 23 ++++++++++++++++++ .../test_geometry/test_vertices.py | 24 +++++++++++++++++++ .../__init__.py | 0 .../test_new_xml_util_patterns_occupancy.py | 15 +++++++----- .../test_new_xml_util_patterns_ventilation.py | 0 .../__init__.py | 0 .../test_new_xml_project_assemblies.py | 0 .../test_new_xml_project_data.py | 0 .../test_new_xml_project_windows.py | 0 .../test_read_xml_file.py | 0 .../__init__.py | 0 .../test_building_components.py | 0 .../test_buildings.py | 0 .../test_variants.py | 0 16 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 tests/test_from_WUFI/test_geometry/test_polygons.py create mode 100644 tests/test_from_WUFI/test_geometry/test_vertices.py rename tests/test_from_WUFI/{test_patterns_from_WUFI => test_patterns}/__init__.py (100%) rename tests/test_from_WUFI/{test_patterns_from_WUFI => test_patterns}/test_new_xml_util_patterns_occupancy.py (62%) rename tests/test_from_WUFI/{test_patterns_from_WUFI => test_patterns}/test_new_xml_util_patterns_ventilation.py (100%) rename tests/test_from_WUFI/{test_project_from_WUFI => test_project}/__init__.py (100%) rename tests/test_from_WUFI/{test_project_from_WUFI => test_project}/test_new_xml_project_assemblies.py (100%) rename tests/test_from_WUFI/{test_project_from_WUFI => test_project}/test_new_xml_project_data.py (100%) rename tests/test_from_WUFI/{test_project_from_WUFI => test_project}/test_new_xml_project_windows.py (100%) rename tests/test_from_WUFI/{test_project_from_WUFI => test_project}/test_read_xml_file.py (100%) rename tests/test_from_WUFI/{test_variants_from_WUFI => test_variants}/__init__.py (100%) rename tests/test_from_WUFI/{test_variants_from_WUFI => test_variants}/test_building_components.py (100%) rename tests/test_from_WUFI/{test_variants_from_WUFI => test_variants}/test_buildings.py (100%) rename tests/test_from_WUFI/{test_variants_from_WUFI => test_variants}/test_variants.py (100%) diff --git a/PHX/from_WUFI_XML/phx_schemas.py b/PHX/from_WUFI_XML/phx_schemas.py index fb0e855..48fdd79 100644 --- a/PHX/from_WUFI_XML/phx_schemas.py +++ b/PHX/from_WUFI_XML/phx_schemas.py @@ -1412,7 +1412,7 @@ def _PhxMechanicalDevice(_data: wufi_xml.Device) -> Any: def _PhxDevice_Ventilation(_data: wufi_xml.Device) -> PhxDeviceVentilator: phx_obj = PhxDeviceVentilator() - phx_obj.display_name = _data.Name + phx_obj.display_name = _data.Name or "unnamed_device" phx_obj.id_num = _data.IdentNr phx_obj.identifier = str(_data.IdentNr) diff --git a/PHX/from_WUFI_XML/wufi_file_schema.py b/PHX/from_WUFI_XML/wufi_file_schema.py index 162258c..2e52081 100644 --- a/PHX/from_WUFI_XML/wufi_file_schema.py +++ b/PHX/from_WUFI_XML/wufi_file_schema.py @@ -501,6 +501,7 @@ class Duct(BaseModel): _unpack_xml_tag_name = validator("*", allow_reuse=True, pre=True)(unpack_xml_tag) + class PHDistribution(BaseModel): # TODO DistributionHeating: DistributionHeating DistributionDHW: Optional[DistributionDHW] @@ -599,7 +600,7 @@ class Heating_Parameters(BaseModel): class Device(BaseModel): - Name: str + Name: Optional[str] IdentNr: int SystemType: int TypeDevice: int diff --git a/tests/test_from_WUFI/test_geometry/test_polygons.py b/tests/test_from_WUFI/test_geometry/test_polygons.py new file mode 100644 index 0000000..5348992 --- /dev/null +++ b/tests/test_from_WUFI/test_geometry/test_polygons.py @@ -0,0 +1,23 @@ +from PHX.model.project import PhxProject, PhxVariant + + +def _total_num_polygons(variant: PhxVariant) -> int: + """Calculate the total number of Polygons in a variant.""" + return len( + [ + p for c in variant.building.all_components + for p in c.polygons + ] + ) + +def test_building_has_same_number_of_polygons( + create_phx_project_from_hbjson: PhxProject, + create_phx_project_from_wufi_xml: PhxProject, +) -> None: + for hbjson_variant, wufi_xml_variant in zip( + create_phx_project_from_hbjson.variants, + create_phx_project_from_wufi_xml.variants, + ): + num_hbjson_polygons = _total_num_polygons(hbjson_variant) + num_xml_polygons = _total_num_polygons(wufi_xml_variant) + assert num_hbjson_polygons == num_xml_polygons diff --git a/tests/test_from_WUFI/test_geometry/test_vertices.py b/tests/test_from_WUFI/test_geometry/test_vertices.py new file mode 100644 index 0000000..fb3c5f5 --- /dev/null +++ b/tests/test_from_WUFI/test_geometry/test_vertices.py @@ -0,0 +1,24 @@ +from PHX.model.project import PhxProject, PhxVariant + + +def _total_num_vertices(variant: PhxVariant) -> int: + """Calculate the total number of vertices in a variant.""" + return len( + [ + v for c in variant.building.all_components + for p in c.polygons + for v in p.vertices + ] + ) + +def test_building_has_same_number_of_vertices( + create_phx_project_from_hbjson: PhxProject, + create_phx_project_from_wufi_xml: PhxProject, +) -> None: + for hbjson_variant, wufi_xml_variant in zip( + create_phx_project_from_hbjson.variants, + create_phx_project_from_wufi_xml.variants, + ): + num_hbjson_vertices = _total_num_vertices(hbjson_variant) + num_xml_vertices = _total_num_vertices(wufi_xml_variant) + assert num_hbjson_vertices == num_xml_vertices diff --git a/tests/test_from_WUFI/test_patterns_from_WUFI/__init__.py b/tests/test_from_WUFI/test_patterns/__init__.py similarity index 100% rename from tests/test_from_WUFI/test_patterns_from_WUFI/__init__.py rename to tests/test_from_WUFI/test_patterns/__init__.py diff --git a/tests/test_from_WUFI/test_patterns_from_WUFI/test_new_xml_util_patterns_occupancy.py b/tests/test_from_WUFI/test_patterns/test_new_xml_util_patterns_occupancy.py similarity index 62% rename from tests/test_from_WUFI/test_patterns_from_WUFI/test_new_xml_util_patterns_occupancy.py rename to tests/test_from_WUFI/test_patterns/test_new_xml_util_patterns_occupancy.py index 75b541b..9101517 100644 --- a/tests/test_from_WUFI/test_patterns_from_WUFI/test_new_xml_util_patterns_occupancy.py +++ b/tests/test_from_WUFI/test_patterns/test_new_xml_util_patterns_occupancy.py @@ -7,6 +7,8 @@ def _find_matching_pattern( _util_pattern: PhxScheduleOccupancy, _util_patterns: ValuesView[PhxScheduleOccupancy], ) -> PhxScheduleOccupancy: + """Helper Function: Find the matching pattern in the XML set""" + for pat in _util_patterns: if _util_pattern.display_name == pat.display_name: return pat @@ -20,16 +22,17 @@ def test_vent_patterns_match( create_phx_project_from_wufi_xml: PhxProject, ) -> None: # -- Pull out the Occupancy Patterns - util_pats_hbjson = ( + utilization_patterns_from_hbjson = ( create_phx_project_from_hbjson.utilization_patterns_occupancy.patterns ) - util_pats_xml = ( + utilization_patterns_from_xml = ( create_phx_project_from_wufi_xml.utilization_patterns_occupancy.patterns ) - assert len(util_pats_hbjson) == len(util_pats_xml) + assert len(utilization_patterns_from_hbjson) == len(utilization_patterns_from_xml) - for pattern_hbjson in util_pats_hbjson.values(): - util_pat_xml = _find_matching_pattern(pattern_hbjson, util_pats_xml.values()) + for pattern_from_hbjson in utilization_patterns_from_hbjson.values(): + pattern_from_xml = _find_matching_pattern(pattern_from_hbjson, + utilization_patterns_from_xml.values()) - assert util_pat_xml == pattern_hbjson + assert pattern_from_xml == pattern_from_hbjson diff --git a/tests/test_from_WUFI/test_patterns_from_WUFI/test_new_xml_util_patterns_ventilation.py b/tests/test_from_WUFI/test_patterns/test_new_xml_util_patterns_ventilation.py similarity index 100% rename from tests/test_from_WUFI/test_patterns_from_WUFI/test_new_xml_util_patterns_ventilation.py rename to tests/test_from_WUFI/test_patterns/test_new_xml_util_patterns_ventilation.py diff --git a/tests/test_from_WUFI/test_project_from_WUFI/__init__.py b/tests/test_from_WUFI/test_project/__init__.py similarity index 100% rename from tests/test_from_WUFI/test_project_from_WUFI/__init__.py rename to tests/test_from_WUFI/test_project/__init__.py diff --git a/tests/test_from_WUFI/test_project_from_WUFI/test_new_xml_project_assemblies.py b/tests/test_from_WUFI/test_project/test_new_xml_project_assemblies.py similarity index 100% rename from tests/test_from_WUFI/test_project_from_WUFI/test_new_xml_project_assemblies.py rename to tests/test_from_WUFI/test_project/test_new_xml_project_assemblies.py diff --git a/tests/test_from_WUFI/test_project_from_WUFI/test_new_xml_project_data.py b/tests/test_from_WUFI/test_project/test_new_xml_project_data.py similarity index 100% rename from tests/test_from_WUFI/test_project_from_WUFI/test_new_xml_project_data.py rename to tests/test_from_WUFI/test_project/test_new_xml_project_data.py diff --git a/tests/test_from_WUFI/test_project_from_WUFI/test_new_xml_project_windows.py b/tests/test_from_WUFI/test_project/test_new_xml_project_windows.py similarity index 100% rename from tests/test_from_WUFI/test_project_from_WUFI/test_new_xml_project_windows.py rename to tests/test_from_WUFI/test_project/test_new_xml_project_windows.py diff --git a/tests/test_from_WUFI/test_project_from_WUFI/test_read_xml_file.py b/tests/test_from_WUFI/test_project/test_read_xml_file.py similarity index 100% rename from tests/test_from_WUFI/test_project_from_WUFI/test_read_xml_file.py rename to tests/test_from_WUFI/test_project/test_read_xml_file.py diff --git a/tests/test_from_WUFI/test_variants_from_WUFI/__init__.py b/tests/test_from_WUFI/test_variants/__init__.py similarity index 100% rename from tests/test_from_WUFI/test_variants_from_WUFI/__init__.py rename to tests/test_from_WUFI/test_variants/__init__.py diff --git a/tests/test_from_WUFI/test_variants_from_WUFI/test_building_components.py b/tests/test_from_WUFI/test_variants/test_building_components.py similarity index 100% rename from tests/test_from_WUFI/test_variants_from_WUFI/test_building_components.py rename to tests/test_from_WUFI/test_variants/test_building_components.py diff --git a/tests/test_from_WUFI/test_variants_from_WUFI/test_buildings.py b/tests/test_from_WUFI/test_variants/test_buildings.py similarity index 100% rename from tests/test_from_WUFI/test_variants_from_WUFI/test_buildings.py rename to tests/test_from_WUFI/test_variants/test_buildings.py diff --git a/tests/test_from_WUFI/test_variants_from_WUFI/test_variants.py b/tests/test_from_WUFI/test_variants/test_variants.py similarity index 100% rename from tests/test_from_WUFI/test_variants_from_WUFI/test_variants.py rename to tests/test_from_WUFI/test_variants/test_variants.py