def test_get_all_assets_ranked(base_system, parameters): actual_ranking = get_all_assets_ranked(base_system, 'fttdp', 'insideout', 0) actual_ranking_ids = [e.id for e in actual_ranking] expected_ranking = ['A', 'B', 'C', 'D'] assert actual_ranking_ids == expected_ranking actual_ranking = get_all_assets_ranked(base_system, 'fttdp', 'rural', 0.5) actual_ranking_ids = [e.id for e in actual_ranking] expected_ranking = ['B', 'A'] assert actual_ranking_ids == expected_ranking actual_ranking = get_all_assets_ranked(base_system, 'fttdp', 'outsidein', 0) actual_ranking_ids = [e.id for e in actual_ranking] expected_ranking = ['D', 'C', 'B', 'A'] assert actual_ranking_ids == expected_ranking
def test_ranking_using_an_unknown(small_system_40): with pytest.raises(ValueError) as ex: get_all_assets_ranked(small_system_40._exchanges, 'unknown', 'exchange', 'fttp', False) msg = 'Did not recognise ranking preference variable' assert msg in str(ex)
def test_rollout_costs_calculation(small_system_40): actual_rollout_costs_exchange = get_all_assets_ranked(small_system_40._exchanges, 'rollout_costs', 'exchange', 'fttp', True) #True equals most expensive at the top # [{'id': 'exchange_EACAM', 'costs_assets_exchange_fttp': 50000, 'link_upgrade_costs': 0, 'total_cost': 50000}] # [{'id': 'exchange_EACOM', 'costs_assets_exchange_fttp': 50000, 'link_upgrade_costs': 0, 'total_cost': 50000}] actual_rollout_costs_exchange_values = [asset.rollout_costs['fttp'] for asset in actual_rollout_costs_exchange] expected_rollout_costs_exchange = [57811, 57474] assert actual_rollout_costs_exchange_values == expected_rollout_costs_exchange actual_rollout_costs_cabinet = get_all_assets_ranked(small_system_40._cabinets, 'rollout_costs', 'cabinet', 'fttp', True) #True equals most expensive at the top # [{'id': 'cabinet_{EACAM}{P100}', 'costs_assets_cabinet_fttp': 50, 'link_upgrade_costs': 1500.0, 'total_cost': 1550.0}] # [{'id': 'cabinet_{EACOM}{P200}', 'costs_assets_cabinet_fttp': 50, 'link_upgrade_costs': 2000.0, 'total_cost': 2050.0}] actual_rollout_costs_cabinet_values = [ asset.rollout_costs['fttp'] for asset in actual_rollout_costs_cabinet ] expected_rollout_costs_cabinet = [7811, 7474] assert actual_rollout_costs_cabinet_values == expected_rollout_costs_cabinet actual_rollout_costs_distribution = get_all_assets_ranked(small_system_40._distributions, 'rollout_costs', 'distribution', 'fttp', True) #True equals the least beneficial at the top # [{'id': 'distribution_{EACAM}{1}', 'costs_assets_premise_fttp_modem': 400, 'costs_assets_premise_fttp_optical_network_terminator': 200, 'planning_administration_cost': 200, 'costs_assets_premise_fttp_optical_connection_point': 37, 'link_upgrade_costs': 1000.0, 'total_cost': 1837.0}] # [{'id': 'distribution_{EACAM}{2}', 'costs_assets_premise_fttp_modem': 400, 'costs_assets_premise_fttp_optical_network_terminator': 200, 'planning_administration_cost': 200, 'costs_assets_premise_fttp_optical_connection_point': 37, 'link_upgrade_costs': 1250.0, 'total_cost': 2087.0}] # [{'id': 'distribution_{EACAM}{3}', 'costs_assets_premise_fttp_modem': 400, 'costs_assets_premise_fttp_optical_network_terminator': 200, 'planning_administration_cost': 200, 'costs_assets_premise_fttp_optical_connection_point': 37, 'link_upgrade_costs': 1500.0, 'total_cost': 2337.0}] # [{'id': 'distribution_{EACOM}{4}', 'costs_assets_premise_fttp_modem': 400, 'costs_assets_premise_fttp_optical_network_terminator': 200, 'planning_administration_cost': 200, 'costs_assets_premise_fttp_optical_connection_point': 37, 'link_upgrade_costs': 1750.0, 'total_cost': 2587.0}] # [{'id': 'distribution_{EACOM}{5}', 'costs_assets_premise_fttp_modem': 400, 'costs_assets_premise_fttp_optical_network_terminator': 200, 'planning_administration_cost': 200, 'costs_assets_premise_fttp_optical_connection_point': 37, 'link_upgrade_costs': 2000.0, 'total_cost': 2837.0}] actual_rollout_costs_distribution_values = [ asset.rollout_costs['fttp'] for asset in actual_rollout_costs_distribution ] expected_rollout_costs_distribution = [2837, 2587, 2337, 2087, 1837] assert expected_rollout_costs_distribution == actual_rollout_costs_distribution_values
def test_ranking_using_rollout_costs_at_cabinet_level(small_system_40): actual_ranking_by_cost = get_all_assets_ranked(small_system_40._cabinets, 'rollout_costs', 'cabinet', 'fttp', True) #True equals most expensive at the top actual_ranking_by_cost_ids = [asset.id for asset in actual_ranking_by_cost] expectation_ranking_by_cost = [ 'cabinet_{EACAM}{P100}', 'cabinet_{EACOM}{P200}', ] assert expectation_ranking_by_cost == actual_ranking_by_cost_ids
def test_ranking_using_rollout_costs_at_exchange_level(small_system_40): actual_ranking_by_cost = get_all_assets_ranked(small_system_40._exchanges, 'rollout_costs', 'exchange', 'fttp', True) #True equals most expensive at the top actual_ranking_by_cost_ids = [asset.id for asset in actual_ranking_by_cost] expectation_ranking_by_cost = [ 'exchange_EACAM', 'exchange_EACOM', ] assert expectation_ranking_by_cost == actual_ranking_by_cost_ids
def test_ranking_benefits_by_cabinet_reversed(small_system_40): actual_ranking_by_benefit = get_all_assets_ranked(small_system_40._cabinets, 'rollout_benefits', 'cabinet', 'fttp', True) actual_ranking_by_benefit_ids = [asset.id for asset in actual_ranking_by_benefit] expectation_ranking_by_benefit = [ 'cabinet_{EACAM}{P100}', 'cabinet_{EACOM}{P200}', ] assert expectation_ranking_by_benefit == actual_ranking_by_benefit_ids
def test_benefits_calculation_by_exchange(small_system_40): #two dists capable of ungrading totalling £49920 #benefit = wtp * months * payback_years * ((100-profit_margin)/100) #£26880 = 700 * 12 * 4 * (100-20)/100) #£23040 = 600 * 12 * 4 * (100-20)/100) actual_ranking_by_benefit = get_all_assets_ranked(small_system_40._exchanges, 'rollout_benefits', 'exchange', 'fttp', False) actual_benefits_calculation = [asset.rollout_benefits['fttp'] for asset in actual_ranking_by_benefit] expectation_benefits_calculation = [0, 49920.0] assert expectation_benefits_calculation == actual_benefits_calculation
def test_ranking_using_rollout_costs(small_system_40): actual_ranking_by_cost = get_all_assets_ranked(small_system_40._distributions, 'rollout_costs', 'distribution', 'fttp', True) actual_ranking_by_cost_ids = [asset.id for asset in actual_ranking_by_cost] expectation_ranking_by_cost = [ 'distribution_{EACOM}{5}', 'distribution_{EACOM}{4}', 'distribution_{EACAM}{3}', 'distribution_{EACAM}{2}', 'distribution_{EACAM}{1}', ] assert expectation_ranking_by_cost == actual_ranking_by_cost_ids
def test_ranking_benefits_by_exchange(small_system_40): #my_list = [600, 100, 200, 300] #print(sorted(my_list, reverse=False)) # [100, 200, 300, 600] actual_ranking_by_benefit = get_all_assets_ranked(small_system_40._exchanges, 'rollout_benefits', 'exchange', 'fttp', False) actual_ranking_by_benefit_ids = [asset.id for asset in actual_ranking_by_benefit] expectation_ranking_by_benefit = [ 'exchange_EACOM', 'exchange_EACAM', ] assert expectation_ranking_by_benefit == actual_ranking_by_benefit_ids