11# License: MIT
22# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
34"""Tests for BatteryStatusTracker."""
45
56# pylint: disable=too-many-lines
3839from tests .timeseries .mock_microgrid import MockMicrogrid
3940
4041from ....utils .component_data_wrapper import BatteryDataWrapper , InverterDataWrapper
42+ from ....utils .receive_timeout import Timeout , receive_timeout
4143
4244
4345def battery_data ( # pylint: disable=too-many-arguments
@@ -123,26 +125,6 @@ class Message(Generic[T]):
123125INVERTER_ID = 8
124126
125127
126- class _Timeout :
127- """Sentinel for timeout."""
128-
129-
130- async def recv_timeout (recv : Receiver [T ], timeout : float = 0.1 ) -> T | type [_Timeout ]:
131- """Receive message from receiver with timeout.
132-
133- Args:
134- recv: Receiver to receive message from.
135- timeout: Timeout in seconds.
136-
137- Returns:
138- Received message or _Timeout if timeout is reached.
139- """
140- try :
141- return await asyncio .wait_for (recv .receive (), timeout = timeout )
142- except asyncio .TimeoutError :
143- return _Timeout
144-
145-
146128# pylint: disable=protected-access, unused-argument
147129class TestBatteryStatus :
148130 """Tests BatteryStatusTracker."""
@@ -952,7 +934,7 @@ async def test_critical_error(
952934 # --- battery warning error (keeps working) ---
953935 await self ._send_healthy_inverter (mock_microgrid )
954936 await self ._send_warning_error_battery (mock_microgrid )
955- assert await recv_timeout (status_receiver , timeout = 0.1 ) is _Timeout
937+ assert await receive_timeout (status_receiver , timeout = 0.1 ) is Timeout
956938
957939 await self ._send_healthy_battery (mock_microgrid )
958940 await self ._send_healthy_inverter (mock_microgrid )
@@ -971,7 +953,7 @@ async def test_critical_error(
971953 # --- inverter warning error (keeps working) ---
972954 await self ._send_healthy_battery (mock_microgrid )
973955 await self ._send_warning_error_inverter (mock_microgrid )
974- assert await recv_timeout (status_receiver , timeout = 0.1 ) is _Timeout
956+ assert await receive_timeout (status_receiver , timeout = 0.1 ) is Timeout
975957
976958 await self ._send_healthy_battery (mock_microgrid )
977959 await self ._send_healthy_inverter (mock_microgrid )
@@ -1023,11 +1005,11 @@ async def test_stale_data(
10231005 # --- stale battery data ---
10241006 await self ._send_healthy_inverter (mock_microgrid )
10251007 await self ._send_healthy_battery (mock_microgrid , timestamp )
1026- assert await recv_timeout (status_receiver ) is _Timeout
1008+ assert await receive_timeout (status_receiver ) is Timeout
10271009
10281010 await self ._send_healthy_inverter (mock_microgrid )
10291011 await self ._send_healthy_battery (mock_microgrid , timestamp )
1030- assert await recv_timeout (status_receiver , 0.3 ) == ComponentStatus (
1012+ assert await receive_timeout (status_receiver , 0.3 ) == ComponentStatus (
10311013 BATTERY_ID , ComponentStatusEnum .NOT_WORKING
10321014 )
10331015
@@ -1039,11 +1021,11 @@ async def test_stale_data(
10391021 # --- stale inverter data ---
10401022 await self ._send_healthy_battery (mock_microgrid )
10411023 await self ._send_healthy_inverter (mock_microgrid , timestamp )
1042- assert await recv_timeout (status_receiver ) is _Timeout
1024+ assert await receive_timeout (status_receiver ) is Timeout
10431025
10441026 await self ._send_healthy_battery (mock_microgrid )
10451027 await self ._send_healthy_inverter (mock_microgrid , timestamp )
1046- assert await recv_timeout (status_receiver , 0.3 ) == ComponentStatus (
1028+ assert await receive_timeout (status_receiver , 0.3 ) == ComponentStatus (
10471029 BATTERY_ID , ComponentStatusEnum .NOT_WORKING
10481030 )
10491031
0 commit comments