Skip to content

Commit 9cdbdae

Browse files
committed
Tests: Add convenience methods to create batteries with multiple inverters
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 23a141f commit 9cdbdae

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

tests/actor/power_distributing/test_power_distributing.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,7 @@ async def test_battery_two_inverters(self, mocker: MockerFixture) -> None:
537537
graph = gen.to_graph(
538538
(
539539
ComponentCategory.METER,
540-
[
541-
(
542-
ComponentCategory.METER,
543-
[
544-
(
545-
ComponentCategory.INVERTER,
546-
bat_component,
547-
),
548-
(
549-
ComponentCategory.INVERTER,
550-
bat_component,
551-
),
552-
],
553-
),
554-
],
540+
[gen.battery_with_inverter(bat_component, 2)],
555541
)
556542
)
557543

@@ -600,28 +586,7 @@ async def test_two_batteries_three_inverters(self, mocker: MockerFixture) -> Non
600586
batteries = gen.components(*[ComponentCategory.BATTERY] * 2)
601587

602588
graph = gen.to_graph(
603-
(
604-
ComponentCategory.METER,
605-
[
606-
(
607-
ComponentCategory.METER,
608-
[
609-
(
610-
ComponentCategory.INVERTER,
611-
[*batteries],
612-
),
613-
(
614-
ComponentCategory.INVERTER,
615-
[*batteries],
616-
),
617-
(
618-
ComponentCategory.INVERTER,
619-
[*batteries],
620-
),
621-
],
622-
),
623-
],
624-
)
589+
(ComponentCategory.METER, gen.batteries_with_inverter(batteries, 3))
625590
)
626591

627592
async with _mocks(mocker, graph=graph) as mocks:

tests/utils/graph_generator.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,55 @@ def component(self, other: Component) -> Component:
7070
the given component.
7171
"""
7272

73+
def battery_with_inverter(self, battery: Component, num_inverters: int) -> Any:
74+
"""Add a meter and inverters to the given battery.
75+
76+
Args:
77+
one_or_more_batteries: the battery component.
78+
num_inverters: the number of inverters to create.
79+
80+
Returns:
81+
connected graph components for the given battery.
82+
"""
83+
return self._battery_with_inverter(battery, num_inverters)
84+
85+
def batteries_with_inverter(
86+
self, one_or_more_batteries: list[Component], num_inverters: int
87+
) -> Any:
88+
"""Add a meter and inverters to the given batteries.
89+
90+
Args:
91+
one_or_more_batteries: the battery components.
92+
num_inverters: the number of inverters to create.
93+
94+
Returns:
95+
connected graph components for the given batteries.
96+
"""
97+
return self._battery_with_inverter(one_or_more_batteries, num_inverters)
98+
99+
def _battery_with_inverter(
100+
self, one_or_more_batteries: Component | list[Component], num_inverters: int
101+
) -> Any:
102+
"""Add a meter and inverters to the given battery or batteries.
103+
104+
Args:
105+
one_or_more_batteries: the battery component or components.
106+
num_inverters: the number of inverters to create.
107+
108+
Returns:
109+
connected graph components for the given battery or batteries.
110+
"""
111+
return (
112+
ComponentCategory.METER,
113+
[
114+
(
115+
self.component(ComponentCategory.INVERTER, InverterType.BATTERY),
116+
one_or_more_batteries,
117+
)
118+
for _ in range(num_inverters)
119+
],
120+
)
121+
73122
@overload
74123
def component(
75124
self, other: ComponentCategory, comp_type: ComponentType | None = None

0 commit comments

Comments
 (0)