Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions tests/test_formula_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
LiIonBattery,
Meter,
SolarInverter,
SteamBoiler,
WindTurbine,
)

Expand Down Expand Up @@ -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(
Expand All @@ -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",
),
]


Expand Down Expand Up @@ -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()},
Expand Down
29 changes: 29 additions & 0 deletions tests/test_microgrid_component_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading