Skip to content

Commit

Permalink
Merge pull request #104 from bluesky/103_improve_asyncstatus_message
Browse files Browse the repository at this point in the history
#103 add task and exception info to AsyncStatus message
  • Loading branch information
dperl-dls authored Jan 30, 2024
2 parents aeb49f6 + 6b05cb5 commit 4db6f6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/ophyd_async/core/async_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def wrap_f(self) -> AsyncStatus:

def __repr__(self) -> str:
if self.done:
if self.exception() is not None:
status = "errored"
if e := self.exception():
status = f"errored: {repr(e)}"
else:
status = "done"
else:
status = "pending"
return f"<{type(self).__name__} {status}>"
return f"<{type(self).__name__}, task: {self.task.get_coro()}, {status}>"

__str__ = __repr__
17 changes: 13 additions & 4 deletions tests/core/test_async_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,30 @@ async def test_async_status_str_for_normal_coroutine(normal_coroutine):
normal_task = asyncio.Task(normal_coroutine())
status = AsyncStatus(normal_task)

assert str(status) == "<AsyncStatus pending>"
for comment_chunk in ["<AsyncStatus,", "normal_coroutine", "pending>"]:
assert comment_chunk in str(status)
await status

assert str(status) == "<AsyncStatus done>"
for comment_chunk in ["<AsyncStatus,", "normal_coroutine", "done>"]:
assert comment_chunk in str(status)


async def test_async_status_str_for_failing_coroutine(failing_coroutine):
failing_task = asyncio.Task(failing_coroutine())
status = AsyncStatus(failing_task)

assert str(status) == "<AsyncStatus pending>"
for comment_chunk in ["<AsyncStatus,", "failing_coroutine", "pending>"]:
assert comment_chunk in str(status)
with pytest.raises(ValueError):
await status

assert str(status) == "<AsyncStatus errored>"
for comment_chunk in [
"<AsyncStatus,",
"failing_coroutine",
"errored:",
"ValueError",
]:
assert comment_chunk in str(status)


class FailingMovable(Movable, Device):
Expand Down

0 comments on commit 4db6f6e

Please sign in to comment.