104 lines
3.1 KiB
Python
104 lines
3.1 KiB
Python
"""Tests for Falcon device."""
|
|
|
|
import threading
|
|
from unittest import mock
|
|
|
|
import ophyd
|
|
import pytest
|
|
from ophyd_devices.tests.utils import MockPV, patch_dual_pvs
|
|
|
|
from superxas_bec.devices.falcon import FalconAcquiringStatus, FalconSuperXAS
|
|
|
|
# pylint: disable=protected-access
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def falcon():
|
|
"""Trigger device with mocked EPICS PVs."""
|
|
name = "falcon"
|
|
prefix = "X10DA-SITORO:"
|
|
with mock.patch.object(ophyd, "cl") as mock_cl:
|
|
mock_cl.get_pv = MockPV
|
|
mock_cl.thread_class = threading.Thread
|
|
dev = FalconSuperXAS(name=name, prefix=prefix)
|
|
patch_dual_pvs(dev)
|
|
yield dev
|
|
|
|
|
|
def test_devices_falcon(falcon):
|
|
"""Test init and on_connected methods of Falcon device"""
|
|
|
|
assert falcon.prefix == "X10DA-SITORO:"
|
|
assert falcon.name == "falcon"
|
|
assert falcon._pv_timeout == 1
|
|
falcon.on_connected()
|
|
|
|
|
|
def test_devices_falcon_stage(falcon):
|
|
"""Test on_stage method of Falcon device"""
|
|
|
|
falcon.collect_mode.put(1)
|
|
falcon.preset_real_time.put(1)
|
|
falcon.stop_all.put(0)
|
|
falcon.acquiring.put(FalconAcquiringStatus.DONE)
|
|
# Should resolve with that status
|
|
falcon.on_stage()
|
|
assert falcon.collect_mode.get() == 0
|
|
assert falcon.preset_real_time.get() == 0
|
|
assert falcon.stop_all.get() == 1
|
|
# Should timeout
|
|
falcon.acquiring.put(FalconAcquiringStatus.ACQUIRING)
|
|
falcon._pv_timeout = 0.1
|
|
with pytest.raises(TimeoutError):
|
|
falcon.on_stage()
|
|
|
|
|
|
def test_devices_falcon_unstage(falcon):
|
|
"""Test on_unstage method of Falcon device"""
|
|
|
|
falcon.stop_all.put(0)
|
|
falcon.erase_all.put(0)
|
|
falcon.acquiring.put(FalconAcquiringStatus.DONE)
|
|
# Should resolve with that status
|
|
falcon.on_unstage()
|
|
assert falcon.stop_all.get() == 1
|
|
assert falcon.erase_all.get() == 1
|
|
# Should timeout
|
|
falcon.acquiring.put(FalconAcquiringStatus.ACQUIRING)
|
|
falcon._pv_timeout = 0.1
|
|
with pytest.raises(TimeoutError):
|
|
falcon.on_unstage()
|
|
|
|
|
|
def test_devices_falcon_stop(falcon):
|
|
"""Test on_stop method of Falcon device"""
|
|
assert falcon.stopped is False
|
|
falcon.stop_all.put(0)
|
|
falcon.stop()
|
|
assert falcon.stopped is True
|
|
assert falcon.stop_all.get() == 1
|
|
|
|
|
|
def test_devices_falcon_stop_erase_and_wait_for_acquiring(falcon):
|
|
"""
|
|
Test _stop_erase_and_wait_for_acquiring method of Falcon device.
|
|
|
|
This method is called by the trigger card when the Falcon needs to be reset, and
|
|
placed in a state where it can receive a trigger again
|
|
"""
|
|
# Set initial values to different states
|
|
falcon.stop_all.put(0)
|
|
falcon.erase_start.put(0)
|
|
|
|
falcon.acquiring.put(FalconAcquiringStatus.ACQUIRING)
|
|
# If falcon status is acquiring, it should call stop_all
|
|
status = falcon._stop_erase_and_wait_for_acquiring()
|
|
assert falcon.stop_all.get() == 1
|
|
assert falcon.erase_start.get() == 1
|
|
# The status resolved once it sees acquiring change from DONE to ACQUIRING
|
|
assert status.done is False
|
|
falcon.acquiring.put(FalconAcquiringStatus.DONE)
|
|
falcon.acquiring.set(FalconAcquiringStatus.ACQUIRING).wait()
|
|
assert status.done is True
|