@@ -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
15051430class TestComponentTypeIdentification :
15061431 """Test the component type identification methods in the component graph."""
0 commit comments