test: add tests for setting simple XAS scans
This commit is contained in:
@@ -10,7 +10,7 @@ from ophyd.utils import LimitError
|
||||
from ophyd_devices.tests.utils import MockPV
|
||||
|
||||
# from bec_server.device_server.tests.utils import DMMock
|
||||
from debye_bec.devices.mo1_bragg import Mo1Bragg, MoveType
|
||||
from debye_bec.devices.mo1_bragg import Mo1Bragg, MoveType, ScanControlMode
|
||||
|
||||
# TODO move this function to ophyd_devices, it is duplicated in csaxs_bec and needed for other pluging repositories
|
||||
from debye_bec.devices.test_utils.utils import patch_dual_pvs
|
||||
@@ -39,8 +39,8 @@ def test_init(mock_bragg):
|
||||
|
||||
def test_check_value(mock_bragg):
|
||||
dev = mock_bragg
|
||||
dev.low_limit_energy._read_pv.mock_data = 0
|
||||
dev.high_limit_energy._read_pv.mock_data = 1
|
||||
dev.low_lim._read_pv.mock_data = 0
|
||||
dev.high_lim._read_pv.mock_data = 1
|
||||
dev.low_limit_angle._read_pv.mock_data = 10
|
||||
dev.high_limit_angle._read_pv.mock_data = 20
|
||||
# Check that limits are taken correctly from angle or energy
|
||||
@@ -70,24 +70,24 @@ def test_move_succeeds(mock_bragg):
|
||||
dev = mock_bragg
|
||||
dev.move_abs._read_pv.mock_data = 0
|
||||
# Move succeeds
|
||||
with mock.patch.object(dev.move_abs_done._read_pv, "mock_data", side_effect=[0, 1]):
|
||||
with mock.patch.object(dev.motor_is_moving._read_pv, "mock_data", side_effect=[0, 1]):
|
||||
status = dev.move(0.5)
|
||||
# Sleep needed for while loop in _move_and_finish
|
||||
time.sleep(0.5)
|
||||
assert status.done is True
|
||||
assert status.success is True
|
||||
assert dev.setpoint_abs_energy.get() == 0.5
|
||||
assert dev.setpoint.get() == 0.5
|
||||
assert dev.move_abs.get() == 1
|
||||
|
||||
|
||||
def test_stop_move(mock_bragg):
|
||||
dev = mock_bragg
|
||||
dev.move_abs._read_pv.mock_data = 0
|
||||
dev.move_abs_done._read_pv.mock_data = 0
|
||||
dev.motor_is_moving._read_pv.mock_data = 0
|
||||
# Move fails
|
||||
status = dev.move(0.5)
|
||||
assert status.done is False
|
||||
time.sleep(0.5)
|
||||
assert status.done is False
|
||||
assert dev._stopped == False
|
||||
dev.stop()
|
||||
time.sleep(0.5)
|
||||
@@ -111,3 +111,40 @@ def test_set_xtal(mock_bragg):
|
||||
assert dev.crystal.d_spacing_si111.get() == 3
|
||||
assert dev.crystal.d_spacing_si311.get() == 4
|
||||
assert dev.crystal.xtal_enum.get() == 1
|
||||
|
||||
|
||||
def test_setup_simple_xas_scan(mock_bragg):
|
||||
dev = mock_bragg
|
||||
dev.scan_control.scan_status._read_pv.mock_data = 1
|
||||
dev.setup_simple_xas_scan(low=0.5, high=1, scan_time=0.1, mode=0, scan_duration=10)
|
||||
|
||||
assert dev.scan_settings.xrd_enable_hi_enum.get() == False
|
||||
assert dev.scan_settings.xrd_enable_lo_enum.get() == False
|
||||
|
||||
assert dev.scan_settings.s_scan_energy_hi.get() == 1
|
||||
assert dev.scan_settings.s_scan_energy_lo.get() == 0.5
|
||||
assert dev.scan_settings.s_scan_scantime.get() == 0.1
|
||||
|
||||
assert dev.scan_control.scan_mode_enum.get() == ScanControlMode.SIMPLE
|
||||
assert dev.scan_control.scan_duration.get() == 10
|
||||
|
||||
dev.scan_control.scan_status._read_pv.mock_data = 0
|
||||
with pytest.raises(TimeoutError):
|
||||
dev.setup_simple_xas_scan(
|
||||
low=0.5, high=1, scan_time=0.1, mode=0, scan_duration=10, timeout=0.5
|
||||
)
|
||||
|
||||
|
||||
def test_kickoff_scan(mock_bragg):
|
||||
dev = mock_bragg
|
||||
dev.scan_control.scan_start_timer._read_pv.mock_data = 0
|
||||
dev.scan_control.scan_status._read_pv.mock_data = 1
|
||||
dev.setup_simple_xas_scan(low=0.5, high=1, scan_time=0.1, mode=0, scan_duration=10)
|
||||
# Start time mode
|
||||
dev.kickoff()
|
||||
assert dev.scan_control.scan_start_timer.get() == 1
|
||||
dev.scan_control.scan_start_infinite._read_pv.mock_data = 0
|
||||
# Start infinite mode
|
||||
dev.setup_simple_xas_scan(low=0.5, high=1, scan_time=0.1, mode=0, scan_duration=0)
|
||||
dev.kickoff()
|
||||
assert dev.scan_control.scan_start_infinite.get() == 1
|
||||
|
||||
Reference in New Issue
Block a user