Skip to content

Commit

Permalink
fix(test): Update all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-p-may committed Sep 12, 2022
1 parent c435a7f commit cc2a797
Show file tree
Hide file tree
Showing 34 changed files with 2,150 additions and 1,366 deletions.
52 changes: 39 additions & 13 deletions PHX/from_HBJSON/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
from typing import List, Union, Tuple
from functools import partial

from honeybee import room, face
from honeybee.boundarycondition import Outdoors, Ground
from honeybee_energy.boundarycondition import Adiabatic
from honeybee_energy.load import infiltration, people, equipment, hotwater
try: # import the core honeybee dependencies
from honeybee.typing import clean_ep_string
except ImportError as e:
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:
from honeybee import room, face
from honeybee.boundarycondition import Outdoors, Ground
from honeybee_energy.boundarycondition import Adiabatic
from honeybee_energy import shw
from honeybee_energy.load import people, equipment, infiltration
from honeybee_energy.schedule.ruleset import ScheduleRuleset
from honeybee_energy.lib.scheduletypelimits import schedule_type_limit_by_identifier
except ImportError as e:
raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

from PHX.model import project


HB_BC = Union[Outdoors, Ground, Adiabatic]


Expand Down Expand Up @@ -81,7 +93,7 @@ def merge_occupancies(_hb_rooms: List[room.Room]) -> people.People:

# Build up the new object's attributes
total_floor_area = sum(rm.floor_area for rm in _hb_rooms)
new_hb_ppl = _hb_rooms[0].properties.energy.people.duplicate()
new_hb_ppl = _hb_rooms[0].properties.energy.people.duplicate() # type: ignore
new_hb_ppl.people_per_area = total_hb_people / total_floor_area
new_hb_ppl.properties.ph.number_bedrooms = total_ph_bedrooms
new_hb_ppl.properties.ph.number_people = total_ph_people
Expand Down Expand Up @@ -128,25 +140,39 @@ def merge_infiltrations(_hb_rooms: List[room.Room]) -> infiltration.Infiltration
return new_infil


def merge_shw(_hb_rooms: List[room.Room]) -> hotwater.ServiceHotWater:
"""
def merge_shw(_hb_rooms: List[room.Room]) -> shw.SHWSystem:
"""Merge together several Honeybee-Energy SHW System System objects.
Arguments:
----------
*
* _hb_rooms (List[room.Room]): The list of Honeybee Rooms to get the
SHW System System from.
Returns:
--------
*
* (shw.SHWSystem): A single new Honeybee-Energy
SHW System System Object.
"""
new_shw: hotwater.ServiceHotWater = _hb_rooms[0].properties.energy.shw.duplicate()

# -- Merge the SHWSystemPhProperties
new_prop = sum(hb_room.properties.energy.shw.properties.ph for hb_room in _hb_rooms)
new_shw.properties._ph = new_prop
# -- Find the first HBE SHWSystem System in the list of HB-Rooms, and use that as the 'base'
for room in _hb_rooms:
if room.properties.energy.shw: #type: ignore
new_shw: shw.SHWSystem = room.properties.energy.shw.duplicate() # type: ignore
break
else:
# -- If no SHWSystem found anywhere, return a new default HBE SHWSystem System
return shw.SHWSystem(
identifier=clean_ep_string('_default_shw_system_'),
equipment_type='Electric_WaterHeater',
)

# -- Merge the SHWSystemPhProperties and then apply it to the new HBE SHWSystem System
new_prop = sum(hb_room.properties.energy.shw.properties.ph for hb_room in _hb_rooms) # type: ignore
new_shw.properties._ph = new_prop # type: ignore

return new_shw


def merge_elec_equip(_hb_rooms: List[room.Room]) -> equipment.ElectricEquipment:
"""Returns a new HB-ElectricEquipment-Obj with it's values set from a list of input HB-Rooms.
Expand Down
6 changes: 3 additions & 3 deletions PHX/model/hvac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def get_mech_device_by_id(self, _id_num: int) -> hvac.PhxMechanicalDevice:
* (hvac.PhxMechanicalDevice): The Mechanical Device found with the
matching ID-Number. Or Error if not found.
"""
for sys in self._devices.values():
if sys.id_num == _id_num:
return sys
for device in self._devices.values():
if device.id_num == _id_num:
return device

raise NoVentUnitFoundError(_id_num)

Expand Down
5 changes: 4 additions & 1 deletion PHX/model/hvac/ventilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class PhxDeviceVentilator(PhxDeviceVentilation):
device_type: DeviceType = field(init=False, default=DeviceType.VENTILATION)
params: PhxDeviceVentilatorParams = field(
default_factory=PhxDeviceVentilatorParams)


def __post_init__(self):
super().__post_init__()

def __add__(self, other: PhxDeviceVentilator) -> PhxDeviceVentilator:
base = super().__add__(other)
new_obj = self.__class__.from_kwargs(**vars(base))
Expand Down
25 changes: 5 additions & 20 deletions _testing_to_WUFI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"""DEV SANDBOX: convert an HBJSON file over to WUFI XML format."""

import importlib
import pathlib

from rich import print
Expand All @@ -12,34 +11,20 @@
from PHX.to_WUFI_XML import xml_builder, xml_txt_to_file
from PHX.model import (building, project, geometry, schedules, certification,
constructions, elec_equip, components)
from tests.conftest import _reload_phx_classes, _reset_phx_class_counters

SOURCE_DIR = pathlib.Path("tests", "_source_hbjson")
SOURCE_DIR = pathlib.Path("sample", "hbjson")
source_file_names = [
# "Multi_Room_Complete.hbjson",
"220819_Chapman.hbjson",
"Default_Model_Single_Zone.hbjson",
"Multi_Room_Complete.hbjson",
]
SOURCE_FILES = [pathlib.Path(SOURCE_DIR, n) for n in source_file_names]
TARGET_DIR = pathlib.Path("tests", "_reference_xml")

def reload_PHX():
"""Reload all the PHX model modules to reset counters. This is only needed
so that the tests align when converting multiple models in one run."""
importlib.reload(geometry)
importlib.reload(building)
importlib.reload(project)
importlib.reload(geometry)
importlib.reload(schedules)
importlib.reload(certification)
importlib.reload(constructions)
importlib.reload(elec_equip)
importlib.reload(components)



def generate_xml_file(_source: pathlib.Path, _target_dir: pathlib.Path):
# -- Re-set all the PHX modules (counters)
reload_PHX()
_reload_phx_classes()
_reset_phx_class_counters()

target_file = pathlib.Path(_target_dir, _source.stem + '.xml')

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ filterwarnings = [

[tool.coverage.run]
# --- For testing...
command_line = "-m pytest tests"
command_line = "-m pytest . tests/test_to_WUFI_xml"
source = ["honeybee_ph"]
# ---
branch = true
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ honeybee-core>=1.51.11
honeybee-energy>=1.91.16
honeybee-schema>=1.50.2
honeybee-standards>=2.0.5
honeybee-ph>=1.2.2
ladybug-core>=0.39.55
ladybug-geometry>=1.24.2
ladybug-geometry-polyskel>=1.3.55
Expand Down
Loading

0 comments on commit cc2a797

Please sign in to comment.