def fixture_with_leaves(): area = Area("house", [ PV("pv1", panel_count=1, config=create_config()), PV("pv2", panel_count=4, config=create_config()), HomeMeter("home meter", home_meter_profile="some_path.csv", config=create_config()), ]) return area_to_string(area)
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"
def appliance_fixture(): child1 = Area('child1', appliance=PVAppliance(initially_on=False)) child2 = Area('child2', appliance=PVAppliance()) return area_to_string(Area('parent', [child1, child2]))
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
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
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
def test_encode_strategy_appliance(): area = Area("child", [], None, PVStrategy(), PVAppliance()) area_dict = json.loads(area_to_string(area)) assert 'children' not in area_dict assert area_dict['strategy']['type'] == 'PVStrategy' assert area_dict['appliance']['type'] == 'PVAppliance'
def budget_keeper_fixture(): child = Area('child', appliance=PVAppliance()) budget_keeper = BudgetKeeper(budget=100.0, days_per_period=30) return area_to_string(Area('parent', [child], budget_keeper=budget_keeper))
def fixture_with_leaves(): area = Area("house", [PV("pv1", panel_count=1), PV("pv2", panel_count=4)]) return area_to_string(area)
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
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