From bb6a762e232c19074c6777a0ce4bf60c5ba029de Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Thu, 9 Nov 2023 11:02:25 +0000 Subject: [PATCH] (#794) Center stub offsets after an XRC also adds tests --- setup.cfg | 2 +- .../flyscan_xray_centre_plan.py | 4 ++-- src/hyperion/experiment_plans/tests/conftest.py | 6 ++++++ .../tests/test_flyscan_xray_centre_plan.py | 17 +++++++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index 1c87b8622..95f20fff5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,7 +36,7 @@ install_requires = xarray doct databroker - dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@b58451b5902db75b9d7cf1c40740bdeac3e53348 + dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@f5e79547b3a94ddb54a81cdc6205f244a2be80ea pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774 scipy diff --git a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py index 7daebcbaf..18fb8d6b4 100755 --- a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py @@ -18,7 +18,7 @@ from dodal.devices.fast_grid_scan import set_fast_grid_scan_params as set_flyscan_params from dodal.devices.flux import Flux from dodal.devices.s4_slit_gaps import S4SlitGaps -from dodal.devices.smargon import Smargon +from dodal.devices.smargon import Smargon, StubPosition from dodal.devices.synchrotron import Synchrotron from dodal.devices.undulator import Undulator from dodal.devices.xbpm_feedback import XBPMFeedback @@ -247,7 +247,7 @@ def run_gridscan_and_move( hyperion.log.LOGGER.info("Recentring smargon co-ordinate system to this point.") yield from bps.mv( - fgs_composite.sample_motors.stub_offsets.center_at_current_position, 1 + fgs_composite.sample_motors.stub_offsets, StubPosition.CURRENT_AS_CENTER ) diff --git a/src/hyperion/experiment_plans/tests/conftest.py b/src/hyperion/experiment_plans/tests/conftest.py index ab2a335e3..f2457a9bf 100644 --- a/src/hyperion/experiment_plans/tests/conftest.py +++ b/src/hyperion/experiment_plans/tests/conftest.py @@ -89,6 +89,12 @@ def smargon() -> Smargon: smargon.z.user_setpoint._use_limits = False smargon.omega.user_setpoint._use_limits = False + # Initial positions, needed for stub_offsets + smargon.stub_offsets.center_at_current_position.disp.sim_put(0) + smargon.x.user_readback.sim_put(0.0) + smargon.y.user_readback.sim_put(0.0) + smargon.z.user_readback.sim_put(0.0) + with patch_motor(smargon.omega), patch_motor(smargon.x), patch_motor( smargon.y ), patch_motor(smargon.z): diff --git a/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py index 0c8839c96..9e45b87ab 100644 --- a/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py @@ -348,7 +348,10 @@ def test_when_gridscan_finished_then_smargon_stub_offsets_are_set( mock_subscriptions, ) ) - assert fake_fgs_composite.smargon.stub_offsets.center_at_current_position.get() == 1 + assert ( + fake_fgs_composite.smargon.stub_offsets.center_at_current_position.proc.get() + == 1 + ) @patch("hyperion.experiment_plans.flyscan_xray_centre_plan.run_gridscan", autospec=True) @@ -360,11 +363,14 @@ def test_given_gridscan_fails_to_centre_then_stub_offsets_not_set( test_fgs_params: GridscanInternalParameters, RE: RunEngine, ): - move_xyz.side_effect = Exception() + class MoveException(Exception): + pass + + move_xyz.side_effect = MoveException() mock_subscriptions = MagicMock() mock_subscriptions.zocalo_handler.wait_for_results.return_value = ((0, 0, 0), None) - with pytest.raises(Exception): + with pytest.raises(MoveException): RE( run_gridscan_and_move( fake_fgs_composite, @@ -372,7 +378,10 @@ def test_given_gridscan_fails_to_centre_then_stub_offsets_not_set( mock_subscriptions, ) ) - assert fake_fgs_composite.smargon.stub_offsets.center_at_current_position.get() == 0 + assert ( + fake_fgs_composite.smargon.stub_offsets.center_at_current_position.proc.get() + == 0 + ) @patch("hyperion.experiment_plans.flyscan_xray_centre_plan.bps.sleep", autospec=True)