11# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
22#
33# SPDX-License-Identifier: MPL-2.0
4+ from copy import deepcopy
45
56import pytest
67
1213# pylint: disable=missing-function-docstring
1314
1415
15- def test_from_arrays (basic_grid : Grid ):
16- graphs = GraphContainer . from_arrays (basic_grid )
16+ def test_rebuild_graphs (basic_grid : Grid ):
17+ orig_graphs = deepcopy (basic_grid . graphs )
1718
18- assert isinstance (graphs , GraphContainer )
19- assert basic_grid .graphs .complete_graph .nr_nodes == graphs .complete_graph .nr_nodes
20- assert basic_grid .graphs .complete_graph .nr_branches == 6
21-
22- assert basic_grid .graphs .active_graph .nr_nodes == graphs .active_graph .nr_nodes
23- assert basic_grid .graphs .active_graph .nr_branches == 5
24-
25- assert set (basic_grid .node .id ) == set (graphs .active_graph .external_ids )
26- assert set (basic_grid .node .id ) == set (graphs .complete_graph .external_ids )
19+ basic_grid .graphs = GraphContainer .empty ()
20+ assert basic_grid .graphs != orig_graphs
21+ basic_grid .rebuild_graphs ()
22+ assert orig_graphs == basic_grid .graphs
2723
2824
2925@pytest .fixture
@@ -81,7 +77,7 @@ def test_delete_branch3(
8177 assert not graph_container_with_5_nodes .complete_graph .has_branch (from_node , to_node )
8278
8379
84- def test_from_arrays_active_three_winding (basic_grid : Grid ):
80+ def test_rebuild_graphs_active_three_winding (basic_grid : Grid ):
8581 nodes = NodeArray .zeros (3 )
8682 nodes .id = [1000 , 1001 , 1002 ]
8783 basic_grid .append (nodes )
@@ -95,15 +91,16 @@ def test_from_arrays_active_three_winding(basic_grid: Grid):
9591 three_winding_transformer .status_3 = 1
9692 basic_grid .append (three_winding_transformer )
9793
98- graphs = GraphContainer .from_arrays (basic_grid )
94+ basic_grid .rebuild_graphs ()
95+ graphs = basic_grid .graphs
9996 assert basic_grid .graphs .complete_graph .nr_nodes == graphs .complete_graph .nr_nodes
10097 assert basic_grid .graphs .complete_graph .nr_branches == 6 + 3
10198
10299 assert basic_grid .graphs .active_graph .nr_nodes == graphs .active_graph .nr_nodes
103100 assert basic_grid .graphs .active_graph .nr_branches == 5 + 3
104101
105102
106- def test_from_arrays_partially_active_three_winding (basic_grid : Grid ):
103+ def test_rebuild_graphs_partially_active_three_winding (basic_grid : Grid ):
107104 nodes = NodeArray .zeros (3 )
108105 nodes .id = [1000 , 1001 , 1002 ]
109106 basic_grid .append (nodes )
@@ -117,7 +114,8 @@ def test_from_arrays_partially_active_three_winding(basic_grid: Grid):
117114 three_winding_transformer .status_3 = 0
118115 basic_grid .append (three_winding_transformer )
119116
120- graphs = GraphContainer .from_arrays (basic_grid )
117+ basic_grid .rebuild_graphs ()
118+ graphs = basic_grid .graphs
121119 assert basic_grid .graphs .complete_graph .nr_nodes == graphs .complete_graph .nr_nodes
122120 assert basic_grid .graphs .complete_graph .nr_branches == 6 + 3
123121
@@ -132,8 +130,8 @@ def test_from_arrays_partially_active_three_winding(basic_grid: Grid):
132130 assert not basic_grid .graphs .active_graph .has_branch (1001 , 1002 )
133131
134132
135- def test_from_arrays_invalid_arrays (basic_grid : Grid ):
133+ def test_rebuild_graphs_invalid_arrays (basic_grid : Grid ):
136134 basic_grid .node = basic_grid .node .exclude (id = 106 )
137135
138136 with pytest .raises (RecordDoesNotExist ):
139- GraphContainer . from_arrays ( basic_grid )
137+ basic_grid . rebuild_graphs ( )
0 commit comments