diff --git a/test/conftest.py b/test/conftest.py index d1ff9fa62..2427882dc 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -65,6 +65,25 @@ def converters_dataframe(): ) +@pytest.fixture(scope="function") +def links_dataframe(): + return pd.DataFrame( + { + "link_id": "link_5231_5232", + "bus0": 5231, + "bus1": 5232, + "voltage": 380.0, + "p_nom": 600.0, + "length": 1000.0, + "underground": "t", + "under_construction": "f", + "geometry": "'LINESTRING(6.8884 45.6783 ", + "": "6.8894 45.6793)'", + }, + index=[0], + ) + + @pytest.fixture(scope="function") def transformers_dataframe(): return pd.DataFrame( diff --git a/test/test_base_network.py b/test/test_base_network.py index 76e0f6790..8a783185b 100644 --- a/test/test_base_network.py +++ b/test/test_base_network.py @@ -25,6 +25,8 @@ _load_buses, _load_converters_from_eg, _load_converters_from_osm, + _load_links_from_eg, + _load_links_from_osm, _load_transformers, ) @@ -205,6 +207,78 @@ def test_load_converters_from_osm( assert df_converters_comparison.empty +def test_load_links_from_eg(tmpdir, buses_dataframe, config, links_dataframe): + """ + Verify what returned by _load_links_from_eg. + """ + df_links_reference = pd.DataFrame( + { + "link_id": "link_5231_5232", + "bus0": "5231", + "bus1": "5232", + "voltage": 380.0, + "p_nom": 600.0, + "length": 1.0, + "underground": True, + "under_construction": False, + "geometry": "LINESTRING(6.8884 45.6783 ,6.8894 45.6793)", + "carrier": "DC", + }, + index=[0], + ) + buses_path = pathlib.Path(tmpdir, "buses.csv") + buses_dataframe.to_csv(buses_path, index=False) + countries = config["countries"] + italy_shape = pathlib.Path(path_cwd, "test", "test_data", "italy_shape.geojson") + df_buses = _load_buses(buses_path, italy_shape, countries, config) + links_path = pathlib.Path(tmpdir, "links_exercise.csv") + links_dataframe.to_csv(links_path, index=False) + df_links_output = ( + _load_links_from_eg(df_buses, links_path) + .drop("Unnamed: 9", axis=1) + .reset_index() + ) + df_links_comparison = df_links_output.compare(df_links_reference) + pathlib.Path.unlink(links_path) + assert df_links_comparison.empty + + +def test_load_links_from_osm(tmpdir, buses_dataframe, config, links_dataframe): + """ + Verify what returned by _load_links_from_osm. + """ + df_links_reference = pd.DataFrame( + { + "link_id": "link_5231_5232", + "bus0": "5231", + "bus1": "5232", + "voltage": 380.0, + "p_nom": 600.0, + "length": 1.0, + "underground": True, + "under_construction": False, + "geometry": "LINESTRING(6.8884 45.6783 ,6.8894 45.6793)", + "carrier": "DC", + }, + index=[0], + ) + buses_path = pathlib.Path(tmpdir, "buses.csv") + buses_dataframe.to_csv(buses_path, index=False) + countries = config["countries"] + italy_shape = pathlib.Path(path_cwd, "test", "test_data", "italy_shape.geojson") + df_buses = _load_buses(buses_path, italy_shape, countries, config) + links_path = pathlib.Path(tmpdir, "links_exercise.csv") + links_dataframe.to_csv(links_path, index=False) + df_links_output = ( + _load_links_from_osm(df_buses, links_path) + .drop("Unnamed: 9", axis=1) + .reset_index() + ) + df_links_comparison = df_links_output.compare(df_links_reference) + pathlib.Path.unlink(links_path) + assert df_links_comparison.empty + + def test_load_transformers(tmpdir, buses_dataframe, config, transformers_dataframe): """ Verify what returned by _load_transformers.