Skip to content

Commit

Permalink
DiamondLightSource/hyperion#685 fix other rotation tests for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
d-perl committed Mar 8, 2024
1 parent 47b2252 commit 7d5de5a
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions tests/unit_tests/experiment_plans/test_rotation_scan_plan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from functools import partial
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Callable
from unittest.mock import DEFAULT, MagicMock, call, patch

import pytest
Expand All @@ -11,6 +11,7 @@
from ophyd.status import Status

from hyperion.experiment_plans.rotation_scan_plan import (
RotationMotionProfile,
RotationScanComposite,
calculate_motion_profile,
rotation_scan,
Expand All @@ -34,17 +35,15 @@ def do_rotation_main_plan_for_tests(
run_eng: RunEngine,
expt_params: RotationInternalParameters,
devices: RotationScanComposite,
plan=rotation_scan_plan,
motion_values: RotationMotionProfile,
plan: Callable = rotation_scan_plan,
):
with patch(
"bluesky.preprocessors.__read_and_stash_a_motor",
fake_read,
):
run_eng(
plan(
devices,
expt_params,
),
plan(devices, expt_params, motion_values),
)


Expand All @@ -54,16 +53,31 @@ def run_full_rotation_plan(
test_rotation_params: RotationInternalParameters,
fake_create_rotation_devices: RotationScanComposite,
):
do_rotation_main_plan_for_tests(
RE, test_rotation_params, fake_create_rotation_devices, rotation_scan
with patch(
"bluesky.preprocessors.__read_and_stash_a_motor",
fake_read,
):
RE(
rotation_scan(fake_create_rotation_devices, test_rotation_params),
)
return fake_create_rotation_devices


@pytest.fixture
def motion_values(test_rotation_params: RotationInternalParameters):
return calculate_motion_profile(
test_rotation_params.hyperion_params.detector_params,
test_rotation_params.experiment_params,
0.005,
222,
)
return fake_create_rotation_devices


def setup_and_run_rotation_plan_for_tests(
RE: RunEngine,
test_params: RotationInternalParameters,
fake_create_rotation_devices: RotationScanComposite,
motion_values,
):
smargon = fake_create_rotation_devices.smargon

Expand All @@ -78,9 +92,7 @@ def side_set_w_return(obj, *args):

with patch("bluesky.plan_stubs.wait", autospec=True):
do_rotation_main_plan_for_tests(
RE,
test_params,
fake_create_rotation_devices,
RE, test_params, fake_create_rotation_devices, motion_values
)

return {
Expand All @@ -96,11 +108,10 @@ def setup_and_run_rotation_plan_for_tests_standard(
RE: RunEngine,
test_rotation_params: RotationInternalParameters,
fake_create_rotation_devices: RotationScanComposite,
motion_values,
):
return setup_and_run_rotation_plan_for_tests(
RE,
test_rotation_params,
fake_create_rotation_devices,
RE, test_rotation_params, fake_create_rotation_devices, motion_values
)


Expand All @@ -109,11 +120,10 @@ def setup_and_run_rotation_plan_for_tests_nomove(
RE: RunEngine,
test_rotation_params_nomove: RotationInternalParameters,
fake_create_rotation_devices: RotationScanComposite,
motion_values,
):
return setup_and_run_rotation_plan_for_tests(
RE,
test_rotation_params_nomove,
fake_create_rotation_devices,
RE, test_rotation_params_nomove, fake_create_rotation_devices, motion_values
)


Expand All @@ -126,6 +136,7 @@ def test_rotation_scan_calculations(test_rotation_params: RotationInternalParame
test_rotation_params.hyperion_params.detector_params,
test_rotation_params.experiment_params,
0.005, # time for acceleration
224,
)

assert motion_values.direction == -1
Expand Down Expand Up @@ -250,6 +261,7 @@ def test_cleanup_happens(
RE: RunEngine,
test_rotation_params,
fake_create_rotation_devices: RotationScanComposite,
motion_values: RotationMotionProfile,
):

class MyTestException(Exception):
Expand All @@ -264,18 +276,12 @@ class MyTestException(Exception):
with pytest.raises(MyTestException):
RE(
rotation_scan_plan(
fake_create_rotation_devices,
test_rotation_params,
fake_create_rotation_devices, test_rotation_params, motion_values
)
)
cleanup_plan.assert_not_called()
# check that failure is handled in composite plan
with pytest.raises(MyTestException) as exc:
RE(
rotation_scan(
fake_create_rotation_devices,
test_rotation_params,
)
)
RE(rotation_scan(fake_create_rotation_devices, test_rotation_params))
assert "Experiment fails because this is a test" in exc.value.args[0]
cleanup_plan.assert_called_once()

0 comments on commit 7d5de5a

Please sign in to comment.