Skip to content

Commit 307f473

Browse files
Add tests for steam boilers (#71)
2 parents 30d6ac5 + 9614a1a commit 307f473

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎tests/test_formula_preferences.py‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
LiIonBattery,
3333
Meter,
3434
SolarInverter,
35+
SteamBoiler,
3536
WindTurbine,
3637
)
3738

@@ -144,6 +145,20 @@ def _ev_graph(
144145
)
145146

146147

148+
def _steam_boiler_graph(
149+
config: ComponentGraphConfig | None = None,
150+
) -> ComponentGraph[Any, Any, Any]:
151+
return ComponentGraph(
152+
components={
153+
_grid(),
154+
_meter(),
155+
SteamBoiler(id=ComponentId(3), microgrid_id=_MGRID),
156+
},
157+
connections={_conn(1, 2), _conn(2, 3)},
158+
config=config or ComponentGraphConfig(),
159+
)
160+
161+
147162
_CATEGORIES = [
148163
pytest.param(_pv_graph, "pv_formula", "prefer_meters_in_pv_formula", id="pv"),
149164
pytest.param(
@@ -165,6 +180,12 @@ def _ev_graph(
165180
"prefer_meters_in_ev_charger_formula",
166181
id="ev_charger",
167182
),
183+
pytest.param(
184+
_steam_boiler_graph,
185+
"steam_boiler_formula",
186+
"prefer_meters_in_steam_boiler_formula",
187+
id="steam_boiler",
188+
),
168189
]
169190

170191

@@ -217,13 +238,6 @@ def test_override_false_wins_over_global_true(
217238
assert formula == _DEVICE_PRIMARY
218239

219240

220-
# `steam_boiler_formula` cannot be exercised end-to-end because the
221-
# upstream `frequenz.client.microgrid` Python package does not currently
222-
# expose a `SteamBoiler` component class, so a graph that contains a
223-
# steam boiler cannot be constructed from Python yet. The argument-handling
224-
# edge cases are still meaningful and worth pinning down.
225-
226-
227241
def _empty_graph() -> ComponentGraph[Any, Any, Any]:
228242
return ComponentGraph(
229243
components={_grid(), _meter()},

‎tests/test_microgrid_component_graph.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,35 @@ def test_wind_turbine_graph() -> None:
154154
}
155155

156156

157+
def test_steam_boiler_graph() -> None:
158+
"""Test graph creation and formula generation for Steam Boilers."""
159+
graph: microgrid_component_graph.ComponentGraph[
160+
Component, ComponentConnection, ComponentId
161+
] = microgrid_component_graph.ComponentGraph(
162+
components={
163+
GridConnectionPoint(
164+
id=ComponentId(1),
165+
microgrid_id=MicrogridId(1),
166+
rated_fuse_current=100,
167+
),
168+
Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)),
169+
SteamBoiler(id=ComponentId(3), microgrid_id=MicrogridId(1)),
170+
},
171+
connections={
172+
ComponentConnection(source=ComponentId(1), destination=ComponentId(2)),
173+
ComponentConnection(source=ComponentId(2), destination=ComponentId(3)),
174+
},
175+
)
176+
177+
assert graph.components(matching_types=SteamBoiler) == {
178+
SteamBoiler(id=ComponentId(3), microgrid_id=MicrogridId(1))
179+
}
180+
assert (
181+
graph.steam_boiler_formula(steam_boiler_ids={ComponentId(3)})
182+
== "COALESCE(#2, #3, 0.0)"
183+
)
184+
185+
157186
def test_relay_is_passthrough() -> None:
158187
"""`Relay` maps to cg's `Breaker`, a pass-through category.
159188

0 commit comments

Comments
 (0)