示例#1
0
def test_leaf_external_connection_deserialization():
    recovered = area_from_string(
        '''{
             "name": "house",
             "children":[
                 {"name": "pv1", "type": "PV", "panel_count": 4, "display_type": "PV",
                 "allow_external_connection": true},
                 {"name": "load1", "type": "LoadHours", "avg_power_W": 200, "display_type": "Load",
                 "allow_external_connection": true},
                 {"name": "storage1", "type": "Storage", "display_type": "Storage",
                 "allow_external_connection": true}
             ]
           }
        ''',
        create_config({"external_connection_enabled": True})
    )

    pv1, load1, storage1 = recovered.children
    assert isinstance(pv1, PV)
    assert isinstance(pv1.strategy, PVExternalStrategy)
    assert pv1.strategy.panel_count == 4
    assert pv1.display_type == "PV"
    assert isinstance(load1, LoadHours)
    assert isinstance(load1.strategy, LoadHoursExternalStrategy)
    assert load1.strategy.avg_power_W == 200
    assert load1.display_type == "Load"
    assert isinstance(storage1, Storage)
    assert isinstance(storage1.strategy, StorageExternalStrategy)
    assert storage1.display_type == "Storage"
示例#2
0
def test_area_with_children_roundtrip():
    child1 = Area("child1")
    child2 = Area("child2")
    parent = Area("parent", [child1, child2])
    string = area_to_string(parent)
    recovered = area_from_string(string)
    assert recovered.name == "parent"
    assert recovered.children[0].name == "child1"
    assert recovered.children[1].name == "child2"
示例#3
0
def get_setup(config):
    try:
        setup_path = os.environ['D3A_SETUP_PATH']
        with open(setup_path, 'r') as area_file:
            area_str = area_file.read().replace('\n', '')
        recovered_area = area_from_string(area_str)
        recovered_area.config = config
        return recovered_area
    except KeyError as d3a_key_error:
        raise RuntimeError(
            'D3_SETUP_PATH environment variable not found.') from d3a_key_error
    except FileNotFoundError as d3a_file_error:
        raise RuntimeError('D3A setup file containing area not found on the D3_SETUP_PATH') \
            from d3a_file_error
示例#4
0
def test_leaf_deserialization():
    recovered = area_from_string('''{
             "name": "house",
             "children":[
                 {"name": "pv1", "type": "PV", "panel_count": 4, "risk": 50},
                 {"name": "pv2", "type": "PV", "panel_count": 1, "risk": 10}
             ]
           }
        ''')
    pv1, pv2 = recovered.children
    assert isinstance(pv1, PV)
    assert pv1.strategy.panel_count == 4 and pv1.strategy.risk == 50
    assert isinstance(pv2, PV)
    assert pv2.strategy.panel_count == 1 and pv2.strategy.risk == 10
示例#5
0
def test_leaf_deserialization():
    recovered = area_from_string('''{
             "name": "house",
             "children":[
                 {"name": "pv1", "type": "PV", "panel_count": 4, "display_type": "PV"},
                 {"name": "pv2", "type": "PV", "panel_count": 1, "display_type": "PV"}
             ]
           }
        ''')
    pv1, pv2 = recovered.children
    assert isinstance(pv1, PV)
    assert pv1.strategy.panel_count == 4
    assert pv1.display_type == "PV"
    assert isinstance(pv2, PV)
    assert pv2.strategy.panel_count == 1
    assert pv2.display_type == "PV"
示例#6
0
def test_leaf_deserialization():
    recovered = area_from_string(
        '''{
             "name": "house",
             "children":[
                 {"name": "pv1", "type": "PV", "panel_count": 4, "display_type": "PV"},
                 {"name": "pv2", "type": "PV", "panel_count": 1, "display_type": "PV"},
                 {"name": "home meter", "type": "HomeMeter", "home_meter_profile": "some_path.csv"}
             ]
           }
        ''',
        config=create_config()
    )
    pv1, pv2, home_meter = recovered.children
    assert isinstance(pv1, PV)
    assert pv1.strategy.panel_count == 4
    assert pv1.display_type == "PV"
    assert isinstance(pv2, PV)
    assert pv2.strategy.panel_count == 1
    assert pv2.display_type == "PV"
    assert isinstance(home_meter, HomeMeter)
示例#7
0
def test_appliance_roundtrip(appliance_fixture):
    recovered = area_from_string(appliance_fixture)
    assert recovered.children[1].appliance.initially_on
    assert not recovered.children[0].appliance.is_on
示例#8
0
def test_non_attr_param():
    area1 = Area('area1', [], None, PVStrategy())
    recovered1 = area_from_string(area_to_string(area1))
    assert recovered1.strategy.max_panel_power_W is None
    assert recovered1.strategy.offer_update.final_rate[area1.config.start_date] == \
        ConstSettings.PVSettings.SELLING_RATE_RANGE.final
示例#9
0
def test_strategy_roundtrip_with_params():
    area = Area('area', [], None, PVStrategy(panel_count=42))
    area_str = area_to_string(area)
    recovered = area_from_string(area_str)
    assert recovered.strategy.panel_count == 42
示例#10
0
def test_raises_unknown_class():
    with pytest.raises(ValueError):
        area_from_string("{'name':'broken','strategy':'NonexistentStrategy'}")
示例#11
0
def test_strategy_appliance_roundtrip():
    area = Area("child", [], None, PVStrategy(), PVAppliance())
    recovered = area_from_string(area_to_string(area))
    assert type(recovered.strategy) is PVStrategy
    assert type(recovered.appliance) is PVAppliance
示例#12
0
def test_budget_keeper_roundtrip(budget_keeper_fixture):
    recovered = area_from_string(budget_keeper_fixture)
    assert recovered.budget_keeper.budget == 100.0
    assert recovered.budget_keeper.days_per_period == 30
示例#13
0
def test_roundtrip_with_leaf(fixture_with_leaves):
    recovered = area_from_string(fixture_with_leaves)
    assert isinstance(recovered.children[0].strategy, PVStrategy)
    assert isinstance(recovered.children[1].strategy, PVStrategy)
示例#14
0
def test_roundtrip_with_leaf(fixture_with_leaves):
    recovered = area_from_string(fixture_with_leaves, create_config())
    assert isinstance(recovered.children[0].strategy, PVStrategy)
    assert isinstance(recovered.children[1].strategy, PVStrategy)
    assert isinstance(recovered.children[2].strategy, HomeMeterStrategy)
示例#15
0
def test_non_attr_param():
    area1 = Area('area1', [], PVStrategy())
    recovered1 = area_from_string(area_to_string(area1))
    assert recovered1.strategy.min_selling_rate == ConstSettings.PVSettings.MIN_SELLING_RATE
示例#16
0
def test_strategy_roundtrip_with_params():
    area = Area('area', [], PVStrategy(panel_count=42, risk=1))
    area_str = area_to_string(area)
    assert json.loads(area_str)['strategy']['kwargs']['risk'] == 1
    recovered = area_from_string(area_str)
    assert recovered.strategy.panel_count == 42