def test_update_when_there_were_no_kpis_present(energy_system_handler_no_kpis, mocked_query_results): ''' Should not work! It cannot find the present KPI's in the prop -> Why? @Roos ''' handler = KPIHandler(energy_system_handler_no_kpis, 123456) # Mock the values returned by ETE handler.get_metrics = MagicMock(return_value=mocked_query_results) with pytest.raises(KeyError): handler.update()
def test_update_with_high_low_values(energy_system_handler_with_kpis, mocked_query_results): number_of_kpis = len(energy_system_handler_with_kpis.area().KPIs.kpi) assert number_of_kpis > 3 handler = KPIHandler(energy_system_handler_with_kpis, 123456) # Mock the values returned by ETE handler.get_metrics = MagicMock(return_value=mocked_query_results) handler.update() assert len(handler.energy_system.area().KPIs.kpi) == number_of_kpis
def test_add_kpis(energy_system_handler_no_kpis, mocked_query_results): # make sure we start without KPIs kpis_from_other_source = len(energy_system_handler_no_kpis.area().KPIs.kpi) handler = KPIHandler(energy_system_handler_no_kpis, 123456) # Mock the values returned by ETE handler.get_metrics = MagicMock(return_value=mocked_query_results) handler.add_kpis() # check that there extra are KPIs present assert len(handler.energy_system.area().KPIs.kpi) > kpis_from_other_source
def __attach_esdl_to_etm(self, energy_system_title): ''' Attach ESDL file to scenario ''' KPIHandler(self.energy_system_handler, self.scenario_id).add_kpis_to_esdl() result = AttachEsdlToEtengine.execute( self.scenario_id, self.energy_system_handler.get_as_stream(), energy_system_title) if not result.successful: fail_with(result)
def test_add_quantity_and_units(energy_system_handler_no_kpis): # Check how many quantities there are amount = sum( len(energy_system_handler_no_kpis.get_by_id(quantity)) for quantity in quantities if energy_system_handler_no_kpis.get_by_id(quantity)) print('initial amount of q&u present:', amount) handler = KPIHandler(energy_system_handler_no_kpis, 123456) handler.add_quantity_and_units() # how many now? amount = sum( len(handler.energy_system.get_by_id(quantity)) for quantity in quantities if handler.energy_system.get_by_id(quantity)) print('amount of q&u present after adding:', amount) # TODO: now they should be here! -> but they are not?? for quantity in quantities: assert handler.energy_system.get_by_id(quantity)
def update_esdl(energy_system, scenario_id): """ Updates the given energy system based on an ETM scenario id energy_system EnergySystemHandler, describing the energy_system that needs to be updated scenario_id int, ETM scenario that will be used to update the energy system """ # Update KPIs KPIHandler(energy_system, scenario_id).update() # Update capacities of wind turbines and possibly add measures for asset in get_configs_for_assets('WindTurbine'): if asset['parser'] == 'volatile': VolatileParser(energy_system, asset).update(scenario_id) return energy_system
def test_add_kpis_when_scenario_is_unknown(energy_system_handler_no_kpis): handler = KPIHandler(energy_system_handler_no_kpis, 123456) handler.get_metrics = MagicMock(side_effect=ETMParseError('No scenario')) with pytest.raises(ETMParseError): handler.add_kpis()