Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no op status #540

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ophyd_async/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
)
from ._signal_backend import RuntimeSubsetEnum, SignalBackend, SubsetEnum
from ._soft_signal_backend import SignalMetadata, SoftSignalBackend
from ._status import AsyncStatus, WatchableAsyncStatus
from ._status import AsyncStatus, WatchableAsyncStatus, completed_status
from ._utils import (
DEFAULT_TIMEOUT,
CalculatableTimeout,
Expand Down Expand Up @@ -158,4 +158,5 @@
"get_unique",
"in_micros",
"wait_for_connection",
"completed_status",
]
18 changes: 17 additions & 1 deletion src/ophyd_async/core/_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import functools
import time
from dataclasses import asdict, replace
from typing import AsyncIterator, Awaitable, Callable, Generic, Type, TypeVar, cast
from typing import (
AsyncIterator,
Awaitable,
Callable,
Generic,
Optional,
Type,
TypeVar,
cast,
)

from bluesky.protocols import Status

Expand Down Expand Up @@ -132,3 +141,10 @@ def wrap_f(*args: P.args, **kwargs: P.kwargs) -> WAS:
return cls(f(*args, **kwargs))

return cast(Callable[P, WAS], wrap_f)


@AsyncStatus.wrap
async def completed_status(exception: Optional[Exception] = None):
if exception:
raise exception
return None
8 changes: 7 additions & 1 deletion tests/core/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bluesky.protocols import Movable, Status
from bluesky.utils import FailedStatus

from ophyd_async.core import AsyncStatus, Device
from ophyd_async.core import AsyncStatus, Device, completed_status


async def test_async_status_success():
Expand Down Expand Up @@ -188,3 +188,9 @@ async def coro_status(x: int, y: int, *, z=False):
assert test_result == 12

loop.run_until_complete(do_test())


async def test_completed_status():
with pytest.raises(ValueError):
await completed_status(ValueError())
await completed_status()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could: assert the completed status has .success is True etc.