Skip to content

Commit

Permalink
Use asyncio TimeoutError in wait_for_value (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram authored Sep 13, 2024
1 parent 0cbfbe6 commit 965a4d7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ophyd_async/core/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ async def wait_for_value(self, signal: SignalR[T], timeout: Optional[float]):
try:
await asyncio.wait_for(self._wait_for_value(signal), timeout)
except asyncio.TimeoutError as e:
raise TimeoutError(
raise asyncio.TimeoutError(
f"{signal.name} didn't match {self._matcher_name} in {timeout}s, "
f"last value {self._last_value!r}"
) from e
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def test_wait_for_value_with_value():
await signal.set("blah")

with pytest.raises(
TimeoutError,
asyncio.TimeoutError,
match="signal didn't match 'something' in 0.1s, last value 'blah'",
):
await wait_for_value(signal, "something", timeout=0.1)
Expand All @@ -263,7 +263,7 @@ def less_than_42(v):
return v < 42

with pytest.raises(
TimeoutError,
asyncio.TimeoutError,
match="signal didn't match less_than_42 in 0.1s, last value 45.8",
):
await wait_for_value(signal, less_than_42, timeout=0.1)
Expand Down
3 changes: 2 additions & 1 deletion tests/epics/adpilatus/test_pilatus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from typing import Awaitable, Callable
from unittest.mock import patch

Expand Down Expand Up @@ -84,7 +85,7 @@ async def trigger_and_complete():
"ophyd_async.epics.adpilatus._pilatus_controller.DEFAULT_TIMEOUT",
0.1,
):
with pytest.raises(TimeoutError):
with pytest.raises(asyncio.TimeoutError):
await _trigger(
test_adpilatus,
adpilatus.PilatusTriggerMode.internal,
Expand Down
3 changes: 2 additions & 1 deletion tests/fastcs/panda/test_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging
import os
from pathlib import Path
Expand Down Expand Up @@ -187,7 +188,7 @@ async def test_wait_for_index(mock_writer: PandaHDFWriter):
set_mock_value(mock_writer.panda_data_block.num_captured, 3)
await mock_writer.wait_for_index(3, timeout=1)
set_mock_value(mock_writer.panda_data_block.num_captured, 2)
with pytest.raises(TimeoutError):
with pytest.raises(asyncio.TimeoutError):
await mock_writer.wait_for_index(3, timeout=0.1)


Expand Down

0 comments on commit 965a4d7

Please sign in to comment.