Skip to content

Commit d257e1c

Browse files
committed
Add tests for the ComponentGraphGenerator
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 57560e1 commit d257e1c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/test_graph_generator.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Tests for the component graph generator."""
5+
6+
from unittest.mock import AsyncMock, MagicMock, patch
7+
8+
from frequenz.client.assets import AssetsApiClient
9+
from frequenz.client.assets.electrical_component import (
10+
ComponentConnection,
11+
GridConnectionPoint,
12+
Meter,
13+
SolarInverter,
14+
)
15+
from frequenz.client.common.microgrid import MicrogridId
16+
from frequenz.client.common.microgrid.electrical_components import ElectricalComponentId
17+
18+
from frequenz.gridpool._graph_generator import ComponentGraphGenerator
19+
20+
21+
async def test_formula_generation() -> None:
22+
"""Test that the frequenz.gridpool package loads correctly."""
23+
assets_client_mock = MagicMock(spec=AssetsApiClient)
24+
assets_client_mock.list_microgrid_electrical_components = AsyncMock(
25+
return_value=[
26+
GridConnectionPoint(
27+
id=ElectricalComponentId(1),
28+
microgrid_id=MicrogridId(10),
29+
rated_fuse_current=100,
30+
),
31+
Meter(
32+
id=ElectricalComponentId(2),
33+
microgrid_id=MicrogridId(10),
34+
),
35+
Meter(
36+
id=ElectricalComponentId(3),
37+
microgrid_id=MicrogridId(10),
38+
),
39+
SolarInverter(
40+
id=ElectricalComponentId(4),
41+
microgrid_id=MicrogridId(10),
42+
),
43+
]
44+
)
45+
assets_client_mock.list_microgrid_electrical_component_connections = AsyncMock(
46+
return_value=[
47+
ComponentConnection(
48+
source=ElectricalComponentId(1),
49+
destination=ElectricalComponentId(2),
50+
),
51+
ComponentConnection(
52+
source=ElectricalComponentId(1),
53+
destination=ElectricalComponentId(3),
54+
),
55+
ComponentConnection(
56+
source=ElectricalComponentId(2),
57+
destination=ElectricalComponentId(4),
58+
),
59+
]
60+
)
61+
62+
g = ComponentGraphGenerator("grpc://never.where:-55", connect=False)
63+
with patch.object(g, "_client", assets_client_mock):
64+
graph = await g.get_component_graph(MicrogridId(10))
65+
66+
assert graph.grid_formula() == "COALESCE(#2, #4, 0.0) + #3"
67+
assert graph.pv_formula(None) == "COALESCE(#4, #2, 0.0)"

0 commit comments

Comments
 (0)