|
| 1 | +import asyncio |
1 | 2 | import traceback |
2 | | -from asyncio import create_task |
| 3 | +from asyncio import Event, create_task |
3 | 4 | from functools import partial |
4 | 5 | from unittest.mock import ANY, AsyncMock, MagicMock, call, patch |
5 | 6 |
|
|
22 | 23 | ) |
23 | 24 |
|
24 | 25 |
|
| 26 | +@pytest.fixture |
| 27 | +async def robot_for_unload(): |
| 28 | + device = BartRobot("robot", "-MO-ROBOT-01:") |
| 29 | + device.NOT_BUSY_TIMEOUT = 0.3 # type: ignore |
| 30 | + device.LOAD_TIMEOUT = 0.3 # type: ignore |
| 31 | + await device.connect(mock=True) |
| 32 | + |
| 33 | + trigger_complete = Event() |
| 34 | + drying_complete = Event() |
| 35 | + |
| 36 | + async def finish_later(): |
| 37 | + await drying_complete.wait() |
| 38 | + set_mock_value(device.program_running, False) |
| 39 | + |
| 40 | + async def fake_unload(*args, **kwargs): |
| 41 | + set_mock_value(device.program_running, True) |
| 42 | + await trigger_complete.wait() |
| 43 | + asyncio.create_task(finish_later()) |
| 44 | + |
| 45 | + get_mock_put(device.unload).side_effect = fake_unload |
| 46 | + return device, trigger_complete, drying_complete |
| 47 | + |
| 48 | + |
25 | 49 | async def _get_bart_robot() -> BartRobot: |
26 | 50 | device = BartRobot("robot", "-MO-ROBOT-01:") |
27 | 51 | device.LOAD_TIMEOUT = 1 # type: ignore |
@@ -206,3 +230,41 @@ async def test_moving_the_robot_will_reset_error_if_light_curtain_is_tripped_and |
206 | 230 | call.load.put(None, wait=True), |
207 | 231 | ] |
208 | 232 | ) |
| 233 | + |
| 234 | + |
| 235 | +async def test_unloading_the_robot_waits_for_drying_to_complete(robot_for_unload): |
| 236 | + robot, trigger_completed, drying_completed = robot_for_unload |
| 237 | + drying_completed.set() |
| 238 | + unload_status = robot.set(None) |
| 239 | + |
| 240 | + await asyncio.sleep(0.1) |
| 241 | + assert not unload_status.done |
| 242 | + get_mock_put(robot.unload).assert_called_once() |
| 243 | + |
| 244 | + trigger_completed.set() |
| 245 | + await unload_status |
| 246 | + assert unload_status.done |
| 247 | + |
| 248 | + |
| 249 | +async def test_unloading_the_robot_times_out_if_unloading_takes_too_long( |
| 250 | + robot_for_unload, |
| 251 | +): |
| 252 | + robot, trigger_completed, drying_completed = robot_for_unload |
| 253 | + drying_completed.set() |
| 254 | + unload_status = robot.set(None) |
| 255 | + |
| 256 | + with pytest.raises(RobotLoadError) as exc_info: |
| 257 | + await unload_status |
| 258 | + |
| 259 | + assert isinstance(exc_info.value.__cause__, TimeoutError) |
| 260 | + |
| 261 | + |
| 262 | +async def test_unloading_the_robot_times_out_if_drying_takes_too_long(robot_for_unload): |
| 263 | + robot, trigger_completed, drying_completed = robot_for_unload |
| 264 | + trigger_completed.set() |
| 265 | + unload_status = robot.set(None) |
| 266 | + |
| 267 | + with pytest.raises(RobotLoadError) as exc_info: |
| 268 | + await unload_status |
| 269 | + |
| 270 | + assert isinstance(exc_info.value.__cause__, TimeoutError) |
0 commit comments