Skip to content

Commit

Permalink
#103 add task and exception info to AsyncStatus message
Browse files Browse the repository at this point in the history
  • Loading branch information
d-perl committed Jan 17, 2024
1 parent aeb49f6 commit dadf8d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 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__
10 changes: 10 additions & 0 deletions tests/core/test_async_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ async def test_async_status_propagates_cancelled_error(normal_coroutine):

assert type(status.exception()) == asyncio.CancelledError

async def test_async_status_repr_includes_task_and_exception_info(failing_coroutine):
status = AsyncStatus(failing_coroutine())
assert status.exception() is None

with pytest.raises(ValueError):
await status

assert "failing_coroutine" in str(status)
assert "ValueError" in str(status)


async def test_async_status_has_no_exception_if_coroutine_successful(normal_coroutine):
status = AsyncStatus(normal_coroutine())
Expand Down

0 comments on commit dadf8d6

Please sign in to comment.