Skip to content

Commit

Permalink
Merge pull request #1140 from DominicOram/master
Browse files Browse the repository at this point in the history
ENH: Add __contains__ to AndStatus
  • Loading branch information
DominicOram authored Sep 8, 2023
2 parents cd1e43c + f963880 commit 4fbe8c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ophyd/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,16 @@ def __str__(self):
"".format(self.__class__.__name__, self)
)

def __contains__(self, status: StatusBase) -> bool:
for child in [self.left, self.right]:
if child == status:
return True
if isinstance(child, AndStatus):
if status in child:
return True

return False


class Status(StatusBase):
"""
Expand Down
11 changes: 11 additions & 0 deletions ophyd/tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def test_and():
# make sure deep recursion works
st4 = st1 & st3
st5 = st3 & st4

assert st1 in st3
assert st1 in st4
assert st1 in st5
assert st2 in st4
assert st2 in st5

unused_status = StatusBase()
assert unused_status not in st3
unused_status.set_finished()

state1, cb1 = _setup_state_and_cb()
state2, cb2 = _setup_state_and_cb()
state3, cb3 = _setup_state_and_cb()
Expand Down

0 comments on commit 4fbe8c1

Please sign in to comment.