Skip to content

Commit

Permalink
Unit test base network (#1438)
Browse files Browse the repository at this point in the history
* code: add unit tests for base_network.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* code: pre-commit checks

* code: add further unit tests base_network

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* code: new test

* code: add unit test for _load_buses and sketch the one for _load_converters_from_osm

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* code: pre-commit

* code: fix issue with test_load_buses

* code: unit test for _load_converters_from_osm

* data: add italy_shape.geojson

* code: unit test for _load_converters_from_eg and _load_transformers

* code: add unit test for _load_links_from_osm and _load_links_from_eg

* code: add unit test for _load_lines

* code: add unit test for _reconnect_crimea

* code: add unit test for _set_electrical_parameters_lines_eg

* code: add new unit tests

* code: fixing unlink usage

* code: config fixture - scope from function to session

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
finozzifa and pre-commit-ci[bot] authored Dec 12, 2024
1 parent c7c664d commit 212f9df
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/base_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
from packaging.version import Version, parse
from scipy.sparse import csgraph
from scipy.spatial import KDTree
from shapely.geometry import LineString, Point
from shapely.geometry import Point

PD_GE_2_2 = parse(pd.__version__) >= Version("2.2")

Expand Down
89 changes: 88 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pathlib

import pandas as pd
import pypsa
import pytest
import yaml
Expand All @@ -22,9 +23,95 @@ def ac_dc_network():
return pypsa.examples.ac_dc_meshed(from_master=True)


@pytest.fixture(scope="function")
@pytest.fixture(scope="session")
def config():
path_config = pathlib.Path(pathlib.Path.cwd(), "config", "config.default.yaml")
with open(path_config, "r") as file:
config_dict = yaml.safe_load(file)
return config_dict


@pytest.fixture(scope="function")
def buses_dataframe():
return pd.DataFrame(
{
"bus_id": [5231, 5232],
"voltage": [380.0, 380.0],
"dc": ["f", "f"],
"symbol": ["Substation", "Substation"],
"under_construction": ["f", "f"],
"x": [6.8884, 6.8894],
"y": [45.6783, 45.6793],
"country": ["IT", "IT"],
"geometry": ["POINT (6.8884 45.6783)", "POINT (6.8894 45.6793)"],
},
index=[5090, 5091],
)


@pytest.fixture(scope="function")
def converters_dataframe():
return pd.DataFrame(
{
"converter_id": "convert_5231_5232",
"bus0": 5231,
"bus1": 5232,
"voltage": 380.0,
"geometry": "'LINESTRING(6.8884 45.6783 ",
"": "6.8894 45.6793)'",
},
index=[0],
)


@pytest.fixture(scope="function")
def lines_dataframe():
return pd.DataFrame(
{
"line_id": "line_5231_5232",
"bus0": 5231,
"bus1": 5232,
"voltage": 380.0,
"circuits": 1.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 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(
{
"transformer_id": "transf_5231_5232",
"bus0": 5231,
"bus1": 5232,
"voltage": 380.0,
"geometry": "'LINESTRING(6.8884 45.6783 ",
"": "6.8894 45.6793)'",
},
index=[0],
)
Loading

0 comments on commit 212f9df

Please sign in to comment.