Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-p-may committed Nov 2, 2023
1 parent 0ac0a22 commit ceb9a0a
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion PHX/from_WUFI_XML/phx_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion PHX/from_WUFI_XML/wufi_file_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -599,7 +600,7 @@ class Heating_Parameters(BaseModel):


class Device(BaseModel):
Name: str
Name: Optional[str]
IdentNr: int
SystemType: int
TypeDevice: int
Expand Down
23 changes: 23 additions & 0 deletions tests/test_from_WUFI/test_geometry/test_polygons.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/test_from_WUFI/test_geometry/test_vertices.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit ceb9a0a

Please sign in to comment.