Skip to content

Commit 6f63d69

Browse files
committed
Add tests for the ComponentGraphGenerator
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 2e8ddf6 commit 6f63d69

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

tests/test_gridpool.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,66 @@
33

44
"""Tests for the frequenz.gridpool package."""
55

6-
import frequenz.gridpool
6+
import asyncio
7+
from unittest.mock import AsyncMock, MagicMock, patch
78

9+
from frequenz.client.assets import AssetsApiClient
10+
from frequenz.client.assets.electrical_component import (
11+
ComponentConnection,
12+
GridConnectionPoint,
13+
Meter,
14+
SolarInverter,
15+
)
16+
from frequenz.client.common.microgrid import MicrogridId
17+
from frequenz.client.common.microgrid.electrical_components import ElectricalComponentId
818

9-
def test_loading() -> None:
19+
from frequenz.gridpool._graph_generator import ComponentGraphGenerator
20+
21+
22+
async def test_formula_generation() -> None:
1023
"""Test that the frequenz.gridpool package loads correctly."""
11-
assert frequenz.gridpool is not None
24+
assets_client_mock = MagicMock(spec=AssetsApiClient)
25+
assets_client_mock.list_microgrid_electrical_components = AsyncMock(
26+
return_value=[
27+
GridConnectionPoint(
28+
id=ElectricalComponentId(1),
29+
microgrid_id=MicrogridId(10),
30+
rated_fuse_current=100,
31+
),
32+
Meter(
33+
id=ElectricalComponentId(2),
34+
microgrid_id=MicrogridId(10),
35+
),
36+
Meter(
37+
id=ElectricalComponentId(3),
38+
microgrid_id=MicrogridId(10),
39+
),
40+
SolarInverter(
41+
id=ElectricalComponentId(4),
42+
microgrid_id=MicrogridId(10),
43+
),
44+
]
45+
)
46+
assets_client_mock.list_microgrid_electrical_component_connections = AsyncMock(
47+
return_value=[
48+
ComponentConnection(
49+
source=ElectricalComponentId(1),
50+
destination=ElectricalComponentId(2),
51+
),
52+
ComponentConnection(
53+
source=ElectricalComponentId(1),
54+
destination=ElectricalComponentId(3),
55+
),
56+
ComponentConnection(
57+
source=ElectricalComponentId(2),
58+
destination=ElectricalComponentId(4),
59+
),
60+
]
61+
)
62+
63+
g = ComponentGraphGenerator("grpc://never.where:-55", connect=False)
64+
with patch.object(g, "_client", assets_client_mock):
65+
graph = await g.get_component_graph(MicrogridId(10))
66+
67+
assert graph.grid_formula() == "COALESCE(#2, #4, 0.0) + #3"
68+
assert graph.pv_formula(None) == "COALESCE(#4, #2, 0.0)"

0 commit comments

Comments
 (0)