Skip to content

Commit 182780b

Browse files
authored
Made set_and_wait_for_other_value still still raise a TimeoutError if there is no __name__ on the matcher (#1123)
* Made set_and_wait_for_other_value still still raise a TimeoutError if there is no __name__ on the matcher * Additions from review
1 parent e86f971 commit 182780b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/ophyd_async/core/_signal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,10 @@ async def _wait_for_value():
639639
if wait_for_set_completion:
640640
await status
641641
except TimeoutError as exc:
642+
matcher_name = getattr(matcher, "__name__", f"<{type(matcher).__name__}>")
642643
raise TimeoutError(
643644
f"{match_signal.name} value didn't match value from"
644-
f" {matcher.__name__}() in {timeout}s"
645+
f" {matcher_name}() in {timeout}s"
645646
) from exc
646647

647648
return status

tests/unit_tests/core/test_signal.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import time
55
from asyncio import Event
6+
from functools import partial
67
from typing import Any
78
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, call
89

@@ -334,6 +335,36 @@ def _equals_x(value, x):
334335
)
335336

336337

338+
async def test_given_callable_has_no_name_then_matcher_still_gives_timeout_error():
339+
set_signal = epics_signal_rw(int, "pva://signal")
340+
match_signal = epics_signal_rw(int, "pva://match_signal")
341+
342+
await set_signal.connect(mock=True)
343+
await match_signal.connect(mock=True)
344+
345+
class NoNameCallable:
346+
def __call__(self, val):
347+
return val == 20
348+
349+
with pytest.raises(asyncio.TimeoutError):
350+
await set_and_wait_for_other_value(
351+
set_signal, 20, match_signal, NoNameCallable(), timeout=0.01
352+
)
353+
354+
355+
async def test_partial_matcher_still_gives_timeout_error():
356+
set_signal = epics_signal_rw(int, "pva://signal")
357+
match_signal = epics_signal_rw(int, "pva://match_signal")
358+
359+
await set_signal.connect(mock=True)
360+
await match_signal.connect(mock=True)
361+
362+
with pytest.raises(asyncio.TimeoutError):
363+
await set_and_wait_for_other_value(
364+
set_signal, 20, match_signal, partial(lambda x, y: x == y, 20), timeout=0.01
365+
)
366+
367+
337368
async def test_wait_for_value_with_value():
338369
signal = epics_signal_rw(str, read_pv="pva://signal", name="signal")
339370
await signal.connect(mock=True)

0 commit comments

Comments
 (0)