-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6bc8cb
commit 59d44fe
Showing
5 changed files
with
134 additions
and
30 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,84 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from ophyd_async.core import ( | ||
DEFAULT_TIMEOUT, | ||
Device, | ||
DeviceCollector, | ||
DeviceVector, | ||
SignalRW, | ||
SignalX, | ||
) | ||
from ophyd_async.epics.pvi import fill_pvi_entries | ||
|
||
|
||
class Block1(Device): | ||
device_vector_signal_x: DeviceVector[SignalX] | ||
device_vector_signal_rw: DeviceVector[SignalRW[float]] | ||
signal_x: SignalX | ||
signal_rw: SignalRW[int] | ||
|
||
|
||
class Block2(Device): | ||
device_vector: DeviceVector[Block1] | ||
device: Block1 | ||
signal_x: SignalX | ||
signal_rw: SignalRW[int] | ||
|
||
|
||
class Block3(Device): | ||
device_vector: Optional[DeviceVector[Block2]] | ||
device: Block2 | ||
signal_device: Block1 | ||
signal_x: SignalX | ||
signal_rw: SignalRW[int] | ||
|
||
|
||
@pytest.fixture | ||
def pvi_test_device_t(): | ||
"""A fixture since pytest discourages init in test case classes""" | ||
|
||
class TestDevice(Block3, Device): | ||
def __init__(self, prefix: str, name: str = ""): | ||
self._prefix = prefix | ||
super().__init__(name) | ||
|
||
async def connect( | ||
self, sim: bool = False, timeout: float = DEFAULT_TIMEOUT | ||
) -> None: | ||
await fill_pvi_entries(self, self._prefix + "PVI", timeout=timeout, sim=sim) | ||
|
||
await super().connect(sim) | ||
|
||
yield TestDevice | ||
|
||
|
||
async def test_fill_pvi_entries_sim_mode(pvi_test_device_t): | ||
async with DeviceCollector(sim=True): | ||
test_device = pvi_test_device_t("PREFIX:") | ||
|
||
# device vectors are typed | ||
assert isinstance(test_device.device_vector[1], Block2) | ||
assert isinstance(test_device.device_vector[2], Block2) | ||
|
||
# elements of device vectors are typed recursively | ||
assert test_device.device_vector[1].signal_rw._backend.datatype is int | ||
assert isinstance(test_device.device_vector[1].device, Block1) | ||
assert test_device.device_vector[1].device.signal_rw._backend.datatype is int | ||
assert ( | ||
test_device.device_vector[1].device.device_vector_signal_rw[1]._backend.datatype | ||
is float | ||
) | ||
|
||
# top level blocks are typed | ||
assert isinstance(test_device.signal_device, Block1) | ||
assert isinstance(test_device.device, Block2) | ||
|
||
# elements of top level blocks are typed recursively | ||
assert test_device.device.signal_rw._backend.datatype is int | ||
assert isinstance(test_device.device.device, Block1) | ||
assert test_device.device.device.signal_rw._backend.datatype is int | ||
|
||
# top level signals are typed | ||
assert test_device.signal_rw._backend.datatype is int |
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