diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bbd6efa..cea32b0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: # - name: install python dependencies # run: | # python -m pip install --upgrade pip - # pip install .[dev] + # pip install '.[dev]' # - name: run tests # run: python -m pytest tests/ diff --git a/honeybee_energy_revive/_extend_honeybee_energy_revive.py b/honeybee_energy_revive/_extend_honeybee_energy_revive.py index 797b0aa..32526ce 100644 --- a/honeybee_energy_revive/_extend_honeybee_energy_revive.py +++ b/honeybee_energy_revive/_extend_honeybee_energy_revive.py @@ -37,12 +37,20 @@ OpaqueConstructionProperties, PeopleProperties, ProcessProperties, - PVPropertiesProperties, ServiceHotWaterProperties, ShadeConstructionProperties, WindowConstructionProperties, WindowConstructionShadeProperties, ) + +try: + from honeybee_energy.properties.extension import PVPropertiesProperties +except ImportError: + # -- Until Chris merges the PR, we need to use the MockPVPropertiesProperties + # -- https://github.com/ladybug-tools/honeybee-energy + from honeybee_energy_revive.properties.generator.pv import MockPVPropertiesProperties as PVPropertiesProperties + + from honeybee_energy.schedule.ruleset import ScheduleRulesetProperties # -- Constructions diff --git a/honeybee_energy_revive/properties/generator/pv.py b/honeybee_energy_revive/properties/generator/pv.py index 11bba76..69de8a6 100644 --- a/honeybee_energy_revive/properties/generator/pv.py +++ b/honeybee_energy_revive/properties/generator/pv.py @@ -128,3 +128,9 @@ def __repr__(self): def ToString(self): return str(self) + + +class MockPVPropertiesProperties(object): + + def __init__(self): + pass diff --git a/tests/test_honeybee_energy_revive/properties/generator/__init__.py b/tests/test_honeybee_energy_revive/properties/generator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_honeybee_energy_revive/properties/generator/test_pv.py b/tests/test_honeybee_energy_revive/properties/generator/test_pv.py new file mode 100644 index 0000000..c2498df --- /dev/null +++ b/tests/test_honeybee_energy_revive/properties/generator/test_pv.py @@ -0,0 +1,88 @@ +from unittest.mock import Mock + +import pytest + +from honeybee_energy_revive.properties.generator.pv import ( + PVPropertiesReviveProperties, + PVPropertiesReviveProperties_FromDictError, +) + + +@pytest.fixture +def mock_host(): + return Mock(display_name="Test PvProperties") + + +def test_pv_revive_properties_init(mock_host): + props = PVPropertiesReviveProperties(mock_host) + assert props.host == mock_host + assert props.id_num == 0 + + +def test_pv_revive_properties_host_name(mock_host): + props = PVPropertiesReviveProperties(mock_host) + assert props.host_name == "Test PvProperties" + + props_no_host = PVPropertiesReviveProperties() + assert props_no_host.host_name == "No Host" + + +def test_pv_revive_properties_duplicate(mock_host): + props = PVPropertiesReviveProperties(mock_host) + props.id_num = 5 + + new_host = Mock(display_name="Test PvProperties") + new_props = props.duplicate(new_host) + assert new_props.host == new_host + assert new_props.id_num == 5 + + +def test_pv_revive_properties_to_dict(mock_host): + props = PVPropertiesReviveProperties(mock_host) + props.id_num = 5 + + expected_dict = { + "revive": { + "type": "PVPropertiesReviveProperties", + "id_num": 5, + "cost": 0.0, + "labor_fraction": 0.0, + "lifetime_years": 0, + } + } + assert props.to_dict() == expected_dict + + expected_abridged_dict = { + "revive": { + "type": "PVPropertiesRevivePropertiesAbridged", + "id_num": 5, + "cost": 0.0, + "labor_fraction": 0.0, + "lifetime_years": 0, + } + } + assert props.to_dict(abridged=True) == expected_abridged_dict + + +def test_pv_revive_properties_from_dict(mock_host): + input_dict = { + "type": "PVPropertiesReviveProperties", + "id_num": 5, + "cost": 0.0, + "labor_fraction": 0.0, + "lifetime_years": 0, + } + props = PVPropertiesReviveProperties.from_dict(input_dict, mock_host) + assert props.host == mock_host + assert props.id_num == 5 + + with pytest.raises(PVPropertiesReviveProperties_FromDictError): + invalid_dict = {"type": "InvalidType", "id_num": 5} + PVPropertiesReviveProperties.from_dict(invalid_dict, mock_host) + + +def test_pv_revive_properties_str_repr(mock_host): + props = PVPropertiesReviveProperties(mock_host) + expected_str = "HBE-PVPropertiesRevive Phius REVIVE Property: [host: Test PvProperties]" + assert str(props) == expected_str + assert repr(props) == expected_str