mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2025-06-06 03:40:41 +02:00
test(psi-device-base): enhance PSIDeviceBase tests with additional user method hooks
This commit is contained in:
parent
a7bffb8e3a
commit
0cb64d1ea8
@ -1,13 +1,26 @@
|
||||
"""Module for testing the PSIDeviceBase class."""
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from ophyd import Device
|
||||
from ophyd.status import StatusBase
|
||||
|
||||
from ophyd_devices.interfaces.base_classes.psi_device_base import DeviceStoppedError, PSIDeviceBase
|
||||
from ophyd_devices.sim.sim_positioner import SimPositioner
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
# pylint: disable=protected-access
|
||||
|
||||
|
||||
class SimPositionerDevice(PSIDeviceBase, SimPositioner):
|
||||
"""Simulated Positioner Device with PSI Device Base"""
|
||||
|
||||
|
||||
class SimDevice(PSIDeviceBase, Device):
|
||||
"""Test Device with ohyd.Device as base class"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def device():
|
||||
"""Fixture for Device"""
|
||||
@ -47,3 +60,71 @@ def test_psi_device_base_wait_for_signals(device):
|
||||
|
||||
# Any signal is True
|
||||
assert device.wait_for_condition(check_any_conditions, timeout=1) is True
|
||||
|
||||
|
||||
def test_psi_device_base_init_with_device_manager():
|
||||
"""Test init with device manager"""
|
||||
dm = mock.MagicMock()
|
||||
device = SimPositionerDevice(name="device", device_manager=dm)
|
||||
assert device.device_manager is dm
|
||||
device2 = SimDevice(name="device2", device_manager=dm)
|
||||
assert getattr(device2, "device_manager", None) is None
|
||||
|
||||
|
||||
def test_on_stage_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_stage") as mock_on_stage:
|
||||
res = device.stage()
|
||||
if not isinstance(res, StatusBase):
|
||||
assert isinstance(res, list) is True
|
||||
mock_on_stage.assert_called_once()
|
||||
|
||||
|
||||
def test_on_unstage_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_unstage") as mock_on_unstage:
|
||||
res = device.unstage()
|
||||
if not isinstance(res, StatusBase):
|
||||
assert isinstance(res, list) is True
|
||||
mock_on_unstage.assert_called_once()
|
||||
|
||||
|
||||
def test_on_complete_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_complete") as mock_on_complete:
|
||||
status = device.complete()
|
||||
assert isinstance(status, StatusBase) is True
|
||||
mock_on_complete.assert_called_once()
|
||||
|
||||
|
||||
def test_on_kickoff_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_kickoff") as mock_on_kickoff:
|
||||
status = device.kickoff()
|
||||
assert isinstance(status, StatusBase) is True
|
||||
mock_on_kickoff.assert_called_once()
|
||||
|
||||
|
||||
def test_on_trigger_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_trigger") as mock_on_trigger:
|
||||
mock_on_trigger.return_value = None
|
||||
status = device.trigger()
|
||||
assert isinstance(status, StatusBase) is True
|
||||
mock_on_trigger.assert_called_once()
|
||||
|
||||
|
||||
def test_on_pre_scan_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_pre_scan") as mock_on_pre_scan:
|
||||
mock_on_pre_scan.return_value = None
|
||||
status = device.pre_scan()
|
||||
assert status is None
|
||||
mock_on_pre_scan.assert_called_once()
|
||||
|
||||
|
||||
def test_on_stop_hook(device):
|
||||
"""Test user method hooks"""
|
||||
with mock.patch.object(device, "on_stop") as mock_on_stop:
|
||||
device.stop()
|
||||
mock_on_stop.assert_called_once()
|
||||
|
Loading…
x
Reference in New Issue
Block a user