tests: fix test cases after refactoring
All checks were successful
CI for debye_bec / test (pull_request) Successful in 1m7s
CI for debye_bec / test (push) Successful in 1m5s

This commit was merged in pull request #60.
This commit is contained in:
2025-09-17 07:37:44 +02:00
parent 190eae2c3f
commit c70088e7bc
3 changed files with 43 additions and 24 deletions

View File

@@ -132,10 +132,12 @@ def test_set_trig_settings(mock_bragg):
dev.set_trig_settings(
enable_low=True,
enable_high=False,
exp_time_high=0.1,
exp_time_low=0.01,
break_time_high=0.1,
break_time_low=0.01,
cycle_low=1,
cycle_high=3,
exp_time=0.5,
n_of_trigger=7,
)
assert dev.scan_settings.trig_ena_lo_enum.get() == True
assert dev.scan_settings.trig_ena_hi_enum.get() == False
@@ -143,6 +145,8 @@ def test_set_trig_settings(mock_bragg):
assert dev.scan_settings.trig_every_n_hi.get() == 3
assert dev.scan_settings.trig_time_lo.get() == 0.01
assert dev.scan_settings.trig_time_hi.get() == 0.1
assert dev.trigger_settings.xrd_trig_period.get() == 0.5
assert dev.trigger_settings.xrd_n_of_trig.get() == 7
def test_set_control_settings(mock_bragg):

View File

@@ -35,13 +35,18 @@ if TYPE_CHECKING: # pragma no cover
@pytest.fixture(
scope="function",
params=[(0.1, 1, 1, "line_scan"), (0.2, 2, 2, "time_scan"), (0.5, 5, 5, "xas_advanced_scan")],
params=[
(0.1, 1, 1, "line_scan", "step"),
(0.2, 2, 2, "time_scan", "step"),
(0.5, 5, 5, "xas_advanced_scan", "fly"),
],
)
def mock_scan_info(request, tmpdir):
exp_time, frames_per_trigger, num_points, scan_name = request.param
exp_time, frames_per_trigger, num_points, scan_name, scan_type = request.param
scan_info = ScanStatusMessage(
scan_id="test_id",
status="open",
scan_type=scan_type,
scan_number=1,
scan_parameters={
"exp_time": exp_time,
@@ -71,7 +76,10 @@ def pilatus(mock_scan_info) -> Generator[Pilatus, None, None]:
try:
yield dev
finally:
dev.destroy()
try:
dev.on_destroy()
except ophyd.utils.DestroyedError:
pass
# TODO figure out how to test as set calls on the PV below seem to break it..
@@ -102,7 +110,7 @@ def test_pilatus_on_destroy(pilatus):
with mock.patch.object(pilatus, "on_stop") as mock_on_stop:
pilatus.destroy()
assert mock_on_stop.call_count == 1
assert pilatus._poll_thread_stop_event.is_set()
assert pilatus._poll_thread_kill_event.is_set()
def test_pilatus_on_failure_callback(pilatus):
@@ -119,7 +127,8 @@ def test_pilatus_on_failure_callback(pilatus):
def test_pilatus_on_pre_scan(pilatus):
"""Test the on_pre_scan logic of the Pilatus detector."""
if pilatus.scan_info.msg.scan_name.startswith("xas"):
scan_msg = pilatus.scan_info.msg
if scan_msg.scan_type != "step" and scan_msg.scan_name not in pilatus.xas_xrd_scan_names:
assert pilatus.on_pre_scan() is None
return
pilatus.cam.acquire._read_pv.mock_data = ACQUIREMODE.DONE.value
@@ -135,7 +144,8 @@ def test_pilatus_on_pre_scan(pilatus):
def test_pilatus_on_trigger(pilatus):
"""test on trigger logic of the Pilatus detector."""
if pilatus.scan_info.msg.scan_name.startswith("xas"):
scan_msg = pilatus.scan_info.msg
if scan_msg.scan_type != "step" and scan_msg.scan_name not in pilatus.xas_xrd_scan_names:
status = pilatus.trigger()
assert status.done is True
assert status.success is True
@@ -169,10 +179,12 @@ def test_pilatus_on_trigger_cancel_on_stop(pilatus):
def test_pilatus_on_complete(pilatus):
"""Test the on_complete logic of the Pilatus detector."""
if pilatus.scan_info.msg.scan_name.startswith("xas"):
status = pilatus.complete()
assert status.done is True
assert status.success is True
# TODO add test cases for xas scans
# status = pilatus.complete()
# assert status.done is True
# assert status.success is True
return
# Check in addition that the file event is set properly, once with if it works, and once if not (i.e. when cancelled)
for success in [True, False]:
@@ -191,6 +203,7 @@ def test_pilatus_on_complete(pilatus):
)
pilatus.hdf.num_captured._read_pv.mock_data = num_images - 1
# Call on complete
pilatus.n_images = num_images
status = pilatus.complete()
# Should not be finished
assert status.done is False
@@ -265,7 +278,8 @@ def test_pilatus_on_complete(pilatus):
def test_pilatus_on_stage_raises_low_exp_time(pilatus):
"""Test that on_stage raises a ValueError if the exposure time is too low."""
pilatus.scan_info.msg.scan_parameters["exp_time"] = 0.09
if pilatus.scan_info.msg.scan_name.startswith("xas"):
scan_msg = pilatus.scan_info.msg
if scan_msg.scan_type != "step" and scan_msg.scan_name not in pilatus.xas_xrd_scan_names:
return
with pytest.raises(ValueError):
pilatus.on_stage()

View File

@@ -141,17 +141,18 @@ def test_xas_simple_scan_with_xrd(scan_assembler, ScanStubStatusMock):
stop=5,
scan_time=1,
scan_duration=10,
xrd_enable_low=True,
num_trigger_low=1,
exp_time_low=1,
break_enable_low=True,
break_time_low=1,
cycle_low=1,
xrd_enable_high=True,
num_trigger_high=2,
exp_time_high=3,
break_enable_high=True,
break_time_high=2,
exp_time=1,
n_of_trigger=1,
cycle_high=4,
)
request.device_manager.add_device("nidaq")
reference_commands = get_instructions(request, ScanStubStatusMock)
# TODO #64 based on creating this ScanStatusMessage, we should test the logic of stage/kickoff/complete/unstage in Pilatus and mo1Bragg
assert reference_commands == [
None,
@@ -339,13 +340,13 @@ def test_xas_advanced_scan_with_xrd(scan_assembler, ScanStubStatusMock):
scan_duration=10,
p_kink=50,
e_kink=8500,
xrd_enable_low=True,
num_trigger_low=1,
exp_time_low=1,
break_enable_low=True,
break_time_low=1,
cycle_low=1,
xrd_enable_high=True,
num_trigger_high=2,
exp_time_high=3,
break_enable_high=True,
break_time_high=2,
exp_time=1,
n_of_trigger=1,
cycle_high=4,
)
request.device_manager.add_device("nidaq")