Skip to content

Commit

Permalink
Merge pull request #1099 from tizayi/master
Browse files Browse the repository at this point in the history
BUG: isinstance calls property success before status object is done
  • Loading branch information
coretl committed Mar 24, 2023
2 parents 97c06f6 + 0fe84c8 commit 215bd0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ophyd/v2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def done(self) -> bool:

@property
def success(self) -> bool:
assert self.done, "Status has not completed yet"
if not self.done:
return False

try:
self.task.result()
except (Exception, asyncio.CancelledError):
Expand Down
14 changes: 13 additions & 1 deletion ophyd/v2/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
import re

import pytest
from bluesky.protocols import Status

from ophyd.v2.core import Signal
from ophyd.v2.core import AsyncStatus, Signal


class MySignal(Signal):
Expand All @@ -29,3 +31,13 @@ def test_signals_equality_raises():
match=re.escape("'>' not supported between instances of 'MySignal' and 'int'"),
):
s1 > 4


async def test_async_status_success():
st = AsyncStatus(asyncio.sleep(0.1))
assert isinstance(st, Status)
assert not st.done
assert not st.success
await st
assert st.done
assert st.success

0 comments on commit 215bd0a

Please sign in to comment.