Skip to content

Commit 635914c

Browse files
committed
Remove unused private function
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 8b90479 commit 635914c

File tree

2 files changed

+0
-100
lines changed

2 files changed

+0
-100
lines changed

src/frequenz/sdk/microgrid/component_graph.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,28 +1065,3 @@ def _validate_leaf_components(self) -> None:
10651065
raise InvalidGraphError(
10661066
f"Leaf components with graph successors: {with_successors}"
10671067
)
1068-
1069-
1070-
def _correct_graph_errors(graph: _MicrogridComponentGraph) -> None:
1071-
"""Attempt to correct errors in component graph data.
1072-
1073-
For now, this handles just the special case of graph data that is missing an
1074-
explicit grid endpoint, but has an implicit one due to one or more
1075-
components having node 0 as their parent.
1076-
1077-
Args:
1078-
graph: the graph whose data to correct (will be updated in place)
1079-
"""
1080-
# Check if there is an implicit grid endpoint with id == 0.
1081-
# This is an expected case from the API: that no explicit
1082-
# grid endpoint will be provided, but that components connected
1083-
# to the grid endpoint will have node 0 as their predecessor.
1084-
# pylint: disable=protected-access
1085-
if (
1086-
graph._graph.has_node(0)
1087-
and graph._graph.in_degree(0) == 0
1088-
and graph._graph.out_degree(0) > 0
1089-
and "type" not in graph._graph.nodes[0]
1090-
):
1091-
graph._graph.add_node(0, **asdict(Component(0, ComponentCategory.GRID)))
1092-
# pylint: enable=protected-access

tests/microgrid/test_graph.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,81 +1426,6 @@ def test__validate_leaf_components(self) -> None:
14261426
graph._graph.add_edges_from([(1, 2), (1, 3), (1, 4)])
14271427
graph._validate_leaf_components()
14281428

1429-
def test_graph_correction(self) -> None:
1430-
"""Test the graph correction functionality."""
1431-
# Simple test cases for our built-in graph correction
1432-
# functionality. We test only with `refresh_from`:
1433-
# for `refresh_from_api` it suffices to test that any
1434-
# provided `correct_errors` callback gets invoked,
1435-
# which is already done in `test_refresh_from_api`.
1436-
1437-
graph = gr._MicrogridComponentGraph()
1438-
assert set(graph.components()) == set()
1439-
assert list(graph.connections()) == []
1440-
1441-
# valid graph data: no correction will be applied
1442-
graph.refresh_from(
1443-
components={
1444-
Component(1, ComponentCategory.GRID),
1445-
Component(2, ComponentCategory.METER),
1446-
},
1447-
connections={Connection(1, 2)},
1448-
correct_errors=gr._correct_graph_errors,
1449-
)
1450-
expected = {
1451-
Component(1, ComponentCategory.GRID),
1452-
Component(2, ComponentCategory.METER),
1453-
}
1454-
assert len(graph.components()) == len(expected)
1455-
assert set(graph.components()) == expected
1456-
assert list(graph.connections()) == [Connection(1, 2)]
1457-
1458-
# invalid graph data that (for now at least)
1459-
# cannot be corrected
1460-
with pytest.raises(gr.InvalidGraphError):
1461-
graph.refresh_from(
1462-
components={Component(4, ComponentCategory.METER)},
1463-
connections={Connection(3, 4)},
1464-
correct_errors=gr._correct_graph_errors,
1465-
)
1466-
1467-
# graph is still in last known good state
1468-
assert len(graph.components()) == len(expected)
1469-
assert set(graph.components()) == expected
1470-
assert list(graph.connections()) == [Connection(1, 2)]
1471-
1472-
# invalid graph data where there is no grid
1473-
# endpoint but a node has the magic value 0
1474-
# for its predecessor
1475-
1476-
# without the callback, this is identified as
1477-
# invalid
1478-
with pytest.raises(gr.InvalidGraphError):
1479-
graph.refresh_from(
1480-
components={Component(8, ComponentCategory.METER)},
1481-
connections={Connection(0, 8)},
1482-
)
1483-
1484-
# graph is still in last known good state
1485-
assert len(graph.components()) == len(expected)
1486-
assert set(graph.components()) == expected
1487-
assert list(graph.connections()) == [Connection(1, 2)]
1488-
1489-
# with the callback, this can be corrected
1490-
graph.refresh_from(
1491-
components={Component(8, ComponentCategory.METER)},
1492-
connections={Connection(0, 8)},
1493-
correct_errors=gr._correct_graph_errors,
1494-
)
1495-
expected = {
1496-
Component(8, ComponentCategory.METER),
1497-
Component(0, ComponentCategory.GRID),
1498-
}
1499-
assert len(graph.components()) == len(expected)
1500-
assert set(graph.components()) == expected
1501-
1502-
assert list(graph.connections()) == [Connection(0, 8)]
1503-
15041429

15051430
class TestComponentTypeIdentification:
15061431
"""Test the component type identification methods in the component graph."""

0 commit comments

Comments
 (0)