-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made
ensure_connected
fail properly (#421)
* adjusted for use with bluesky/bluesky#1758 * added a test for `ensure_connected` where the device isnt connected * allowed `ensure_connected` to vacuously succeed if no devices are passed in
- Loading branch information
1 parent
0f67e37
commit 0269697
Showing
4 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
from ophyd_async.core import Device, NotConnected | ||
from ophyd_async.core.mock_signal_backend import MockSignalBackend | ||
from ophyd_async.core.signal import SignalRW | ||
from ophyd_async.epics.signal import epics_signal_rw | ||
from ophyd_async.plan_stubs import ensure_connected | ||
|
||
|
||
def test_ensure_connected(RE): | ||
class MyDevice(Device): | ||
def __init__(self, prefix: str, name=""): | ||
self.signal = epics_signal_rw(str, f"pva://{prefix}:SIGNAL") | ||
super().__init__(name=name) | ||
|
||
device1 = MyDevice("PREFIX1", name="device1") | ||
|
||
def connect(): | ||
yield from ensure_connected(device1, mock=False, timeout=0.1) | ||
|
||
with pytest.raises( | ||
NotConnected, | ||
match="device1: NotConnected:\n signal: NotConnected: pva://PREFIX1:SIGNAL", | ||
): | ||
RE(connect()) | ||
|
||
assert isinstance(device1.signal._connect_task.exception(), NotConnected) | ||
|
||
device1.signal = SignalRW(MockSignalBackend(str)) | ||
RE(connect()) | ||
assert device1.signal._connect_task.exception() is None | ||
|
||
device2 = MyDevice("PREFIX2", name="device2") | ||
|
||
def connect_with_mocking(): | ||
assert device2.signal._connect_task is None | ||
yield from ensure_connected(device2, mock=True, timeout=0.1) | ||
assert device2.signal._connect_task.done() | ||
|
||
RE(connect_with_mocking()) |