mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-02-03 22:08:39 +01:00
tests: add tests for shutter
This commit is contained in:
@@ -21,6 +21,8 @@ def _is_state(state: int | str):
|
|||||||
def _cb(*, old_value, value, **kwargs):
|
def _cb(*, old_value, value, **kwargs):
|
||||||
return value == state
|
return value == state
|
||||||
|
|
||||||
|
return _cb
|
||||||
|
|
||||||
|
|
||||||
class Shutter(PSIDeviceBase):
|
class Shutter(PSIDeviceBase):
|
||||||
"""A generic optics shutter device, for IOCs with the format '[BEAMLINE]-EH1-PSYS:SH-[A/B]-'
|
"""A generic optics shutter device, for IOCs with the format '[BEAMLINE]-EH1-PSYS:SH-[A/B]-'
|
||||||
@@ -39,6 +41,9 @@ class Shutter(PSIDeviceBase):
|
|||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
shutter = Shutter(name="shutter", prefix="X10SA-EH1-PSYS:SH-A-")
|
shutter = Shutter(name="shutter", prefix="X10SA-EH1-PSYS:SH-A-")
|
||||||
|
if shutter.enabled == ShutterEnabled.ENABLED:
|
||||||
|
st = shutter.open()
|
||||||
|
st.wait()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
41
tests/test_shutter.py
Normal file
41
tests/test_shutter.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from ophyd_devices.devices.optics_shutter import Shutter, ShutterEnabled, ShutterOpenState
|
||||||
|
from ophyd_devices.tests.utils import patched_device
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def mock_shutter():
|
||||||
|
with patched_device(Shutter, name="shutter", prefix="X10SA-EH1-PSYS:SH-A-") as shutter:
|
||||||
|
yield shutter
|
||||||
|
|
||||||
|
|
||||||
|
def test_shutter_open(mock_shutter):
|
||||||
|
mock_shutter.is_enabled._read_pv.mock_data = ShutterEnabled.ENABLED.value
|
||||||
|
mock_shutter.is_open._read_pv.mock_data = ShutterOpenState.CLOSED.value
|
||||||
|
st = mock_shutter.open()
|
||||||
|
assert not st.done
|
||||||
|
mock_shutter.is_open._read_pv.mock_data = ShutterOpenState.OPEN.value
|
||||||
|
assert st.done
|
||||||
|
|
||||||
|
|
||||||
|
def test_shutter_close(mock_shutter):
|
||||||
|
mock_shutter.is_enabled._read_pv.mock_data = ShutterEnabled.ENABLED.value
|
||||||
|
mock_shutter.is_open._read_pv.mock_data = ShutterOpenState.OPEN.value
|
||||||
|
st = mock_shutter.close()
|
||||||
|
assert not st.done
|
||||||
|
mock_shutter.is_open._read_pv.mock_data = ShutterOpenState.CLOSED.value
|
||||||
|
assert st.done
|
||||||
|
|
||||||
|
|
||||||
|
def test_shutter_not_enabled(mock_shutter):
|
||||||
|
with pytest.raises(RuntimeError) as e:
|
||||||
|
mock_shutter.open()
|
||||||
|
assert e.match("The shutter is disabled!")
|
||||||
|
|
||||||
|
|
||||||
|
def test_shutter_status(mock_shutter):
|
||||||
|
mock_shutter.is_open._read_pv.mock_data = ShutterOpenState.OPEN.value
|
||||||
|
assert mock_shutter.status() == ShutterOpenState.OPEN.value
|
||||||
|
mock_shutter.is_open._read_pv.mock_data = ShutterOpenState.CLOSED.value
|
||||||
|
assert mock_shutter.status() == ShutterOpenState.CLOSED.value
|
||||||
Reference in New Issue
Block a user