|
3 | 3 |
|
4 | 4 | """Tests for the frequenz.microgrid_component_graph package.""" |
5 | 5 |
|
| 6 | +from frequenz.client.common.microgrid import MicrogridId |
| 7 | +from frequenz.client.common.microgrid.components import ComponentId |
| 8 | +from frequenz.client.microgrid.component import ( |
| 9 | + Component, |
| 10 | + ComponentConnection, |
| 11 | + GridConnectionPoint, |
| 12 | + Meter, |
| 13 | + SolarInverter, |
| 14 | +) |
| 15 | + |
6 | 16 | from frequenz import microgrid_component_graph |
7 | 17 |
|
8 | 18 |
|
9 | | -def test_loading() -> None: |
| 19 | +def test_graph_creation() -> None: |
10 | 20 | """Test that the microgrid_component_graph module loads correctly.""" |
11 | | - assert microgrid_component_graph is not None |
| 21 | + graph: microgrid_component_graph.ComponentGraph[ |
| 22 | + Component, ComponentConnection, ComponentId |
| 23 | + ] = microgrid_component_graph.ComponentGraph( |
| 24 | + components={ |
| 25 | + GridConnectionPoint( |
| 26 | + id=ComponentId(1), |
| 27 | + microgrid_id=MicrogridId(1), |
| 28 | + rated_fuse_current=100, |
| 29 | + ), |
| 30 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 31 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 32 | + SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)), |
| 33 | + }, |
| 34 | + connections={ |
| 35 | + ComponentConnection(source=ComponentId(1), destination=ComponentId(2)), |
| 36 | + ComponentConnection(source=ComponentId(1), destination=ComponentId(3)), |
| 37 | + ComponentConnection(source=ComponentId(2), destination=ComponentId(4)), |
| 38 | + }, |
| 39 | + ) |
| 40 | + assert graph.components() == { |
| 41 | + GridConnectionPoint( |
| 42 | + id=ComponentId(1), microgrid_id=MicrogridId(1), rated_fuse_current=100 |
| 43 | + ), |
| 44 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 45 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 46 | + SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)), |
| 47 | + } |
| 48 | + assert graph.connections() == { |
| 49 | + ComponentConnection(source=ComponentId(1), destination=ComponentId(2)), |
| 50 | + ComponentConnection(source=ComponentId(1), destination=ComponentId(3)), |
| 51 | + ComponentConnection(source=ComponentId(2), destination=ComponentId(4)), |
| 52 | + } |
| 53 | + assert graph.components(matching_ids=[ComponentId(2), ComponentId(3)]) == { |
| 54 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 55 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 56 | + } |
| 57 | + assert graph.components(matching_ids=ComponentId(1)) == { |
| 58 | + GridConnectionPoint( |
| 59 | + id=ComponentId(1), microgrid_id=MicrogridId(1), rated_fuse_current=100 |
| 60 | + ) |
| 61 | + } |
| 62 | + assert graph.components(matching_types=Meter) == { |
| 63 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 64 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 65 | + } |
| 66 | + assert graph.components(matching_types=[Meter, GridConnectionPoint]) == { |
| 67 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 68 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 69 | + GridConnectionPoint( |
| 70 | + id=ComponentId(1), microgrid_id=MicrogridId(1), rated_fuse_current=100 |
| 71 | + ), |
| 72 | + } |
| 73 | + assert graph.components( |
| 74 | + matching_types=[Meter, SolarInverter], |
| 75 | + matching_ids=[ComponentId(1), ComponentId(3), ComponentId(4)], |
| 76 | + ) == { |
| 77 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 78 | + SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)), |
| 79 | + } |
0 commit comments