Skip to content

Commit d282b62

Browse files
committed
Add start_mock_client method
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent b7707ea commit d282b62

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

tests/timeseries/mock_microgrid.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,31 @@ def __init__(
9494
self._actors: list[typing.Any] = []
9595
self._start_meter_streaming(4)
9696

97+
def start_mock_client(
98+
self, initialize_cb: Callable[[MockMicrogridClient], None]
99+
) -> MockMicrogridClient:
100+
"""Set up the mock client.
101+
102+
Creates the microgrid mock client, initializes it, and starts the streaming
103+
tasks.
104+
105+
For unittests, users should use the `start()` method.
106+
107+
Args:
108+
initialize_cb: callback to initialize the mock client.
109+
110+
Returns:
111+
A MockMicrogridClient instance.
112+
"""
113+
self._microgrid = MockMicrogridClient(self._components, self._connections)
114+
115+
initialize_cb(self._microgrid)
116+
117+
self._streaming_tasks = [
118+
asyncio.create_task(coro) for coro in self._streaming_coros
119+
]
120+
return self._microgrid
121+
97122
async def start(
98123
self, mocker: MockerFixture
99124
) -> Tuple[Broadcast[ComponentMetricRequest], ChannelRegistry]:
@@ -103,11 +128,8 @@ async def start(
103128
A sender to send requests to the Resampling actor, and a corresponding
104129
channel registry.
105130
"""
106-
self._microgrid = MockMicrogridClient(self._components, self._connections)
107-
self._microgrid.initialize(mocker)
108-
self._streaming_tasks = [
109-
asyncio.create_task(coro) for coro in self._streaming_coros
110-
]
131+
self.start_mock_client(lambda mock_client: mock_client.initialize(mocker))
132+
111133
await asyncio.sleep(self._sample_rate_s / 2)
112134
ret = await self._init_client_and_actors()
113135
return ret

0 commit comments

Comments
 (0)