From 9614a1a0cfad97a4158f733beb902b03d08c1e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20V=C3=B6lcker?= Date: Thu, 7 May 2026 15:50:31 +0200 Subject: [PATCH] Add tests for steam boilers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Völcker --- tests/test_formula_preferences.py | 28 ++++++++++++++++++------ tests/test_microgrid_component_graph.py | 29 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/tests/test_formula_preferences.py b/tests/test_formula_preferences.py index 5013cec..bc699f6 100644 --- a/tests/test_formula_preferences.py +++ b/tests/test_formula_preferences.py @@ -32,6 +32,7 @@ LiIonBattery, Meter, SolarInverter, + SteamBoiler, WindTurbine, ) @@ -144,6 +145,20 @@ def _ev_graph( ) +def _steam_boiler_graph( + config: ComponentGraphConfig | None = None, +) -> ComponentGraph[Any, Any, Any]: + return ComponentGraph( + components={ + _grid(), + _meter(), + SteamBoiler(id=ComponentId(3), microgrid_id=_MGRID), + }, + connections={_conn(1, 2), _conn(2, 3)}, + config=config or ComponentGraphConfig(), + ) + + _CATEGORIES = [ pytest.param(_pv_graph, "pv_formula", "prefer_meters_in_pv_formula", id="pv"), pytest.param( @@ -165,6 +180,12 @@ def _ev_graph( "prefer_meters_in_ev_charger_formula", id="ev_charger", ), + pytest.param( + _steam_boiler_graph, + "steam_boiler_formula", + "prefer_meters_in_steam_boiler_formula", + id="steam_boiler", + ), ] @@ -217,13 +238,6 @@ def test_override_false_wins_over_global_true( assert formula == _DEVICE_PRIMARY -# `steam_boiler_formula` cannot be exercised end-to-end because the -# upstream `frequenz.client.microgrid` Python package does not currently -# expose a `SteamBoiler` component class, so a graph that contains a -# steam boiler cannot be constructed from Python yet. The argument-handling -# edge cases are still meaningful and worth pinning down. - - def _empty_graph() -> ComponentGraph[Any, Any, Any]: return ComponentGraph( components={_grid(), _meter()}, diff --git a/tests/test_microgrid_component_graph.py b/tests/test_microgrid_component_graph.py index 9f7cbff..7d6c301 100644 --- a/tests/test_microgrid_component_graph.py +++ b/tests/test_microgrid_component_graph.py @@ -154,6 +154,35 @@ def test_wind_turbine_graph() -> None: } +def test_steam_boiler_graph() -> None: + """Test graph creation and formula generation for Steam Boilers.""" + graph: microgrid_component_graph.ComponentGraph[ + Component, ComponentConnection, ComponentId + ] = microgrid_component_graph.ComponentGraph( + components={ + GridConnectionPoint( + id=ComponentId(1), + microgrid_id=MicrogridId(1), + rated_fuse_current=100, + ), + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), + SteamBoiler(id=ComponentId(3), microgrid_id=MicrogridId(1)), + }, + connections={ + ComponentConnection(source=ComponentId(1), destination=ComponentId(2)), + ComponentConnection(source=ComponentId(2), destination=ComponentId(3)), + }, + ) + + assert graph.components(matching_types=SteamBoiler) == { + SteamBoiler(id=ComponentId(3), microgrid_id=MicrogridId(1)) + } + assert ( + graph.steam_boiler_formula(steam_boiler_ids={ComponentId(3)}) + == "COALESCE(#2, #3, 0.0)" + ) + + def test_relay_is_passthrough() -> None: """`Relay` maps to cg's `Breaker`, a pass-through category.