Skip to content

Commit b8c6bd6

Browse files
committed
code: unit tests for get_dea_vehicle_data and rename_pypsa_old
1 parent 26fcb38 commit b8c6bd6

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

test/test_compile_cost_assumptions.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
dea_sheet_names,
2525
geometric_series,
2626
get_data_from_DEA,
27+
get_dea_vehicle_data,
2728
get_excel_sheets,
2829
get_sheet_location,
30+
rename_pypsa_old,
2931
set_round_trip_efficiency,
3032
set_specify_assumptions,
3133
)
@@ -63,7 +65,6 @@ def test_clean_up_units(mock_input_data, mock_output_data, source):
6365
mock_input_data.copy(deep=True), value_column="value", source=source
6466
)
6567
comparison_df = output_df.compare(expected_df)
66-
print(comparison_df)
6768
assert comparison_df.empty
6869

6970

@@ -741,3 +742,44 @@ def test_add_carbon_capture(config):
741742
index=["2020", "source", "unit", "further description"],
742743
)
743744
)
745+
746+
747+
def test_get_dea_vehicle_data(config):
748+
"""
749+
The test verifies what is returned by get_dea_vehicle_data.
750+
"""
751+
df = get_dea_vehicle_data(
752+
snakemake_input_dictionary["dea_vehicles"], ["2020"], pd.DataFrame()
753+
)
754+
assert df.shape == (90, 5)
755+
assert sorted(list(df.columns)) == sorted(
756+
["2020", "unit", "source", "currency_year", "further description"]
757+
)
758+
759+
760+
def test_rename_pypsa_old():
761+
"""
762+
The test verifies what is returned by rename_pypsa_old.
763+
"""
764+
data = {
765+
("decentral water tank storage", "investment"): [46.8],
766+
("central CHP", "investment"): [3000],
767+
("hydrogen underground storage", "investment"): [2000],
768+
("retrofitting I", "investment"): [1000],
769+
("retrofitting II", "investment"): [1500],
770+
}
771+
index = pd.MultiIndex.from_tuples(data.keys())
772+
cost_dataframe_pypsa = pd.DataFrame(data.values(), index=index, columns=["value"])
773+
expected_data = {
774+
("decentral water tank storage", "investment"): [1.0],
775+
("central gas CHP", "investment"): [3000],
776+
("hydrogen storage underground", "investment"): [2000],
777+
}
778+
expected_index = pd.MultiIndex.from_tuples(expected_data.keys())
779+
expected_df = pd.DataFrame(
780+
expected_data.values(), index=expected_index, columns=["value"]
781+
)
782+
expected_df.loc[("decentral water tank storage", "investment"), "unit"] = "EUR/kWh"
783+
output_df = rename_pypsa_old(cost_dataframe_pypsa)
784+
comparison_df = output_df.compare(expected_df)
785+
assert comparison_df.empty

0 commit comments

Comments
 (0)