Skip to content

Commit

Permalink
added some test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Apr 4, 2018
1 parent a38cea7 commit 40fcba9
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 7 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ omit =
energy_demand/read_and_plot_results.py
energy_demand/geography/write_shp.py
energy_demand/basic/logger_setup.py
energy_demand/basic/lookup_tables.py
energy_demand/charts/*
energy_demand/cli/*
energy_demand/validation/*
Expand Down
3 changes: 3 additions & 0 deletions .pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tests/technologies/test_fuel_service_switch.py::test_sum_fuel_across_sectors": true
}
95 changes: 95 additions & 0 deletions .pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[
"tests/test_enduse_func.py::test_assign_lp_no_techs",
"tests/test_enduse_func.py::test_get_peak_day",
"tests/test_enduse_func.py::test_service_switch",
"tests/test_enduse_func.py::test_convert_service_to_p",
"tests/test_enduse_func.py::test_calc_lf_improvement",
"tests/test_enduse_func.py::test_Enduse",
"tests/test_enduse_func.py::test_get_enduse_tech",
"tests/test_enduse_func.py::test_apply_smart_metering",
"tests/test_enduse_func.py::test_fuel_to_service",
"tests/test_enduse_func.py::test_service_to_fuel",
"tests/test_enduse_func.py::test_apply_heat_recovery",
"tests/test_enduse_func.py::test_apply_climate_chante",
"tests/test_enduse_func.py::test_calc_fuel_tech_y",
"tests/test_enduse_func.py::test_calc_fuel_tech_yh",
"tests/test_enduse_func.py::test_apply_specific_change",
"tests/test_enduse_func.py::test_get_enduse_configuration",
"tests/test_enduse_func.py::test_apply_cooling",
"tests/test_enduse_func.py::test_calc_service_switch",
"tests/assumptions/test_assumptions_fuel_share.py::test_assign_by_fuel_tech_p",
"tests/assumptions/test_base_assumptions.py::test_load_non_param_assump",
"tests/assumptions/test_base_assumptions.py::test_load_param_assump",
"tests/basic/test_basic_functions.py::test_get_month_from_string",
"tests/basic/test_basic_functions.py::test_array_to_dict",
"tests/basic/test_conversions.py::test_conversion_ktoe_gwh",
"tests/basic/test_conversions.py::test_kwh_to_gwh",
"tests/basic/test_conversions.py::test_ktoe_to_twh",
"tests/basic/test_conversions.py::test_mw_to_gwhh",
"tests/basic/test_conversions.py::test_convert_fueltypes_ktoe_GWh",
"tests/basic/test_conversions.py::test_convert_fueltypes_sectors_ktoe_gwh",
"tests/basic/test_date_prob.py::test_get_season",
"tests/basic/test_date_prob.py::test_get_model_yeardays_daytype",
"tests/basic/test_date_prob.py::test_get_month_from_yeraday",
"tests/basic/test_date_prob.py::test_date_to_yearday",
"tests/basic/test_date_prob.py::test_yearday_to_date",
"tests/basic/test_date_prob.py::test_fullyear_dates",
"tests/basic/test_date_prob.py::test_get_weekday_type",
"tests/dwelling_stock/test_dw_stock.py::test_get_tot_pop",
"tests/dwelling_stock/test_dw_stock.py::test_get_scenario_driver",
"tests/dwelling_stock/test_dw_stock.py::test_dwelling",
"tests/geography/test_weather_region.py::test_get_shape_peak_yd_factor",
"tests/geography/test_weather_region.py::test_change_temp_climate",
"tests/initialisations/test_helpers.py::test_init_dict_brackets",
"tests/initialisations/test_helpers.py::test_get_nested_dict_key",
"tests/initialisations/test_helpers.py::test_set_same_eff_all_tech",
"tests/profiles/test_hdd_cdd.py::test_effective_temps",
"tests/profiles/test_hdd_cdd.py::test_calc_hdd",
"tests/profiles/test_hdd_cdd.py::test_calc_cdd",
"tests/profiles/test_hdd_cdd.py::test_sigm_temp",
"tests/profiles/test_hdd_cdd.py::test_get_hdd_country",
"tests/profiles/test_hdd_cdd.py::test_get_cdd_country",
"tests/profiles/test_hdd_cdd.py::test_calc_reg_hdd",
"tests/profiles/test_hdd_cdd.py::test_calc_reg_cdd",
"tests/profiles/test_load_factors.py::test_peak_shaving_max_min",
"tests/profiles/test_load_factors.py::test_calc_lf_d",
"tests/profiles/test_load_factors.py::test_calc_lf_y",
"tests/profiles/test_load_factors.py::test_calc_lf_season",
"tests/profiles/test_load_profile.py::test_abs_to_rel",
"tests/profiles/test_load_profile.py::test_calk_peak_h_dh",
"tests/profiles/test_load_profile.py::test_LoadProfileStock",
"tests/profiles/test_load_profile.py::test_generate_key_lu_dict",
"tests/profiles/test_load_profile.py::test_LoadProfile",
"tests/profiles/test_load_profile.py::test_calc_av_lp",
"tests/scripts/test_s_disaggregation.py::test_rs_disaggregate",
"tests/scripts/test_s_disaggregation.py::test_ss_disaggregate",
"tests/scripts/test_s_disaggregation.py::test_is_ss_disaggregate",
"tests/scripts/test_s_fuel_to_service.py::test_init_nested_dict_zero",
"tests/scripts/test_s_fuel_to_service.py::test_sum_2_level_dict",
"tests/scripts/test_s_fuel_to_service.py::test_get_s_fueltype_tech",
"tests/scripts/test_s_generate_sigmoid.py::test_tech_sigmoid_paramters",
"tests/scripts/test_s_generate_sigmoid.py::test_calc_sigmoid_parameters",
"tests/scripts/test_s_generate_sigmoid.py::test_calc_sigmoid_parameters2",
"tests/scripts/test_s_generate_sigmoid.py::test_get_tech_installed",
"tests/scripts/test_s_generate_sigmoid.py::test_calc_service_fuel_switched",
"tests/scripts/test_s_generate_sigmoid.py::test_tech_l_sigmoid",
"tests/scripts/test_s_generate_sigmoid.py::test_get_sig_diffusion",
"tests/scripts/test_s_rs_raw_shapes.py::test_assign_hes_data_to_year",
"tests/technologies/test_diffusion_technologies.py::test_linear_diff",
"tests/technologies/test_diffusion_technologies.py::test_sigmoid_diffusion",
"tests/technologies/test_fuel_service_switch.py::test_switches_to_dict",
"tests/technologies/test_fuel_service_switch.py::test_get_switch_criteria",
"tests/technologies/test_fuel_service_switch.py::test_sum_fuel_across_sectors",
"tests/technologies/test_fuel_service_switch.py::test_create_service_switch",
"tests/technologies/test_fuel_service_switch.py::test_capacity_switch",
"tests/technologies/test_fuel_service_switch.py::test_get_share_s_tech_ey",
"tests/technologies/test_tech_related.py::test_get_tech_type",
"tests/technologies/test_tech_related.py::test_calc_eff_cy",
"tests/technologies/test_tech_related.py::test_calc_hp_eff",
"tests/technologies/test_tech_related.py::test_eff_heat_pump",
"tests/technologies/test_tech_related.py::test_get_fueltype_str",
"tests/technologies/test_tech_related.py::test_get_fueltype_int",
"tests/technologies/test_tech_related.py::test_calc_av_heat_pump_eff_ey",
"tests/technologies/test_technological_stock.py::test_Technology",
"tests/technologies/test_technological_stock.py::test_TechStock"
]
2 changes: 1 addition & 1 deletion energy_demand/plotting/plotting_multiple_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def plot_radar_plots_average_peak_day(
"""Compare averaged dh profile overall regions for peak day
for future year and base year
TODO: SO FAR ONLY FOR ONE SCENARIO
MAYBE: SO FAR ONLY FOR ONE SCENARIO
"""
lookups = lookup_tables.basic_lookups()

Expand Down
12 changes: 6 additions & 6 deletions energy_demand/technologies/fuel_service_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ def get_switch_criteria(

return crit_switch_service

def sum_fuel_across_sectors(enduse_fuels):
def sum_fuel_across_sectors(fuels):
"""Sum fuel across sectors of an enduse if multiple sectors.
Otherwise return unchanged `enduse_fuels`
Otherwise return unchanged `fuels`
Arguments
---------
enduse_fuels : dict or np.array
fuels : dict or np.array
Fuels of an enduse either for sectors or already aggregated
Returns
-------
sum_array : np.array
Sum of fuels of all sectors
"""
if isinstance(enduse_fuels, dict):
sum_array = sum(enduse_fuels.values())
if isinstance(fuels, dict):
sum_array = sum(fuels.values())
return sum_array
else:
return enduse_fuels
return fuels

def get_share_s_tech_ey(
service_switches,
Expand Down
63 changes: 63 additions & 0 deletions tests/technologies/test_fuel_service_switch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,71 @@
"""
"""
import numpy as np
from energy_demand.technologies import fuel_service_switch
from energy_demand.read_write import read_data

def test_switches_to_dict():

service_switches = [
read_data.ServiceSwitch(
enduse='heating',
sector=None,
technology_install='techA',
service_share_ey=0.5,
switch_yr=2020),
read_data.ServiceSwitch(
enduse='heating',
sector=None,
technology_install='techB',
service_share_ey=0.5,
switch_yr=2020)]

out = fuel_service_switch.switches_to_dict(
service_switches=service_switches,
regional_specific=False)

assert out == {'techA': 0.5, 'techB': 0.5}

def test_get_switch_criteria():
"""testing
"""
crit_switch_happening = {'heating': ['sectorA']}

crit = fuel_service_switch.get_switch_criteria(
enduse='heating',
sector='sectorA',
crit_switch_happening=crit_switch_happening,
base_yr=2015,
curr_yr=2015)

assert crit == False

crit = fuel_service_switch.get_switch_criteria(
enduse='heating',
sector='sectorA',
crit_switch_happening=crit_switch_happening,
base_yr=2015,
curr_yr=2025)

assert crit == True

crit = fuel_service_switch.get_switch_criteria(
enduse='heating',
sector='sectorB',
crit_switch_happening=crit_switch_happening,
base_yr=2015,
curr_yr=2025)

assert crit == False

def test_sum_fuel_across_sectors():
"""
"""
fuels = {'sectorA': np.ones(10), 'sectorB': np.ones(10)}
sum = fuel_service_switch.sum_fuel_across_sectors(fuels)

assert np.sum(sum) == 20

def test_create_service_switch():
"""testing
"""
Expand Down

0 comments on commit 40fcba9

Please sign in to comment.