-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(air): Support AirBoundary Constructions
- Add new AirBoundary Properties - Update Tests
- Loading branch information
Showing
5 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# -*- coding: utf-8 -*- | ||
# -*- Python Version: 2.7 -*- | ||
|
||
"""Passive House properties for honeybee_energy.construction.air.AirBoundaryConstruction Objects""" | ||
|
||
try: | ||
from typing import Any | ||
except ImportError: | ||
pass # Python 2.7 | ||
|
||
|
||
class AirBoundaryConstructionPhProperties_FromDictError(Exception): | ||
def __init__(self, _expected_types, _input_type): | ||
self.msg = 'Error: Expected type of "{}". Got: {}'.format(_expected_types, _input_type) | ||
super(AirBoundaryConstructionPhProperties_FromDictError, self).__init__(self.msg) | ||
|
||
|
||
class AirBoundaryConstructionPhProperties(object): | ||
def __init__(self, _host=None): | ||
# type (Any) -> None | ||
self._host = _host | ||
self.id_num = 0 | ||
|
||
@property | ||
def host(self): | ||
return self._host | ||
|
||
def duplicate(self, new_host=None): | ||
# type: (Any) -> AirBoundaryConstructionPhProperties | ||
return self.__copy__(new_host) | ||
|
||
def __copy__(self, new_host=None): | ||
# type: (Any) -> AirBoundaryConstructionPhProperties | ||
host = new_host or self.host | ||
|
||
new_obj = self.__class__(host) | ||
new_obj.id_num = self.id_num | ||
return new_obj | ||
|
||
def to_dict(self, abridged=False): | ||
# type: (bool) -> dict | ||
d = {} | ||
|
||
if abridged: | ||
d["type"] = "AirBoundaryConstructionPhPropertiesAbridged" | ||
else: | ||
d["type"] = "AirBoundaryConstructionPhProperties" | ||
|
||
d["id_num"] = self.id_num | ||
return {"ph": d} | ||
|
||
@classmethod | ||
def from_dict(cls, _input_dict, host): | ||
# type: (dict, Any) -> AirBoundaryConstructionPhProperties | ||
valid_types = ( | ||
"AirBoundaryConstructionPhProperties", | ||
"AirBoundaryConstructionPhPropertiesAbridged", | ||
) | ||
if _input_dict["type"] not in valid_types: | ||
raise AirBoundaryConstructionPhProperties_FromDictError(valid_types, _input_dict["type"]) | ||
|
||
new_obj = cls(host) | ||
new_obj.id_num = _input_dict["id_num"] | ||
return new_obj | ||
|
||
def __str__(self): | ||
return "{}(id_num={!r})".format(self.__class__.__name__, self.id_num) | ||
|
||
def __repr__(self): | ||
return str(self) | ||
|
||
def ToString(self): | ||
return str(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/test_honeybee_energy_ph/test_properties/test_construction/test_air.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from honeybee_energy_ph.properties.construction import air | ||
|
||
|
||
def test_default_air_construction_properties_dict_round_trip(): | ||
s1 = air.AirBoundaryConstructionPhProperties("host") | ||
d1 = s1.to_dict() | ||
s2 = air.AirBoundaryConstructionPhProperties.from_dict(d1["ph"], None) | ||
|
||
assert d1 == s2.to_dict() | ||
|
||
|
||
def test_custom_air_construction_properties_dict_round_trip(): | ||
s1 = air.AirBoundaryConstructionPhProperties("host") | ||
s1.id_num = 11223 | ||
d1 = s1.to_dict() | ||
s2 = air.AirBoundaryConstructionPhProperties.from_dict(d1["ph"], None) | ||
|
||
assert d1 == s2.to_dict() | ||
|
||
|
||
def test_default_air_construction_properties_duplicate(): | ||
s1 = air.AirBoundaryConstructionPhProperties("host") | ||
s2 = s1.duplicate() | ||
|
||
assert s1.to_dict() == s2.to_dict() | ||
|
||
|
||
def test_custom_air_construction_properties__wrong_type_from_dict(): | ||
wrong_dict = { | ||
"type": "not_allowed_type", | ||
} | ||
with pytest.raises(air.AirBoundaryConstructionPhProperties_FromDictError): | ||
s1 = air.AirBoundaryConstructionPhProperties.from_dict(wrong_dict, None) |
35 changes: 35 additions & 0 deletions
35
tests/test_honeybee_energy_ph/test_properties/test_construction/test_opaque.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from honeybee_energy_ph.properties.construction import opaque | ||
|
||
|
||
def test_default_opaque_construction_properties_dict_round_trip(): | ||
s1 = opaque.OpaqueConstructionPhProperties("host") | ||
d1 = s1.to_dict() | ||
s2 = opaque.OpaqueConstructionPhProperties.from_dict(d1["ph"], None) | ||
|
||
assert d1 == s2.to_dict() | ||
|
||
|
||
def test_custom_opaque_construction_properties_dict_round_trip(): | ||
s1 = opaque.OpaqueConstructionPhProperties("host") | ||
s1.id_num = 11223 | ||
d1 = s1.to_dict() | ||
s2 = opaque.OpaqueConstructionPhProperties.from_dict(d1["ph"], None) | ||
|
||
assert d1 == s2.to_dict() | ||
|
||
|
||
def test_default_opaque_construction_properties_duplicate(): | ||
s1 = opaque.OpaqueConstructionPhProperties("host") | ||
s2 = s1.duplicate() | ||
|
||
assert s1.to_dict() == s2.to_dict() | ||
|
||
|
||
def test_custom_opaque_construction_properties__wrong_type_from_dict(): | ||
wrong_dict = { | ||
"type": "not_allowed_type", | ||
} | ||
with pytest.raises(opaque.OpaqueConstructionPhProperties_FromDictError): | ||
s1 = opaque.OpaqueConstructionPhProperties.from_dict(wrong_dict, None) |