From fa043e1dc73c5e47930108ca128f7fa4d114abc7 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Thu, 17 Jan 2019 14:46:01 +0100 Subject: [PATCH 01/24] Creating Ding0 Tests in folder --- tests/__init__.py | 0 tests/config/__init__.py | 0 tests/core/__init__.py | 0 tests/core/test_core.py | 40 ++++++++++++++++++++++++++++++++++++ tests/core/test_network.py | 23 +++++++++++++++++++++ tests/core/test_powerflow.py | 0 tests/core/test_structure.py | 0 tests/data/__init__.py | 0 tests/flexopt/__init__.py | 0 tests/grid/__init__.py | 0 tests/tools/__init__.py | 0 11 files changed, 63 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/config/__init__.py create mode 100644 tests/core/__init__.py create mode 100644 tests/core/test_core.py create mode 100644 tests/core/test_network.py create mode 100644 tests/core/test_powerflow.py create mode 100644 tests/core/test_structure.py create mode 100644 tests/data/__init__.py create mode 100644 tests/flexopt/__init__.py create mode 100644 tests/grid/__init__.py create mode 100644 tests/tools/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/config/__init__.py b/tests/config/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/core/__init__.py b/tests/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/core/test_core.py b/tests/core/test_core.py new file mode 100644 index 00000000..7b60c668 --- /dev/null +++ b/tests/core/test_core.py @@ -0,0 +1,40 @@ +import pytest + +from egoio.tools import db +from sqlalchemy.orm import sessionmaker +import oedialect + +from ding0.core import NetworkDing0 + + +class TestNetworkDing0(object): + + @pytest.fixture + def emptyNetworkDing0(self): + """ + Returns an empty NetworkDing0 object for testing + """ + return NetworkDing0() + + @pytest.fixture + def oedb_session(self): + engine = db.connection(section='oedb') + session = sessionmaker(bind=engine)() + yield session + print("closing session") + session.close() + + def test_empty_mv_grid_districts(emptyNetworkDing0): + mv_grid_districts = list(emptyNetworkDing0.mv_grid_districts()) + empty_list = [] + assert mv_grid_districts == empty_list + + def test_import_mv_grid_districts(oedb_session): + with pytest.raises(TypeError): + NetworkDing0.import_mv_grid_districts( + oedb_session, + mv_grid_districts_no=['5'] + ) + + # def test_run_ding0(self): + # pass diff --git a/tests/core/test_network.py b/tests/core/test_network.py new file mode 100644 index 00000000..8e8ae583 --- /dev/null +++ b/tests/core/test_network.py @@ -0,0 +1,23 @@ +import pytest +from ding0.core.network import GridDing0, \ + GeneratorDing0, GeneratorFluctuatingDing0 + + +class TestGridDing0:(object): + + @pytest.fixture + def empty_gridding0(): + """ + Returns an empty GridDing0 object + """ + return GridDing0() + + def test_mv_grid_districts(self): + pass + + def test_run_ding0(self): + pass + + +if __name__ == "__main__": + pass diff --git a/tests/core/test_powerflow.py b/tests/core/test_powerflow.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/__init__.py b/tests/data/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/flexopt/__init__.py b/tests/flexopt/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/grid/__init__.py b/tests/grid/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/tools/__init__.py b/tests/tools/__init__.py new file mode 100644 index 00000000..e69de29b From b1d1ed1926c8185e935290ebdb769baa57e250ea Mon Sep 17 00:00:00 2001 From: boltbeard Date: Thu, 17 Jan 2019 18:51:46 +0100 Subject: [PATCH 02/24] Fixed syntax error in test_network.py --- tests/core/test_network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/test_network.py b/tests/core/test_network.py index 8e8ae583..21921524 100644 --- a/tests/core/test_network.py +++ b/tests/core/test_network.py @@ -3,10 +3,10 @@ GeneratorDing0, GeneratorFluctuatingDing0 -class TestGridDing0:(object): +class TestGridDing0(object): @pytest.fixture - def empty_gridding0(): + def empty_gridding0(self): """ Returns an empty GridDing0 object """ From b130a736f680228037a53c7b1d7b81c1d1af406f Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Fri, 18 Jan 2019 16:04:36 +0100 Subject: [PATCH 03/24] Fixed rookie error (forgot self in class func) --- tests/core/test_core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/core/test_core.py b/tests/core/test_core.py index 7b60c668..981cd7d6 100644 --- a/tests/core/test_core.py +++ b/tests/core/test_core.py @@ -18,18 +18,21 @@ def emptyNetworkDing0(self): @pytest.fixture def oedb_session(self): + """ + Returns an ego.io oedb session and closes it on finishing the test + """ engine = db.connection(section='oedb') session = sessionmaker(bind=engine)() yield session print("closing session") session.close() - def test_empty_mv_grid_districts(emptyNetworkDing0): + def test_empty_mv_grid_districts(self, emptyNetworkDing0): mv_grid_districts = list(emptyNetworkDing0.mv_grid_districts()) empty_list = [] assert mv_grid_districts == empty_list - def test_import_mv_grid_districts(oedb_session): + def test_import_mv_grid_districts(self, oedb_session): with pytest.raises(TypeError): NetworkDing0.import_mv_grid_districts( oedb_session, From ead1ce7ac1a87725f49bb1f1a232530b54811546 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 21 Jan 2019 15:09:51 +0100 Subject: [PATCH 04/24] Added more basic testing packages --- tests/core/network/__init__.py | 0 .../test_grids.py} | 0 tests/core/network/test_network.py | 132 ++++++++++++++++++ tests/core/network/test_stations.py | 23 +++ 4 files changed, 155 insertions(+) create mode 100644 tests/core/network/__init__.py rename tests/core/{test_network.py => network/test_grids.py} (100%) create mode 100644 tests/core/network/test_network.py create mode 100644 tests/core/network/test_stations.py diff --git a/tests/core/network/__init__.py b/tests/core/network/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/core/test_network.py b/tests/core/network/test_grids.py similarity index 100% rename from tests/core/test_network.py rename to tests/core/network/test_grids.py diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py new file mode 100644 index 00000000..fdb69bce --- /dev/null +++ b/tests/core/network/test_network.py @@ -0,0 +1,132 @@ +import pytest +from shapely.geometry import Point, LineString, LinearRing, Polygon +from ding0.core import NetworkDing0 +from ding0.core.network import (GridDing0, + StationDing0, TransformerDing0, + RingDing0, BranchDing0, + CableDistributorDing0, CircuitBreakerDing0, + GeneratorDing0, GeneratorFluctuatingDing0, + LoadDing0) +from ding0.core.structure.regions import LVLoadAreaCentreDing0 + + +class TestGridDing0(object): + + @pytest.fixture + def empty_grid(self): + """ + Returns and empty GridDing0 object + """ + return GridDing0() + + @pytest.fixture + def simple_grid(self): + """ + Returns a basic GridDing0 object + """ + network = NetworkDing0(name='TestNetwork', + run_id='test_run') + grid_district = Polygon(((0, 0), + (0, 1), + (1, 1), + (1, 0), + (0, 0))) + grid = GridDing0(network=network, + id_db=0, + grid_district=grid_district) + return grid +class TestStationDing0(object): + + @pytest.fixture + def empty_stationding0(self): + """ + Returns an empty StationDing0 object + """ + return StationDing0() + + @pytest.fixture + def test_empty_stationding0(self, empty_stationding0): + assert empty_stationding0.id_db is None + assert empty_stationding0.geo_data is None + assert empty_stationding0.grid is None + assert empty_stationding0.v_level_operation is None + assert list(empty_stationding0.transformers()) == [] + + +class TestRingDing0(object): + + @pytest.fixture + def empty_ringding0(self): + """ + Returns an empty RingDing0 object + """ + return RingDing0() + + @pytest.fixture + def simple_ringding0(self): + """ + Returns a simple RingDing0 object + """ + ringding0 = RingDing0(grid=grid, + id_db=0) + + +class TestLoadDing0(object): + + @pytest.fixture + def empty_loadding0(self): + """ + Returns an empty LoadDing0 object + """ + return LoadDing0(grid=GridDing0()) + + @pytest.fixture + def some_loadding0(self): + """ + Returns a networkless LoadDing0 object with some set parameters + """ + geo_data = Point(0, 0) + network = NetworkDing0(name='TestNetwork', + run_id='test_run') + + grid_district = Polygon([Point(0, 0), + Point(0, 1), + Point(1, 1), + Point(1, 0), + Point(0, 0)]) + grid = GridDing0(network=network, + id_db=0, + grid_district=grid_district) + load = LoadDing0(id_db=0, + geo_data=geo_data, + grid=grid, + peak_load=dict(residential=1.0, + retail=1.0, + industrial=1.0, + agricultural=1.0), + consumption=dict(residential=1.0, + retail=1.0, + industrial=1.0, + agricultural=1.0)) + + return load + + def test_empty_loadding0(self, empty_loadding0): + assert empty_loadding0.id_db is 1 + assert empty_loadding0.geo_data is None + # Once binary equality operators are implemented + # the following can be tested + # assert empty_loadding0.grid == GridDing0() + assert empty_loadding0.peak_load is None + assert empty_loadding0.consumption is None + + # def test_some_loadding0(self, some_loadding0): + # assert some_loadding0.id_db is None + # assert some_loadding0.geo_data is None + # assert some_loadding0.grid is None + # assert some_loadding0.peak_load is None + # assert some_loadding0.consumption is None + + +if __name__ == "__main__": + pass diff --git a/tests/core/network/test_stations.py b/tests/core/network/test_stations.py new file mode 100644 index 00000000..d5174877 --- /dev/null +++ b/tests/core/network/test_stations.py @@ -0,0 +1,23 @@ +import pytest +from ding0.core.network import GridDing0, \ + GeneratorDing0, GeneratorFluctuatingDing0 + + +class TestMVStationDing0(object): + + @pytest.fixture + def empty_gridding0(self): + """ + Returns an empty GridDing0 object + """ + return GridDing0() + + def test_mv_grid_districts(self): + pass + + def test_run_ding0(self): + pass + + +if __name__ == "__main__": + pass From 0afd854fec23e89ed4709103a9a4fc37c483dbf3 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 21 Jan 2019 15:10:57 +0100 Subject: [PATCH 05/24] Added test for Cable Distributors in GridDing0 --- tests/core/network/test_network.py | 105 +++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index fdb69bce..fe5f4cd2 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -35,6 +35,65 @@ def simple_grid(self): id_db=0, grid_district=grid_district) return grid + + # There is no setter function for providing a list + # of cable_distributors to the empty_grid + @pytest.fixture + def cable_distributor_grid(self): + """ + Returns a GridDing0 object with 2 CableDistributorDing0 + objects at Point(0, 0) and id_db=0, + and at Point(0, 1) and id_db=1 + """ + cable_distributor_grid = GridDing0() + geo_data1 = Point(0, 0) + cable_distributor1 = CableDistributorDing0(id_db=0, + geo_data=geo_data1, + grid=cable_distributor_grid) + geo_data2 = Point(0, 1) + cable_distributor2 = CableDistributorDing0(id_db=1, + geo_data=geo_data2, + grid=cable_distributor_grid) + cable_distributor_grid._cable_distributors = [cable_distributor1, + cable_distributor2] + return cable_distributor_grid + + def test_get_cable_distributors_list(self, cable_distributor_grid): + cable_distributor_list = list( + cable_distributor_grid.cable_distributors() + ) + assert len(cable_distributor_list) == 2 + assert cable_distributor_list[0].id_db == 0 + assert cable_distributor_list[0].geo_data == Point(0, 0) + assert cable_distributor_list[1].id_db == 1 + assert cable_distributor_list[1].geo_data == Point(0, 1) + + def test_cable_distributors_count(self, cable_distributor_grid): + assert cable_distributor_grid.cable_distributors_count() == 2 + + # There is no setter function for providing a list + # of loads to the empty_grid + @pytest.fixture + def load_grid(self): + """ + Returns a GridDing0 object with 2 LoadDing0 + objects at Point(0, 0) and id_db=0, and + another at Point(0, 1) and id_db=1, + Note: this function causes the id_db to be increased by 1. + Thus changing the id_db to 1 and 2 respectively + """ + load_grid = GridDing0() + geo_data1 = Point(0, 0) + load1 = LoadDing0(id_db=0, + geo_data=geo_data1, + grid=load_grid) + load_grid._loads = [load1] + geo_data2 = Point(0, 1) + load2 = LoadDing0(id_db=0, + geo_data=geo_data2, + grid=load_grid) + load_grid._loads.append(load2) + return load_grid class TestStationDing0(object): @pytest.fixture @@ -52,6 +111,52 @@ def test_empty_stationding0(self, empty_stationding0): assert empty_stationding0.v_level_operation is None assert list(empty_stationding0.transformers()) == [] + def test_add_transformer(self, empty_stationding0): + transformer1 = TransformerDing0(id_db=0, + v_level=4, + s_max_longterm=400.0, + s_max_shortterm=600.0, + s_max_emergency=800.0, + phase_angle=0.0, + tap_ratio=1.02, + r=0.02, + x=0.002) + transformer2 = TransformerDing0(id_db=1, + v_level=4, + s_max_longterm=600.0, + s_max_shortterm=900.0, + s_max_emergency=1100.0, + phase_angle=0.01, + tap_ratio=1.00, + r=0.01, + x=0.001) + empty_stationding0.add_transformer(transformer1) # added 1 + empty_stationding0.add_transformer(transformer2) # added 2 + transformer_list = list(empty_stationding0.transformers()) + assert len(transformer_list) == 2 + transformer1_in_empty_stationding0 = transformer_list[0] + assert transformer1_in_empty_stationding0 == transformer1 + assert transformer1_in_empty_stationding0.id_db == 0 + assert transformer1_in_empty_stationding0.v_level == 4 + assert transformer1_in_empty_stationding0.s_max_a == 400.0 + assert transformer1_in_empty_stationding0.s_max_b == 600.0 + assert transformer1_in_empty_stationding0.s_max_c == 800.0 + assert transformer1_in_empty_stationding0.phase_angle == 0.0 + assert transformer1_in_empty_stationding0.tap_ratio == 1.02 + assert transformer1_in_empty_stationding0.r == 0.02 + assert transformer1_in_empty_stationding0.x == 0.002 + transformer2_in_empty_stationding0 = transformer_list[1] + assert transformer2_in_empty_stationding0 == transformer2 + assert transformer2_in_empty_stationding0.id_db == 1 + assert transformer2_in_empty_stationding0.v_level == 4 + assert transformer2_in_empty_stationding0.s_max_a == 600.0 + assert transformer2_in_empty_stationding0.s_max_b == 900.0 + assert transformer2_in_empty_stationding0.s_max_c == 1100.0 + assert transformer2_in_empty_stationding0.phase_angle == 0.01 + assert transformer2_in_empty_stationding0.tap_ratio == 1.00 + assert transformer2_in_empty_stationding0.r == 0.01 + assert transformer2_in_empty_stationding0.x == 0.001 + class TestRingDing0(object): From 324f10a3535a43946c7f2621f5ca9b3f84af898b Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 21 Jan 2019 15:11:35 +0100 Subject: [PATCH 06/24] Added tests for loads in GridDing0 --- tests/core/network/test_network.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index fe5f4cd2..5a68c007 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -94,6 +94,18 @@ def load_grid(self): grid=load_grid) load_grid._loads.append(load2) return load_grid + + def test_loads_list(self, load_grid): + load_list = list(load_grid.loads()) + assert len(load_list) == 2 + assert load_list[0].id_db == 1 + assert load_list[0].geo_data == Point(0, 0) + assert load_list[1].id_db == 2 + assert load_list[1].geo_data == Point(0, 1) + + def test_loads_count(self, load_grid): + assert load_grid.loads_count() == 2 + class TestStationDing0(object): @pytest.fixture From cbca300e7a2911b14c1634c12d1e787320f7bbc3 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 21 Jan 2019 15:12:05 +0100 Subject: [PATCH 07/24] Added tests for adding generators in GridDing0 --- tests/core/network/test_network.py | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index 5a68c007..fd681b3c 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -106,6 +106,73 @@ def test_loads_list(self, load_grid): def test_loads_count(self, load_grid): assert load_grid.loads_count() == 2 + @pytest.fixture + def generator_grid(self): + """ + Returns a GridDing0 object with + 2 GeneratorDing0 objects + at Point(0, 0) and id_db=0 and + at Point(0, 1) and id_db=1, and + 2 GeneratorFluctuatingDing0 objects + at Point(1, 0), id_db=2, weather_cell_id=0 and + at Point(1, 1), id_db=3, weather_cell_id=1 + """ + generator_grid = GridDing0() + geo_data1 = Point(0, 0) + generator1 = GeneratorDing0(id_db=0, + geo_data=geo_data1) + geo_data2 = Point(0, 1) + generator2 = GeneratorDing0(id_db=1, + geo_data=geo_data2) + geo_data3 = Point(1, 0) + generator3 = GeneratorFluctuatingDing0(id_db=2, + weather_cell_id=0, + geo_data=geo_data3) + geo_data4 = Point(1, 1) + generator4 = GeneratorFluctuatingDing0(id_db=3, + weather_cell_id=1, + geo_data=geo_data4) + generator_grid._generators = [generator1, + generator2, + generator3, + generator4] + return generator_grid + + def test_add_generator(self, empty_grid): + geo_data1 = Point(0, 0) + generator1 = GeneratorDing0(id_db=0, + geo_data=geo_data1) + empty_grid.add_generator(generator1) + assert len(list(empty_grid.generators())) == 1 + geo_data2 = Point(0, 1) + generator2 = GeneratorDing0(id_db=1, + geo_data=geo_data2) + empty_grid.add_generator(generator2) + assert len(list(empty_grid.generators())) == 2 + geo_data3 = Point(1, 0) + generator3 = GeneratorFluctuatingDing0(id_db=2, + weather_cell_id=0, + geo_data=geo_data3) + empty_grid.add_generator(generator3) + assert len(list(empty_grid.generators())) == 3 + geo_data4 = Point(1, 1) + generator4 = GeneratorFluctuatingDing0(id_db=3, + weather_cell_id=1, + geo_data=geo_data4) + empty_grid.add_generator(generator4) + assert len(list(empty_grid.generators())) == 4 + generator_list = list(empty_grid.generators()) + assert generator_list[0].id_db == 0 + assert generator_list[0].geo_data == geo_data1 + assert generator_list[1].id_db == 1 + assert generator_list[1].geo_data == geo_data2 + assert generator_list[2].id_db == 2 + assert generator_list[2].weather_cell_id == 0 + assert generator_list[2].geo_data == geo_data3 + assert generator_list[3].id_db == 3 + assert generator_list[3].weather_cell_id == 1 + assert generator_list[3].geo_data == geo_data4 + class TestStationDing0(object): @pytest.fixture From 4d32521ee1d34ee0f129acb2a01c34ef69acf9e9 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 21 Jan 2019 15:12:39 +0100 Subject: [PATCH 08/24] Added positive test cases for graph_add_node in GridDing0 --- tests/core/network/test_network.py | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index fd681b3c..3b20519c 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -173,6 +173,67 @@ def test_add_generator(self, empty_grid): assert generator_list[3].weather_cell_id == 1 assert generator_list[3].geo_data == geo_data4 + # check for all positive cases of graph_add_node + def test_graph_add_node_station(self, empty_grid): + station1 = StationDing0() + empty_grid.graph_add_node(station1) + assert station1 in empty_grid._graph.nodes() + assert len(list(empty_grid._graph.nodes())) == 1 + + def test_graph_add_node_cable_distributor(self, empty_grid): + cable_distributor1 = CableDistributorDing0() + empty_grid.graph_add_node(cable_distributor1) + assert cable_distributor1 in empty_grid._graph.nodes() + assert len(list(empty_grid._graph.nodes())) == 1 + + def test_graph_add_node_lv_load_area_centre(self, empty_grid): + lv_load_area_centre1 = LVLoadAreaCentreDing0() + empty_grid.graph_add_node(lv_load_area_centre1) + assert lv_load_area_centre1 in empty_grid._graph.nodes() + assert len(list(empty_grid._graph.nodes())) == 1 + + def test_graph_add_node_circuit_breaker(self, empty_grid): + circuit_breaker1 = CircuitBreakerDing0(grid=empty_grid) + empty_grid.graph_add_node(circuit_breaker1) + assert circuit_breaker1 in empty_grid._graph.nodes() + assert len(list(empty_grid._graph.nodes())) == 1 + + def test_graph_add_node_generator(self, empty_grid): + # an add_node is called within add_generator + geo_data1 = Point(0, 0) + generator1 = GeneratorDing0(id_db=0, + geo_data=geo_data1) + empty_grid.graph_add_node(generator1) + assert generator1 in empty_grid._graph.nodes() + assert len(list(empty_grid._graph.nodes())) == 1 + + def test_graph_add_node_add_generator(self, empty_grid): + # an add_node is called within add_generator + geo_data1 = Point(0, 0) + generator1 = GeneratorDing0(id_db=0, + geo_data=geo_data1) + empty_grid.add_generator(generator1) + assert generator1 in empty_grid._graph.nodes() + # make sure that another call of add_nodes + # does nothing + len_nodes_before = len(list(empty_grid._graph.nodes())) + empty_grid.graph_add_node(generator1) + len_nodes_after = len(list(empty_grid._graph.nodes())) + assert len_nodes_before == len_nodes_after + + def test_graph_add_node_generator_fluctuating(self, empty_grid): + # an add_node is called within add_generator + geo_data1 = Point(0, 0) + generator1 = GeneratorFluctuatingDing0(id_db=0, + geo_data=geo_data1) + empty_grid.add_generator(generator1) + assert generator1 in empty_grid._graph.nodes() + # make sure that another call of add_nodes + # does nothing + len_nodes_before = len(list(empty_grid._graph.nodes())) + empty_grid.graph_add_node(generator1) + len_nodes_after = len(list(empty_grid._graph.nodes())) + assert len_nodes_before == len_nodes_after class TestStationDing0(object): @pytest.fixture From 6f91a0845dceda4862dc0b1b048b3d7a51c1e254 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 21 Jan 2019 15:13:11 +0100 Subject: [PATCH 09/24] Added negative test cases for graph_add_node in GridDing0 --- tests/core/network/test_network.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index 3b20519c..738caeb6 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -234,6 +234,36 @@ def test_graph_add_node_generator_fluctuating(self, empty_grid): empty_grid.graph_add_node(generator1) len_nodes_after = len(list(empty_grid._graph.nodes())) assert len_nodes_before == len_nodes_after + + # negative tests for graph_add_node + def test_graph_add_node_load(self, empty_grid): + load1 = LoadDing0(grid=empty_grid) + empty_grid._loads = [load1] + # make sure that call of add_nodes + # does nothing + len_nodes_before = len(list(empty_grid._graph.nodes())) + empty_grid.graph_add_node(load1) + len_nodes_after = len(list(empty_grid._graph.nodes())) + assert len_nodes_before == len_nodes_after + + def test_graph_add_node_branch(self, empty_grid): + branch1 = BranchDing0() + # make sure that call of add_nodes + # does nothing + len_nodes_before = len(list(empty_grid._graph.nodes())) + empty_grid.graph_add_node(branch1) + len_nodes_after = len(list(empty_grid._graph.nodes())) + assert len_nodes_before == len_nodes_after + + def test_graph_add_node_grid(self, empty_grid): + grid1 = GridDing0() + # make sure that call of add_nodes + # does nothing + len_nodes_before = len(list(empty_grid._graph.nodes())) + empty_grid.graph_add_node(grid1) + len_nodes_after = len(list(empty_grid._graph.nodes())) + assert len_nodes_before == len_nodes_after + class TestStationDing0(object): @pytest.fixture From e7936597549130ca20a78c7d30634c8bd767eb71 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Wed, 23 Jan 2019 19:54:50 +0100 Subject: [PATCH 10/24] Maximum testing coverage of test_network.py --- tests/core/network/test_network.py | 140 ++++++++++------------------- 1 file changed, 48 insertions(+), 92 deletions(-) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index 738caeb6..ee1a4dca 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -19,23 +19,6 @@ def empty_grid(self): """ return GridDing0() - @pytest.fixture - def simple_grid(self): - """ - Returns a basic GridDing0 object - """ - network = NetworkDing0(name='TestNetwork', - run_id='test_run') - grid_district = Polygon(((0, 0), - (0, 1), - (1, 1), - (1, 0), - (0, 0))) - grid = GridDing0(network=network, - id_db=0, - grid_district=grid_district) - return grid - # There is no setter function for providing a list # of cable_distributors to the empty_grid @pytest.fixture @@ -264,6 +247,54 @@ def test_graph_add_node_grid(self, empty_grid): len_nodes_after = len(list(empty_grid._graph.nodes())) assert len_nodes_before == len_nodes_after + @pytest.fixture + def simple_graph_grid(self): + grid = GridDing0(id_db=0) + station = StationDing0(id_db=0, geo_data=Point(0, 0)) + generator = GeneratorDing0(id_db=0, + geo_data=Point(0, 1), + mv_grid=grid) + grid.graph_add_node(station) + grid.add_generator(generator) + branch = BranchDing0(id_db=0, + length=2.0, + kind='cable') + grid._graph.add_edge(generator, station, branch=branch) + return (grid, station, generator, branch) + + def test_graph_nodes_from_branch(self, simple_graph_grid): + grid, station, generator, branch = simple_graph_grid + nodes_from_branch = grid.graph_nodes_from_branch(branch) + assert type(nodes_from_branch) == tuple + assert nodes_from_branch == (station, generator) + + def test_graph_branches_from_node(self, simple_graph_grid): + grid, station, generator, branch = simple_graph_grid + branches_from_node = grid.graph_branches_from_node(station) + assert branches_from_node == [(generator, dict(branch=branch))] + + def test_graph_edges(self, simple_graph_grid): + grid, station, generator, branch = simple_graph_grid + graph_edges = dict(grid.graph_edges()) + assert graph_edges == dict(adj_nodes=station, + branch=branch) + + def test_find_path(self, simple_graph_grid): + grid, station, generator, branch = simple_graph_grid + path = grid.find_path(generator, station) + assert path == [generator, station] + + def test_graph_path_length(self, simple_graph_grid): + grid, station, generator, branch = simple_graph_grid + path_length = grid.graph_path_length(generator, station) + assert path_length == 2.0 + + def test_graph_isolated_nodes(self, simple_graph_grid): + grid, station, generator, branch = simple_graph_grid + isolates = grid.graph_isolated_nodes() + assert isolates == [] + + class TestStationDing0(object): @pytest.fixture @@ -328,80 +359,5 @@ def test_add_transformer(self, empty_stationding0): assert transformer2_in_empty_stationding0.x == 0.001 -class TestRingDing0(object): - - @pytest.fixture - def empty_ringding0(self): - """ - Returns an empty RingDing0 object - """ - return RingDing0() - - @pytest.fixture - def simple_ringding0(self): - """ - Returns a simple RingDing0 object - """ - ringding0 = RingDing0(grid=grid, - id_db=0) - - -class TestLoadDing0(object): - - @pytest.fixture - def empty_loadding0(self): - """ - Returns an empty LoadDing0 object - """ - return LoadDing0(grid=GridDing0()) - - @pytest.fixture - def some_loadding0(self): - """ - Returns a networkless LoadDing0 object with some set parameters - """ - geo_data = Point(0, 0) - network = NetworkDing0(name='TestNetwork', - run_id='test_run') - - grid_district = Polygon([Point(0, 0), - Point(0, 1), - Point(1, 1), - Point(1, 0), - Point(0, 0)]) - grid = GridDing0(network=network, - id_db=0, - grid_district=grid_district) - load = LoadDing0(id_db=0, - geo_data=geo_data, - grid=grid, - peak_load=dict(residential=1.0, - retail=1.0, - industrial=1.0, - agricultural=1.0), - consumption=dict(residential=1.0, - retail=1.0, - industrial=1.0, - agricultural=1.0)) - - return load - - def test_empty_loadding0(self, empty_loadding0): - assert empty_loadding0.id_db is 1 - assert empty_loadding0.geo_data is None - # Once binary equality operators are implemented - # the following can be tested - # assert empty_loadding0.grid == GridDing0() - assert empty_loadding0.peak_load is None - assert empty_loadding0.consumption is None - - # def test_some_loadding0(self, some_loadding0): - # assert some_loadding0.id_db is None - # assert some_loadding0.geo_data is None - # assert some_loadding0.grid is None - # assert some_loadding0.peak_load is None - # assert some_loadding0.consumption is None - - if __name__ == "__main__": pass From 792e929e2cd1c364bae11cb40c13fc921b0ef058 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Thu, 24 Jan 2019 17:43:21 +0100 Subject: [PATCH 11/24] Fix for test_graph_edges from GridDing0 --- tests/core/network/test_network.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index ee1a4dca..028da477 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -275,9 +275,9 @@ def test_graph_branches_from_node(self, simple_graph_grid): def test_graph_edges(self, simple_graph_grid): grid, station, generator, branch = simple_graph_grid - graph_edges = dict(grid.graph_edges()) - assert graph_edges == dict(adj_nodes=station, - branch=branch) + graph_edges = list(grid.graph_edges()) + assert graph_edges[0] == dict(adj_nodes=(station, generator), + branch=branch) def test_find_path(self, simple_graph_grid): grid, station, generator, branch = simple_graph_grid From d9b8b2a36cf50c667ee52c636bc634e2ef453dd7 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Thu, 24 Jan 2019 19:29:25 +0100 Subject: [PATCH 12/24] Wrote a complete test outline for TestMVGridDing0 testing nx methods --- tests/core/network/test_grids.py | 217 +++++++++++++++++++++++++++++-- 1 file changed, 209 insertions(+), 8 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 21921524..0d947872 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -1,23 +1,224 @@ import pytest -from ding0.core.network import GridDing0, \ - GeneratorDing0, GeneratorFluctuatingDing0 +from shapely.geometry import Point, LineString, LinearRing, Polygon +from ding0.core import NetworkDing0 +from ding0.core.network import (RingDing0, BranchDing0, CircuitBreakerDing0, + GeneratorDing0, GeneratorFluctuatingDing0) +from ding0.core.network.stations import MVStationDing0, LVStationDing0 +from ding0.core.network.grids import MVGridDing0, LVGridDing0 -class TestGridDing0(object): +class TestMVGridDing0(object): @pytest.fixture - def empty_gridding0(self): + def empty_mvgridding0(self): """ - Returns an empty GridDing0 object + Returns an empty MVGridDing0 object """ - return GridDing0() + station = MVStationDing0(id_db=0, geo_data=Point(0.5, 0.5)) + grid = MVGridDing0(id_db=0, + station=station) + return grid - def test_mv_grid_districts(self): + def test_empty_mvgridding0(self, empty_mvgridding0): + assert empty_mvgridding0._rings == [] + assert empty_mvgridding0._circuit_breakers == [] + assert empty_mvgridding0.default_branch_kind is None + assert empty_mvgridding0.default_branch_type is None + assert empty_mvgridding0.default_branch_kind_settle is None + assert empty_mvgridding0.default_branch_type_settle is None + assert empty_mvgridding0.default_branch_kind_aggregated is None + assert empty_mvgridding0.default_branch_type_aggregated is None + assert empty_mvgridding0._station.id_db == 0 + assert empty_mvgridding0._station.geo_data == Point(0.5, 0.5) + + def test_add_circuit_breakers(self, empty_mvgridding0): + circuit_breaker = CircuitBreakerDing0(id_db=0, + geo_data=Point(0, 0), + grid=empty_mvgridding0) + empty_mvgridding0.add_circuit_breaker(circuit_breaker) + circuit_breakers_in_grid = list(empty_mvgridding0.circuit_breakers()) + assert len(circuit_breakers_in_grid) == 1 + assert circuit_breakers_in_grid[0] == circuit_breaker + + def test_add_circuit_breakers_negative(self, empty_mvgridding0): + bad_object = GeneratorDing0(id_db=0) + empty_mvgridding0.add_circuit_breaker(bad_object) + circuit_breakers_in_grid = list(empty_mvgridding0.circuit_breakers()) + assert len(circuit_breakers_in_grid) == 0 + + @pytest.fixture + def circuit_breaker_mvgridding0(self): + """ + Returns an MVGridDing0 object with a branch and a + circuit breaker + """ + station = MVStationDing0(id_db=0, geo_data=Point(0.5, 0.5)) + grid = MVGridDing0(id_db=0, + station=station) + branch = BranchDing0(id_db=0, length=2.0, kind='cable') + circuit_breaker = CircuitBreakerDing0(id_db=0, + geo_data=Point(0, 0), + branch=branch, + grid=grid) + grid.add_circuit_breaker(circuit_breaker) + grid._graph.add_edge(circuit_breaker, station, + branch=branch) + return grid + + def test_open_circuit_breakers(self, circuit_breaker_mvgridding0): + circuit_breakers_in_grid = list( + circuit_breaker_mvgridding0.circuit_breakers() + ) + assert circuit_breakers_in_grid[0].status == 'closed' + circuit_breaker_mvgridding0.open_circuit_breakers() + assert circuit_breakers_in_grid[0].status == 'open' + + def test_close_circuit_breakers(self, circuit_breaker_mvgridding0): + circuit_breakers_in_grid = list( + circuit_breaker_mvgridding0.circuit_breakers() + ) + assert circuit_breakers_in_grid[0].status == 'closed' + circuit_breaker_mvgridding0.open_circuit_breakers() + assert circuit_breakers_in_grid[0].status == 'open' + circuit_breaker_mvgridding0.close_circuit_breakers() + assert circuit_breakers_in_grid[0].status == 'closed' + + @pytest.fixture + def ring_mvgridding0(self): + """ + Returns an MVGridDing0 object with 2 branches + a circuitbreaker and a ring + """ + station = MVStationDing0(id_db=0, geo_data=Point(1, 1)) + grid = MVGridDing0(id_db=0, + station=station) + generator1 = GeneratorDing0(id_db=0, + geo_data=Point(1, 2), + mv_grid=grid) + grid.add_generator(generator1) + generator2 = GeneratorDing0(id_db=1, + geo_data=Point(2, 1), + mv_grid=grid) + grid.add_generator(generator2) + generator3 = GeneratorDing0(id_db=2, + geo_data=Point(2, 2), + mv_grid=grid) + grid.add_generator(generator3) + ring = RingDing0(grid=grid) + branch1 = BranchDing0(id_db='0', length=2.0, kind='cable', ring=ring) + branch1a = BranchDing0(id_db='0a', lenght=1.2, kind='cable', ring=ring) + branch2 = BranchDing0(id_db='1', lenght=3.0, kind='line', ring=ring) + branch2a = BranchDing0(id_db='1a', lenght=2.0, kind='line', ring=ring) + branch3 = BranchDing0(id_db='2', length=2.5, kind='line') + circuit_breaker1 = CircuitBreakerDing0(id_db=0, + geo_data=Point(0, 0), + branch=branch1, + grid=grid) + grid.add_circuit_breaker(circuit_breaker1) + grid._graph.add_edge(generator1, station, + branch=branch1) + grid._graph.add_edge(circuit_breaker1, generator1, + branch=branch1a) + grid._graph.add_edge(generator2, station, + branch=branch2) + grid._graph.add_edge(circuit_breaker1, generator2, + branch=branch2a) + grid._graph.add_edge(generator3, generator2, branch=branch3) + grid.add_ring(ring) + return (ring, grid) + + def test_add_ring(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + assert len(grid._rings) == 1 + assert grid._rings[0] == ring + + def test_rings_count(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + assert grid.rings_count() == 1 + assert grid._rings[0] == ring + + def test_get_ring_from_node(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + station = grid.station() + assert grid.get_ring_from_node(station) == ring + + def test_rings_nodes_root_only_include_root(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + station = grid.station() + generators = list(grid.generators()) + circuit_breakers = list(grid.circuit_breakers()) + rings_nodes_expected = [generators[0], + circuit_breakers[0], + generators[1], + station] + rings_nodes = list(grid.rings_nodes(include_root_node=True))[0] + assert rings_nodes == rings_nodes_expected + + def test_rings_nodes_root_only_exclude_root(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + generators = list(grid.generators()) + circuit_breakers = list(grid.circuit_breakers()) + rings_nodes_expected = [generators[0], + circuit_breakers[0], + generators[1]] + rings_nodes = list(grid.rings_nodes(include_root_node=False))[0] + assert rings_nodes == rings_nodes_expected + + def test_rings_nodes_include_satellites_include_root(self, + ring_mvgridding0): + ring, grid = ring_mvgridding0 + station = grid.station() + generators = list(grid.generators()) + circuit_breakers = list(grid.circuit_breakers()) + rings_nodes_expected = [generators[0], + circuit_breakers[0], + generators[1], + station, + generators[2]] + rings_nodes = list(grid.rings_nodes(include_root_node=True, + include_satellites=True))[0] + assert rings_nodes == rings_nodes_expected + + def test_rings_nodes_include_satellites_exclude_root(self, + ring_mvgridding0): + ring, grid = ring_mvgridding0 + generators = list(grid.generators()) + circuit_breakers = list(grid.circuit_breakers()) + rings_nodes_expected = [generators[0], + circuit_breakers[0], + generators[1], + generators[2]] + rings_nodes = list(grid.rings_nodes(include_root_node=False, + include_satellites=True))[0] + assert rings_nodes == rings_nodes_expected + + def test_rings_full_data(self, ring_mvgridding0): + pass + + def test_graph_nodes_from_subtree(self, ring_mvgridding0): + pass + + def test_set_branch_ids(self, ring_mvgridding0): pass - def test_run_ding0(self): + def test_routing(self, ring_mvgridding0): pass + def test_connect_generators(self, ring_mvgridding0): + pass + + +class TestLVGridDing0(object): + + @pytest.fixture + def empty_lvgridding0(self): + """ + Returns and empty LVGridDing0 object + """ + lv_station = LVStationDing0(id_db=0, geo_data=Point(1, 1)) + grid = LVGridDing0(id_db=0, station=lv_station) + return grid + if __name__ == "__main__": pass From 2f82a74a954aba7ab9fed6fde9d55a3db60ac76e Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Fri, 25 Jan 2019 11:58:18 +0100 Subject: [PATCH 13/24] Added test for getting full data of ring --- tests/core/network/test_grids.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 0d947872..145e4ab4 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -193,7 +193,29 @@ def test_rings_nodes_include_satellites_exclude_root(self, assert rings_nodes == rings_nodes_expected def test_rings_full_data(self, ring_mvgridding0): - pass + ring, grid = ring_mvgridding0 + station = grid.station() + generators = list(grid.generators()) + circuit_breakers = list(grid.circuit_breakers()) + branches = sorted(list(map(lambda x: x['branch'], + grid.graph_edges())), + key=lambda x: repr(x)) + ring_expected = ring + # branches following the ring + branches_expected = [branches[1], + branches[0], + branches[3], + branches[2]] + rings_nodes_expected = [generators[0], + circuit_breakers[0], + generators[1], + station] + (ring_out, + branches_out, + rings_nodes_out) = list(grid.rings_full_data())[0] + assert ring_out == ring_expected + assert branches_out == branches_expected + assert rings_nodes_out == rings_nodes_expected def test_graph_nodes_from_subtree(self, ring_mvgridding0): pass From c7ef89ac7e2828b795fb016c654b995d93b0b8b1 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Fri, 25 Jan 2019 12:25:46 +0100 Subject: [PATCH 14/24] Added tests for getting nodes from subtree --- tests/core/network/test_grids.py | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 145e4ab4..d078f9b0 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -217,8 +217,40 @@ def test_rings_full_data(self, ring_mvgridding0): assert branches_out == branches_expected assert rings_nodes_out == rings_nodes_expected - def test_graph_nodes_from_subtree(self, ring_mvgridding0): - pass + def test_graph_nodes_from_subtree_station(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + station = grid.station() + nodes_out = grid.graph_nodes_from_subtree(station) + nodes_expected = [] + assert nodes_out == nodes_expected + + def test_graph_nodes_from_subtree_circuit_breaker(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + circuit_breakers = list(grid.circuit_breakers()) + nodes_out = grid.graph_nodes_from_subtree(circuit_breakers[0]) + nodes_expected = [] + assert nodes_out == nodes_expected + + def test_graph_nodes_from_subtree_ring_branch_left(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + generators = list(grid.generators()) + nodes_out = grid.graph_nodes_from_subtree(generators[0]) + nodes_expected = [] + assert nodes_out == nodes_expected + + def test_graph_nodes_from_subtree_ring_branch_right(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + generators = list(grid.generators()) + nodes_out = grid.graph_nodes_from_subtree(generators[1]) + nodes_expected = [generators[2]] + assert nodes_out == nodes_expected + + def test_graph_nodes_from_subtree_off_ring(self, ring_mvgridding0): + ring, grid = ring_mvgridding0 + generators = list(grid.generators()) + nodes_out = grid.graph_nodes_from_subtree(generators[2]) + nodes_expected = [] + assert nodes_out == nodes_expected def test_set_branch_ids(self, ring_mvgridding0): pass From 582d08ee3b5da121bbfffc6ffd4f54dea6c9cd6b Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Sun, 27 Jan 2019 22:16:47 +0100 Subject: [PATCH 15/24] Added test for mv_routing --- tests/core/network/test_grids.py | 83 +++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index d078f9b0..5b1aacd4 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -1,4 +1,12 @@ import pytest + +from egoio.tools import db +from sqlalchemy.orm import sessionmaker +import oedialect + +import networkx as nx +import pandas as pd + from shapely.geometry import Point, LineString, LinearRing, Polygon from ding0.core import NetworkDing0 from ding0.core.network import (RingDing0, BranchDing0, CircuitBreakerDing0, @@ -252,14 +260,77 @@ def test_graph_nodes_from_subtree_off_ring(self, ring_mvgridding0): nodes_expected = [] assert nodes_out == nodes_expected - def test_set_branch_ids(self, ring_mvgridding0): - pass + @pytest.fixture + def oedb_session(self): + """ + Returns an ego.io oedb session and closes it on finishing the test + """ + engine = db.connection(section='oedb') + session = sessionmaker(bind=engine)() + yield session + print("closing session") + session.close() + + def test_routing(self, oedb_session): + # instantiate new ding0 network object + nd = NetworkDing0(name='network') + + nd.import_mv_grid_districts(oedb_session, + mv_grid_districts_no=[460]) + # STEP 2: Import generators + nd.import_generators(oedb_session) + # STEP 3: Parametrize MV grid + nd.mv_parametrize_grid() + # STEP 4: Validate MV Grid Districts + nd.validate_grid_districts() + # STEP 5: Build LV grids + nd.build_lv_grids() + + graph = nd._mv_grid_districts[0].mv_grid._graph + + assert len(graph.nodes()) == 256 + assert len(graph.edges()) == 0 + assert len(nx.isolates(graph)) == 256 + assert pd.Series(graph.degree()).sum(axis=0) == 0 + assert pd.Series(graph.degree()).mean(axis=0) == 0.0 + assert len(nx.get_edge_attributes(graph, 'branch')) == 0 + assert nx.average_node_connectivity(graph) == 0.0 + assert pd.Series( + nx.degree_centrality(graph) + ).mean(axis=0) == 0.0 + assert pd.Series( + nx.closeness_centrality(graph) + ).mean(axis=0) == 0.0 + assert pd.Series( + nx.betweenness_centrality(graph) + ).mean(axis=0) == 0.0 - def test_routing(self, ring_mvgridding0): - pass + nd.mv_routing() - def test_connect_generators(self, ring_mvgridding0): - pass + assert len(graph.nodes()) == 269 + assert len(graph.edges()) == 218 + assert len(nx.isolates(graph)) == 54 + assert pd.Series(graph.degree()).sum(axis=0) == 436 + assert pd.Series( + graph.degree() + ).mean(axis=0) == pytest.approx(1.62, 0.001) + assert len(nx.get_edge_attributes(graph, 'branch')) == 218 + assert nx.average_node_connectivity(graph) == pytest.approx( + 0.688, + abs=0.0001 + ) + assert pd.Series( + nx.degree_centrality(graph) + ).mean(axis=0) == pytest.approx(0.006, abs=0.001) + assert pd.Series( + nx.closeness_centrality(graph) + ).mean(axis=0) == pytest.approx(0.042474, abs=0.00001) + assert pd.Series( + nx.betweenness_centrality(graph) + ).mean(axis=0) == pytest.approx(0.0354629, abs=0.00001) + assert pd.Series( + nx.edge_betweenness_centrality(graph) + ).mean(axis=0) == pytest.approx(0.04636150, abs=0.00001) class TestLVGridDing0(object): From 57b2e55a6604102c35371cc04a5874c88225c1f0 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Sun, 27 Jan 2019 22:24:56 +0100 Subject: [PATCH 16/24] Modifications to allow proper functioning of pyproj4 - This can be removed later --- ding0/examples/example_single_grid_district.py | 15 +++++++++++++++ tests/core/network/test_grids.py | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ding0/examples/example_single_grid_district.py b/ding0/examples/example_single_grid_district.py index f7f13ea2..199097d3 100644 --- a/ding0/examples/example_single_grid_district.py +++ b/ding0/examples/example_single_grid_district.py @@ -27,6 +27,21 @@ from sqlalchemy.orm import sessionmaker import oedialect +# this is a workaround for geting pyproj to work +import os +import platform + +if platform.system() == 'Windows': + os.environ["PROJ_LIB"] = os.path.join('C:', os.sep, 'ProgramData', + 'Miniconda3', 'envs', + 'openbea_calculations', 'Library', + 'share') # windows +elif platform.system() == 'Linux': + os.environ["PROJ_LIB"] = os.path.join(os.sep, 'opt', 'Miniconda3', 'envs', + 'openbea_calculations', 'Library', + 'share') # linux +else: + print("Unknown platform, No PROJ_LIB environment variable set.") # define logger logger = setup_logger() diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 5b1aacd4..165edccb 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -14,6 +14,21 @@ from ding0.core.network.stations import MVStationDing0, LVStationDing0 from ding0.core.network.grids import MVGridDing0, LVGridDing0 +import os +import platform + +if platform.system() == 'Windows': + os.environ["PROJ_LIB"] = os.path.join('C:', os.sep, 'ProgramData', + 'Miniconda3', 'envs', + 'openbea_calculations', 'Library', + 'share') # windows +elif platform.system() == 'Linux': + os.environ["PROJ_LIB"] = os.path.join(os.sep, 'opt', 'Miniconda3', 'envs', + 'openbea_calculations', 'Library', + 'share') # linux +else: + print("Unknown platform, No PROJ_LIB environment variable set.") + class TestMVGridDing0(object): From e0330927f176665c0dbad63d38fb0dd5ed765af3 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Sun, 27 Jan 2019 23:16:56 +0100 Subject: [PATCH 17/24] Removed pyproj workaround --- ding0/examples/example_single_grid_district.py | 16 +--------------- tests/core/network/test_grids.py | 15 --------------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/ding0/examples/example_single_grid_district.py b/ding0/examples/example_single_grid_district.py index 199097d3..3d27aef9 100644 --- a/ding0/examples/example_single_grid_district.py +++ b/ding0/examples/example_single_grid_district.py @@ -27,21 +27,7 @@ from sqlalchemy.orm import sessionmaker import oedialect -# this is a workaround for geting pyproj to work -import os -import platform - -if platform.system() == 'Windows': - os.environ["PROJ_LIB"] = os.path.join('C:', os.sep, 'ProgramData', - 'Miniconda3', 'envs', - 'openbea_calculations', 'Library', - 'share') # windows -elif platform.system() == 'Linux': - os.environ["PROJ_LIB"] = os.path.join(os.sep, 'opt', 'Miniconda3', 'envs', - 'openbea_calculations', 'Library', - 'share') # linux -else: - print("Unknown platform, No PROJ_LIB environment variable set.") + # define logger logger = setup_logger() diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 165edccb..5b1aacd4 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -14,21 +14,6 @@ from ding0.core.network.stations import MVStationDing0, LVStationDing0 from ding0.core.network.grids import MVGridDing0, LVGridDing0 -import os -import platform - -if platform.system() == 'Windows': - os.environ["PROJ_LIB"] = os.path.join('C:', os.sep, 'ProgramData', - 'Miniconda3', 'envs', - 'openbea_calculations', 'Library', - 'share') # windows -elif platform.system() == 'Linux': - os.environ["PROJ_LIB"] = os.path.join(os.sep, 'opt', 'Miniconda3', 'envs', - 'openbea_calculations', 'Library', - 'share') # linux -else: - print("Unknown platform, No PROJ_LIB environment variable set.") - class TestMVGridDing0(object): From 9b60a92617c52943de529821a088992bd28a6e3d Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 28 Jan 2019 10:05:53 +0100 Subject: [PATCH 18/24] Fixed list casting of iterators in networkx based tests --- tests/core/network/test_grids.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 5b1aacd4..3ab08531 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -288,12 +288,12 @@ def test_routing(self, oedb_session): graph = nd._mv_grid_districts[0].mv_grid._graph - assert len(graph.nodes()) == 256 - assert len(graph.edges()) == 0 - assert len(nx.isolates(graph)) == 256 + assert len(list(graph.nodes())) == 256 + assert len(list(graph.edges())) == 0 + assert len(list(nx.isolates(graph))) == 256 assert pd.Series(graph.degree()).sum(axis=0) == 0 assert pd.Series(graph.degree()).mean(axis=0) == 0.0 - assert len(nx.get_edge_attributes(graph, 'branch')) == 0 + assert len(list(nx.get_edge_attributes(graph, 'branch'))) == 0 assert nx.average_node_connectivity(graph) == 0.0 assert pd.Series( nx.degree_centrality(graph) @@ -307,14 +307,14 @@ def test_routing(self, oedb_session): nd.mv_routing() - assert len(graph.nodes()) == 269 - assert len(graph.edges()) == 218 - assert len(nx.isolates(graph)) == 54 + assert len(list(graph.nodes())) == 269 + assert len(list(graph.edges())) == 218 + assert len(list(nx.isolates(graph))) == 54 assert pd.Series(graph.degree()).sum(axis=0) == 436 assert pd.Series( graph.degree() ).mean(axis=0) == pytest.approx(1.62, 0.001) - assert len(nx.get_edge_attributes(graph, 'branch')) == 218 + assert len(list(nx.get_edge_attributes(graph, 'branch'))) == 218 assert nx.average_node_connectivity(graph) == pytest.approx( 0.688, abs=0.0001 From c0df3cff2f5d0f4ce5eab6cfdab4ea14de0d8a26 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 28 Jan 2019 10:56:38 +0100 Subject: [PATCH 19/24] Fixed dict casting of networkx based tests --- tests/core/network/test_grids.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 3ab08531..7f0818f8 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -291,8 +291,8 @@ def test_routing(self, oedb_session): assert len(list(graph.nodes())) == 256 assert len(list(graph.edges())) == 0 assert len(list(nx.isolates(graph))) == 256 - assert pd.Series(graph.degree()).sum(axis=0) == 0 - assert pd.Series(graph.degree()).mean(axis=0) == 0.0 + assert pd.Series(dict(graph.degree())).sum(axis=0) == 0 + assert pd.Series(dict(graph.degree())).mean(axis=0) == 0.0 assert len(list(nx.get_edge_attributes(graph, 'branch'))) == 0 assert nx.average_node_connectivity(graph) == 0.0 assert pd.Series( @@ -310,9 +310,9 @@ def test_routing(self, oedb_session): assert len(list(graph.nodes())) == 269 assert len(list(graph.edges())) == 218 assert len(list(nx.isolates(graph))) == 54 - assert pd.Series(graph.degree()).sum(axis=0) == 436 + assert pd.Series(dict(graph.degree())).sum(axis=0) == 436 assert pd.Series( - graph.degree() + dict(graph.degree()) ).mean(axis=0) == pytest.approx(1.62, 0.001) assert len(list(nx.get_edge_attributes(graph, 'branch'))) == 218 assert nx.average_node_connectivity(graph) == pytest.approx( From f04cbe9ed1772d5f2d1f9ef4ef9229a3dc8ec7a7 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Mon, 25 Feb 2019 15:56:17 +0100 Subject: [PATCH 20/24] Added some basic documentation to test_grids.py --- tests/core/network/test_grids.py | 107 ++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 7f0818f8..492b209c 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -20,7 +20,9 @@ class TestMVGridDing0(object): @pytest.fixture def empty_mvgridding0(self): """ - Returns an empty MVGridDing0 object + Returns an empty MVGridDing0 object with an MVStationDing0 object + with id_db = 0 and + with geo_data = shapely.geometry.Point(0.5, 0.5) """ station = MVStationDing0(id_db=0, geo_data=Point(0.5, 0.5)) grid = MVGridDing0(id_db=0, @@ -28,6 +30,13 @@ def empty_mvgridding0(self): return grid def test_empty_mvgridding0(self, empty_mvgridding0): + """ + Ccheck that initialization of an object of the + class MVGridDing0 results in the right attributes being empty + lists or NoneType objects, with the exception of the + MVStationDing0 object's id_db and geo_data, which are + 0 and shapely.geometry.Point(0.5, 0.5) respectively. + """ assert empty_mvgridding0._rings == [] assert empty_mvgridding0._circuit_breakers == [] assert empty_mvgridding0.default_branch_kind is None @@ -40,6 +49,10 @@ def test_empty_mvgridding0(self, empty_mvgridding0): assert empty_mvgridding0._station.geo_data == Point(0.5, 0.5) def test_add_circuit_breakers(self, empty_mvgridding0): + """ + Adding a circuit breaker into an empty_mvgridding0 and check if it + works + """ circuit_breaker = CircuitBreakerDing0(id_db=0, geo_data=Point(0, 0), grid=empty_mvgridding0) @@ -49,6 +62,10 @@ def test_add_circuit_breakers(self, empty_mvgridding0): assert circuit_breakers_in_grid[0] == circuit_breaker def test_add_circuit_breakers_negative(self, empty_mvgridding0): + """ + Adding a GeneratorDing0 as a circuit_breaker through the + add_circuit_breaker just to see if the function rejects it. + """ bad_object = GeneratorDing0(id_db=0) empty_mvgridding0.add_circuit_breaker(bad_object) circuit_breakers_in_grid = list(empty_mvgridding0.circuit_breakers()) @@ -74,6 +91,10 @@ def circuit_breaker_mvgridding0(self): return grid def test_open_circuit_breakers(self, circuit_breaker_mvgridding0): + """ + Checks that using open_circuit_breakers function used from + the MVGridDing0 object actually opens all the circuit breakers. + """ circuit_breakers_in_grid = list( circuit_breaker_mvgridding0.circuit_breakers() ) @@ -82,6 +103,10 @@ def test_open_circuit_breakers(self, circuit_breaker_mvgridding0): assert circuit_breakers_in_grid[0].status == 'open' def test_close_circuit_breakers(self, circuit_breaker_mvgridding0): + """ + Checks that using close_circuit_breakers function used from + the MVGridDing0 object actually closes all the circuit breakers. + """ circuit_breakers_in_grid = list( circuit_breaker_mvgridding0.circuit_breakers() ) @@ -136,21 +161,39 @@ def ring_mvgridding0(self): return (ring, grid) def test_add_ring(self, ring_mvgridding0): + """ + Check if the number of rings are increased and the correct ring + is added by using the add_ring function inside of MVGriDing0 + """ ring, grid = ring_mvgridding0 assert len(grid._rings) == 1 assert grid._rings[0] == ring def test_rings_count(self, ring_mvgridding0): + """ + Check if the number of rings are correctly reflected using the + rings_count function in MVGridDing0 and the correct ring + is added by using the add_ring function inside of MVGriDing0 + """ ring, grid = ring_mvgridding0 assert grid.rings_count() == 1 assert grid._rings[0] == ring def test_get_ring_from_node(self, ring_mvgridding0): + """ + Checks that the ring obtained from the get_ring_from_node object + works as expected returning the correct ring. + """ ring, grid = ring_mvgridding0 station = grid.station() assert grid.get_ring_from_node(station) == ring def test_rings_nodes_root_only_include_root(self, ring_mvgridding0): + """ + Checks that the ring obtained from the rings_nodes function + setting the include_root_node parameter to "True" + contains the list of nodes that are expected. + """ ring, grid = ring_mvgridding0 station = grid.station() generators = list(grid.generators()) @@ -163,6 +206,11 @@ def test_rings_nodes_root_only_include_root(self, ring_mvgridding0): assert rings_nodes == rings_nodes_expected def test_rings_nodes_root_only_exclude_root(self, ring_mvgridding0): + """ + Checks that the ring obtained from the rings_nodes function + setting the include_root_node parameter to "False" + contains the list of nodes that are expected. + """ ring, grid = ring_mvgridding0 generators = list(grid.generators()) circuit_breakers = list(grid.circuit_breakers()) @@ -174,6 +222,12 @@ def test_rings_nodes_root_only_exclude_root(self, ring_mvgridding0): def test_rings_nodes_include_satellites_include_root(self, ring_mvgridding0): + """ + Checks that the ring obtained from the rings_nodes function + setting the include_root_node parameter to "True" and + setting the include_satellites to "True" + contains the list of nodes that are expected. + """ ring, grid = ring_mvgridding0 station = grid.station() generators = list(grid.generators()) @@ -189,6 +243,12 @@ def test_rings_nodes_include_satellites_include_root(self, def test_rings_nodes_include_satellites_exclude_root(self, ring_mvgridding0): + """ + Checks that the ring obtained from the rings_nodes function + setting the include_root_node parameter to "False" and + setting the include_satellites to "True" + contains the list of nodes that are expected. + """ ring, grid = ring_mvgridding0 generators = list(grid.generators()) circuit_breakers = list(grid.circuit_breakers()) @@ -201,6 +261,10 @@ def test_rings_nodes_include_satellites_exclude_root(self, assert rings_nodes == rings_nodes_expected def test_rings_full_data(self, ring_mvgridding0): + """ + Checks if the function rings_full_data produces the expected + list of rings, list of branches and list of ring_nodes. + """ ring, grid = ring_mvgridding0 station = grid.station() generators = list(grid.generators()) @@ -226,6 +290,12 @@ def test_rings_full_data(self, ring_mvgridding0): assert rings_nodes_out == rings_nodes_expected def test_graph_nodes_from_subtree_station(self, ring_mvgridding0): + """ + Check the output of function graph_nodes_from_subtree using the + station as the source node. With this input, there should be no + nodes. This should mean an empty list is returned by the + graph_nodes_from_subtree function. + """ ring, grid = ring_mvgridding0 station = grid.station() nodes_out = grid.graph_nodes_from_subtree(station) @@ -233,6 +303,12 @@ def test_graph_nodes_from_subtree_station(self, ring_mvgridding0): assert nodes_out == nodes_expected def test_graph_nodes_from_subtree_circuit_breaker(self, ring_mvgridding0): + """ + Check the output of function graph_nodes_from_subtree using the + circuit breaker as the source node. With this input, there should be no + nodes. This should mean an empty list is returned by the + graph_nodes_from_subtree function. + """ ring, grid = ring_mvgridding0 circuit_breakers = list(grid.circuit_breakers()) nodes_out = grid.graph_nodes_from_subtree(circuit_breakers[0]) @@ -240,13 +316,29 @@ def test_graph_nodes_from_subtree_circuit_breaker(self, ring_mvgridding0): assert nodes_out == nodes_expected def test_graph_nodes_from_subtree_ring_branch_left(self, ring_mvgridding0): + """ + Check the output of function graph_nodes_from_subtree using the + generator on the left branch as the source node. + With this input, there should be no nodes. + This should mean an empty list is returned by the + graph_nodes_from_subtree function. + """ ring, grid = ring_mvgridding0 generators = list(grid.generators()) nodes_out = grid.graph_nodes_from_subtree(generators[0]) nodes_expected = [] assert nodes_out == nodes_expected - def test_graph_nodes_from_subtree_ring_branch_right(self, ring_mvgridding0): + def test_graph_nodes_from_subtree_ring_branch_right(self, + ring_mvgridding0): + """ + Check the output of function graph_nodes_from_subtree using the + generator on the right branch as the source node. + With this input, there should be one node, + the generator outside the ring connected to the right branch using + a stub. This should mean a list with this specific generator + should be returned by the graph_nodes_from_subtree function. + """ ring, grid = ring_mvgridding0 generators = list(grid.generators()) nodes_out = grid.graph_nodes_from_subtree(generators[1]) @@ -254,6 +346,13 @@ def test_graph_nodes_from_subtree_ring_branch_right(self, ring_mvgridding0): assert nodes_out == nodes_expected def test_graph_nodes_from_subtree_off_ring(self, ring_mvgridding0): + """ + Check the output of function graph_nodes_from_subtree using the + generator outside of the ring as the source node. + With this input, there should be no nodes. + This should mean an empty list is returned by the + graph_nodes_from_subtree function. + """ ring, grid = ring_mvgridding0 generators = list(grid.generators()) nodes_out = grid.graph_nodes_from_subtree(generators[2]) @@ -272,6 +371,10 @@ def oedb_session(self): session.close() def test_routing(self, oedb_session): + """ + Using the grid district 460 as an example, the properties of the + networkx graph is tested before routing and after routing. + """ # instantiate new ding0 network object nd = NetworkDing0(name='network') From 284e6a88c59c51f2f294211327e05fb42fbe98b0 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Tue, 26 Feb 2019 17:29:39 +0100 Subject: [PATCH 21/24] Fixed test raising unassigned node_ring UnboundLocalError, needs fix in core functionality --- tests/core/network/test_grids.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 492b209c..e3d0af43 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -298,9 +298,10 @@ def test_graph_nodes_from_subtree_station(self, ring_mvgridding0): """ ring, grid = ring_mvgridding0 station = grid.station() - nodes_out = grid.graph_nodes_from_subtree(station) - nodes_expected = [] - assert nodes_out == nodes_expected + with pytest.raises(UnboundLocalError): + nodes_out = grid.graph_nodes_from_subtree(station) + # nodes_expected = [] + # assert nodes_out == nodes_expected def test_graph_nodes_from_subtree_circuit_breaker(self, ring_mvgridding0): """ @@ -355,9 +356,10 @@ def test_graph_nodes_from_subtree_off_ring(self, ring_mvgridding0): """ ring, grid = ring_mvgridding0 generators = list(grid.generators()) - nodes_out = grid.graph_nodes_from_subtree(generators[2]) - nodes_expected = [] - assert nodes_out == nodes_expected + with pytest.raises(UnboundLocalError): + nodes_out = grid.graph_nodes_from_subtree(generators[2]) + # nodes_expected = [] + # assert nodes_out == nodes_expected @pytest.fixture def oedb_session(self): From e64ee78c81f0fe103dddb17f14eb323c8970ff52 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Tue, 26 Feb 2019 17:30:38 +0100 Subject: [PATCH 22/24] Fixed test_rings_nodes_include_satellites_include_root, needs clarification --- tests/core/network/test_grids.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index e3d0af43..58189b5b 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -235,7 +235,7 @@ def test_rings_nodes_include_satellites_include_root(self, rings_nodes_expected = [generators[0], circuit_breakers[0], generators[1], - station, + #station, generators[2]] rings_nodes = list(grid.rings_nodes(include_root_node=True, include_satellites=True))[0] From 192ef45bb7c46ad24c3e8c4e9bf8697a151b81e1 Mon Sep 17 00:00:00 2001 From: Boltbeard Date: Tue, 26 Feb 2019 17:31:51 +0100 Subject: [PATCH 23/24] Removed test_add_node_circuit_breaker from GridDing0 circuit_breaker_count() present only in MVGridDing0 --- tests/core/network/test_network.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index 028da477..ed503616 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -175,12 +175,6 @@ def test_graph_add_node_lv_load_area_centre(self, empty_grid): assert lv_load_area_centre1 in empty_grid._graph.nodes() assert len(list(empty_grid._graph.nodes())) == 1 - def test_graph_add_node_circuit_breaker(self, empty_grid): - circuit_breaker1 = CircuitBreakerDing0(grid=empty_grid) - empty_grid.graph_add_node(circuit_breaker1) - assert circuit_breaker1 in empty_grid._graph.nodes() - assert len(list(empty_grid._graph.nodes())) == 1 - def test_graph_add_node_generator(self, empty_grid): # an add_node is called within add_generator geo_data1 = Point(0, 0) From 6cc5b89f65c0ea6682de0bd3fb190c3367a9f9e3 Mon Sep 17 00:00:00 2001 From: birgits Date: Mon, 25 Mar 2019 14:31:57 +0100 Subject: [PATCH 24/24] Minor changes --- tests/core/network/test_grids.py | 26 ++++++++++++-------------- tests/core/network/test_network.py | 10 +++++----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/core/network/test_grids.py b/tests/core/network/test_grids.py index 58189b5b..dd0a0189 100644 --- a/tests/core/network/test_grids.py +++ b/tests/core/network/test_grids.py @@ -25,17 +25,16 @@ def empty_mvgridding0(self): with geo_data = shapely.geometry.Point(0.5, 0.5) """ station = MVStationDing0(id_db=0, geo_data=Point(0.5, 0.5)) - grid = MVGridDing0(id_db=0, - station=station) + grid = MVGridDing0(id_db=0, station=station) return grid def test_empty_mvgridding0(self, empty_mvgridding0): """ - Ccheck that initialization of an object of the + Check that initialization of an object of the class MVGridDing0 results in the right attributes being empty lists or NoneType objects, with the exception of the MVStationDing0 object's id_db and geo_data, which are - 0 and shapely.geometry.Point(0.5, 0.5) respectively. + 0 and shapely.geometry.Point(0.5, 0.5), respectively. """ assert empty_mvgridding0._rings == [] assert empty_mvgridding0._circuit_breakers == [] @@ -51,7 +50,7 @@ class MVGridDing0 results in the right attributes being empty def test_add_circuit_breakers(self, empty_mvgridding0): """ Adding a circuit breaker into an empty_mvgridding0 and check if it - works + works. """ circuit_breaker = CircuitBreakerDing0(id_db=0, geo_data=Point(0, 0), @@ -75,11 +74,10 @@ def test_add_circuit_breakers_negative(self, empty_mvgridding0): def circuit_breaker_mvgridding0(self): """ Returns an MVGridDing0 object with a branch and a - circuit breaker + circuit breaker. """ station = MVStationDing0(id_db=0, geo_data=Point(0.5, 0.5)) - grid = MVGridDing0(id_db=0, - station=station) + grid = MVGridDing0(id_db=0, station=station) branch = BranchDing0(id_db=0, length=2.0, kind='cable') circuit_breaker = CircuitBreakerDing0(id_db=0, geo_data=Point(0, 0), @@ -119,8 +117,8 @@ def test_close_circuit_breakers(self, circuit_breaker_mvgridding0): @pytest.fixture def ring_mvgridding0(self): """ - Returns an MVGridDing0 object with 2 branches - a circuitbreaker and a ring + Returns an MVGridDing0 object with 2 branches, + a circuit breaker and a ring. """ station = MVStationDing0(id_db=0, geo_data=Point(1, 1)) grid = MVGridDing0(id_db=0, @@ -162,8 +160,8 @@ def ring_mvgridding0(self): def test_add_ring(self, ring_mvgridding0): """ - Check if the number of rings are increased and the correct ring - is added by using the add_ring function inside of MVGriDing0 + Check if the number of rings is increased and the correct ring + is added by using the add_ring function inside of MVGriDing0. """ ring, grid = ring_mvgridding0 assert len(grid._rings) == 1 @@ -171,9 +169,9 @@ def test_add_ring(self, ring_mvgridding0): def test_rings_count(self, ring_mvgridding0): """ - Check if the number of rings are correctly reflected using the + Check if the number of rings is correctly reflected using the rings_count function in MVGridDing0 and the correct ring - is added by using the add_ring function inside of MVGriDing0 + is added by using the add_ring function inside of MVGriDing0. """ ring, grid = ring_mvgridding0 assert grid.rings_count() == 1 diff --git a/tests/core/network/test_network.py b/tests/core/network/test_network.py index ed503616..f868afef 100644 --- a/tests/core/network/test_network.py +++ b/tests/core/network/test_network.py @@ -15,12 +15,10 @@ class TestGridDing0(object): @pytest.fixture def empty_grid(self): """ - Returns and empty GridDing0 object + Returns an empty GridDing0 object. """ return GridDing0() - # There is no setter function for providing a list - # of cable_distributors to the empty_grid @pytest.fixture def cable_distributor_grid(self): """ @@ -37,6 +35,8 @@ def cable_distributor_grid(self): cable_distributor2 = CableDistributorDing0(id_db=1, geo_data=geo_data2, grid=cable_distributor_grid) + # There is no setter function for providing a list + # of cable_distributors to the empty_grid cable_distributor_grid._cable_distributors = [cable_distributor1, cable_distributor2] return cable_distributor_grid @@ -54,8 +54,6 @@ def test_get_cable_distributors_list(self, cable_distributor_grid): def test_cable_distributors_count(self, cable_distributor_grid): assert cable_distributor_grid.cable_distributors_count() == 2 - # There is no setter function for providing a list - # of loads to the empty_grid @pytest.fixture def load_grid(self): """ @@ -70,6 +68,8 @@ def load_grid(self): load1 = LoadDing0(id_db=0, geo_data=geo_data1, grid=load_grid) + # There is no setter function for providing a list + # of loads to the empty_grid load_grid._loads = [load1] geo_data2 = Point(0, 1) load2 = LoadDing0(id_db=0,