Skip to content

Commit acc890f

Browse files
fix: delete_branch3 used wrong argument name (#29)
Signed-off-by: Vincent Koppen <[email protected]>
1 parent 1888e15 commit acc890f

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/power_grid_model_ds/_core/model/graphs/models/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def delete_branch_array(self, branch_array: BranchArray, raise_on_fail: bool = T
158158
if self._branch_is_relevant(branch):
159159
self.delete_branch(branch.from_node.item(), branch.to_node.item(), raise_on_fail=raise_on_fail)
160160

161-
def delete_branch3_array(self, branch_array: Branch3Array, raise_on_fail: bool = True) -> None:
161+
def delete_branch3_array(self, branch3_array: Branch3Array, raise_on_fail: bool = True) -> None:
162162
"""Delete all branch3s in the branch3 array from the graph."""
163-
for branch3 in branch_array:
163+
for branch3 in branch3_array:
164164
branches = _get_branch3_branches(branch3)
165165
self.delete_branch_array(branches, raise_on_fail=raise_on_fail)
166166

tests/unit/model/graphs/test_container.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,57 @@ def test_from_arrays(basic_grid):
2626
assert set(basic_grid.node.id) == set(graphs.complete_graph.external_ids)
2727

2828

29+
@pytest.fixture
30+
def graph_container_with_5_nodes():
31+
graph_container = GraphContainer.empty()
32+
for node_id in range(1, 6):
33+
node = NodeArray.empty(1)
34+
node.id = node_id
35+
graph_container.add_node(node)
36+
return graph_container
37+
38+
39+
@pytest.fixture
40+
def three_winding_transformers():
41+
three_winding_transformers = ThreeWindingTransformerArray.empty(2)
42+
three_winding_transformers.id = [301, 302]
43+
three_winding_transformers.node_1 = [1, 1]
44+
three_winding_transformers.node_2 = [2, 4]
45+
three_winding_transformers.node_3 = [3, 5]
46+
three_winding_transformers.status_1 = [1, 1]
47+
three_winding_transformers.status_2 = [1, 1]
48+
three_winding_transformers.status_3 = [0, 1]
49+
50+
return three_winding_transformers
51+
52+
53+
def test_add_branch3(graph_container_with_5_nodes, three_winding_transformers):
54+
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
55+
for from_node, to_node in [(1, 2), (1, 4), (1, 5), (4, 5)]:
56+
assert graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
57+
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
58+
59+
for from_node, to_node in [(1, 3), (2, 3)]:
60+
assert not graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
61+
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
62+
63+
64+
def test_delete_branch3(graph_container_with_5_nodes, three_winding_transformers):
65+
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
66+
graph_container_with_5_nodes.delete_branch3(three_winding_transformers[0])
67+
68+
assert not graph_container_with_5_nodes.active_graph.has_branch(1, 2)
69+
assert not graph_container_with_5_nodes.complete_graph.has_branch(1, 2)
70+
for from_node, to_node in [(1, 4), (1, 5), (4, 5)]:
71+
assert graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
72+
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
73+
graph_container_with_5_nodes.delete_branch3(three_winding_transformers[1])
74+
75+
for from_node, to_node in [(1, 2), (1, 4), (1, 5), (4, 5)]:
76+
assert not graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
77+
assert not graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
78+
79+
2980
def test_from_arrays_active_three_winding(basic_grid):
3081
nodes = NodeArray.zeros(3)
3182
nodes.id = [1000, 1001, 1002]

0 commit comments

Comments
 (0)