Skip to content

Commit

Permalink
(#117) (#45) add a bit more to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Apr 9, 2024
1 parent a4bdf2d commit dce34dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ophyd_async/core/async_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _run_callbacks(self, task: asyncio.Task):

def exception(self, timeout: float | None = 0.0) -> BaseException | None:
if timeout != 0.0:
raise Exception(
raise ValueError(
"cannot honour any timeout other than 0 in an asynchronous function"
)
if self.task.done():
Expand Down
17 changes: 16 additions & 1 deletion tests/core/test_async_status_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@ def __call__(

class ASTestDevice(StandardReadable, Movable):
def __init__(self, name: str = "") -> None:
self._staged: bool = False
self.sig = SignalR(backend=SimSignalBackend(datatype=int, source="sim:TEST"))
super().__init__(name)

@AsyncStatus.wrap
async def stage(self):
self._staged = True
await asyncio.sleep(0.01)


class ASTestDeviceSingleSet(ASTestDevice):
@AsyncStatus.wrap
async def set(self, val):
assert self._staged
await asyncio.sleep(0.01)
self.sig._backend._set_value(val) # type: ignore

Expand All @@ -86,6 +93,7 @@ def __init__(

@WatchableAsyncStatus.wrap
async def set(self, val) -> AsyncIterator:
assert self._staged
self._initial = await self.sig.get_value()
for point in self.values:
await asyncio.sleep(0.01)
Expand Down Expand Up @@ -156,9 +164,14 @@ async def coro_status(x: int, y: int, *, z=False):
loop.run_until_complete(do_test())


async def test_asyncstatus_wraps_set(RE):
async def test_asyncstatus_wraps_both_stage_and_set(RE):
td = ASTestDeviceSingleSet()
await td.connect()
with pytest.raises(AssertionError):
st = td.set(5)
assert isinstance(st, AsyncStatus)
await st
await td.stage()
st = td.set(5)
assert isinstance(st, AsyncStatus)
await st
Expand All @@ -170,6 +183,7 @@ async def test_asyncstatus_wraps_set(RE):
async def test_asyncstatus_wraps_set_iterator_with_class_or_func_watcher(RE):
td = ASTestDeviceIteratorSet()
await td.connect()
await td.stage()
st = td.set(6)
updates = []

Expand All @@ -186,6 +200,7 @@ async def test_asyncstatus_wraps_set_iterator_with_class_or_func_watcher(RE):
async def test_asyncstatus_wraps_failing_set_iterator_(RE):
td = ASTestDeviceIteratorSet(values=[1, 2, 3], complete_set=False)
await td.connect()
await td.stage()
st = td.set(6)
updates = []

Expand Down

0 comments on commit dce34dc

Please sign in to comment.