diff --git a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py index acd9c5ae1..79e6ee21c 100644 --- a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py +++ b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py @@ -54,7 +54,7 @@ def __init__( for self.ispyb_ids.""" ISPYB_LOGGER.debug("Initialising ISPyB callback") super().__init__(log=ISPYB_LOGGER, emit=emit) - self._oav_snapshot_event_idx: Optional[int] = None + self._oav_snapshot_event_idx: int = 0 self._hwscan_data_collection_info: Optional[DataCollectionInfo] = None self._sample_barcode: Optional[str] = None self.params: GridscanInternalParameters | RotationInternalParameters | None = ( @@ -92,6 +92,9 @@ def activity_gated_event(self, doc: Event) -> Event: ISPYB_LOGGER.debug("ISPyB handler received event document.") assert self.ispyb is not None, "ISPyB deposition wasn't initialised!" assert self.params is not None, "ISPyB handler didn't recieve parameters!" + assert ( + self._hwscan_data_collection_info + ), "Processed unexpected event prior to callback activation" event_descriptor = self.descriptors.get(doc["descriptor"]) if event_descriptor is None: @@ -139,6 +142,7 @@ def _handle_ispyb_hardware_read(self, doc): def _handle_oav_snapshot_triggered(self, doc): assert self.ispyb_ids.data_collection_ids, "No current data collection" + assert self.params, "ISPyB handler didn't recieve parameters!" data = doc["data"] data_collection_id = None data_collection_info = DataCollectionInfo() @@ -201,6 +205,7 @@ def _handle_oav_snapshot_triggered(self, doc): def _handle_ispyb_transmission_flux_read(self, doc): assert self._hwscan_data_collection_info + assert self.params if doc["data"]["attenuator_actual_transmission"]: # Ispyb wants the transmission in a percentage, we use fractions self._hwscan_data_collection_info.transmission = ( diff --git a/tests/system_tests/external_interaction/test_ispyb_dev_connection.py b/tests/system_tests/external_interaction/test_ispyb_dev_connection.py index 4ccffc2a4..9acd63c0a 100644 --- a/tests/system_tests/external_interaction/test_ispyb_dev_connection.py +++ b/tests/system_tests/external_interaction/test_ispyb_dev_connection.py @@ -334,7 +334,7 @@ def test_ispyb_deposition_in_rotation_plan( fake_create_rotation_devices.dcm.energy_in_kev.user_readback.sim_put( # pyright: ignore energy_ev / 1000 ) - fake_create_rotation_devices.undulator.current_gap.sim_put(1.12) + fake_create_rotation_devices.undulator.current_gap.sim_put(1.12) # pyright: ignore fake_create_rotation_devices.synchrotron.machine_status.synchrotron_mode.sim_put( # pyright: ignore test_synchrotron_mode.value ) diff --git a/tests/unit_tests/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/experiment_plans/test_grid_detection_plan.py index 634e05541..0e442d979 100644 --- a/tests/unit_tests/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/experiment_plans/test_grid_detection_plan.py @@ -238,11 +238,11 @@ def decorated(): RE(ispyb_activation_wrapper(test_fgs_params, decorated())) assert_event( - cb.activity_gated_start.mock_calls[0], + cb.activity_gated_start.mock_calls[0], # pyright:ignore {"activate_callbacks": ["GridscanISPyBCallback"]}, ) assert_event( - cb.activity_gated_event.mock_calls[0], + cb.activity_gated_event.mock_calls[0], # pyright: ignore { "oav_snapshot_top_left_x": 8, "oav_snapshot_top_left_y": -6, @@ -255,7 +255,7 @@ def decorated(): }, ) assert_event( - cb.activity_gated_event.mock_calls[1], + cb.activity_gated_event.mock_calls[1], # pyright:ignore { "oav_snapshot_top_left_x": 8, "oav_snapshot_top_left_y": 2, diff --git a/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py index e88ea0904..260cb8dce 100644 --- a/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py @@ -1,6 +1,6 @@ import random import types -from typing import Tuple +from typing import Any, Tuple from unittest.mock import DEFAULT, MagicMock, call, patch import bluesky.preprocessors as bpp @@ -351,7 +351,7 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run( move_xyz: MagicMock, run_gridscan: MagicMock, move_aperture: MagicMock, - RE_with_subs: RunEngine, + RE_with_subs, mock_subscriptions: Tuple[GridscanNexusFileCallback, GridscanISPyBCallback], fake_fgs_composite: FlyScanXRayCentreComposite, test_panda_fgs_params: PandAGridscanInternalParameters, @@ -395,7 +395,7 @@ def test_when_gridscan_finished_then_smargon_stub_offsets_are_set( move_xyz: MagicMock, run_gridscan: MagicMock, aperture_set: MagicMock, - RE_with_subs: RunEngine, + RE_with_subs: tuple[RunEngine, Any], mock_subscriptions: Tuple[GridscanNexusFileCallback, GridscanISPyBCallback], test_panda_fgs_params: PandAGridscanInternalParameters, fake_fgs_composite: FlyScanXRayCentreComposite, @@ -441,7 +441,7 @@ def test_when_gridscan_succeeds_ispyb_comment_appended_to( move_xyz: MagicMock, run_gridscan: MagicMock, aperture_set: MagicMock, - RE_with_subs: RunEngine, + RE_with_subs: tuple[RunEngine, Any], mock_subscriptions: Tuple[GridscanNexusFileCallback, GridscanISPyBCallback], test_panda_fgs_params: PandAGridscanInternalParameters, fake_fgs_composite: FlyScanXRayCentreComposite, @@ -486,7 +486,7 @@ def test_when_gridscan_fails_ispyb_comment_appended_to( setup_panda_for_flyscan: MagicMock, move_xyz: MagicMock, run_gridscan: MagicMock, - RE_with_subs: RunEngine, + RE_with_subs: tuple[RunEngine, Any], mock_subscriptions: Tuple[GridscanNexusFileCallback, GridscanISPyBCallback], test_panda_fgs_params: PandAGridscanInternalParameters, fake_fgs_composite: FlyScanXRayCentreComposite, diff --git a/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py index 82f0bba64..64381b616 100644 --- a/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py @@ -75,9 +75,6 @@ def test_when_pin_centre_xray_centre_called_then_plan_runs_correctly( @patch( "hyperion.experiment_plans.grid_detect_then_xray_centre_plan.GridDetectionCallback", ) -@patch( - "hyperion.experiment_plans.grid_detect_then_xray_centre_plan.OavSnapshotCallback", -) @patch( "hyperion.experiment_plans.pin_centre_then_xray_centre_plan.pin_tip_centre_plan", autospec=True, @@ -89,7 +86,6 @@ def test_when_pin_centre_xray_centre_called_then_plan_runs_correctly( def test_when_pin_centre_xray_centre_called_then_detector_positioned( mock_grid_detect: MagicMock, mock_pin_tip_centre: MagicMock, - mock_oav_callback: MagicMock, mock_grid_callback: MagicMock, test_pin_centre_then_xray_centre_params: PinCentreThenXrayCentreInternalParameters, simple_beamline, @@ -97,12 +93,6 @@ def test_when_pin_centre_xray_centre_called_then_detector_positioned( sim_run_engine, ): - mock_oav_callback.return_value.out_upper_left = [[1, 3], [3, 4]] - mock_oav_callback.return_value.snapshot_filenames = [ - ["1.png", "2.png", "3.png"], - ["1.png", "2.png", "3.png"], - ["1.png", "2.png", "3.png"], - ] mock_grid_callback.return_value.get_grid_parameters.return_value = GridScanParams( dwell_time_ms=0, x_start=0, diff --git a/tests/unit_tests/external_interaction/callbacks/conftest.py b/tests/unit_tests/external_interaction/callbacks/conftest.py index 1f162d6a5..c82eab32a 100644 --- a/tests/unit_tests/external_interaction/callbacks/conftest.py +++ b/tests/unit_tests/external_interaction/callbacks/conftest.py @@ -149,6 +149,10 @@ class TestData: } # type: ignore test_event_document_oav_snapshot_xy: Event = { "descriptor": "b5ba4aec-de49-4970-81a4-b4a847391d34", + "time": 1666604299.828203, + "timestamps": {}, + "seq_num": 1, + "uid": "29033ecf-e052-43dd-98af-c7cdd62e8174", "data": { "oav_snapshot_top_left_x": 50, "oav_snapshot_top_left_y": 100, @@ -162,6 +166,10 @@ class TestData: } test_event_document_oav_snapshot_xz: Event = { "descriptor": "b5ba4aec-de49-4970-81a4-b4a847391d34", + "time": 1666604299.828203, + "timestamps": {}, + "seq_num": 1, + "uid": "29033ecf-e052-43dd-98af-c7cdd62e8174", "data": { "oav_snapshot_top_left_x": 50, "oav_snapshot_top_left_y": 0, diff --git a/tests/unit_tests/external_interaction/callbacks/test_plan_reactive_callback.py b/tests/unit_tests/external_interaction/callbacks/test_plan_reactive_callback.py index 48aaf6d0e..0f3dca5c5 100644 --- a/tests/unit_tests/external_interaction/callbacks/test_plan_reactive_callback.py +++ b/tests/unit_tests/external_interaction/callbacks/test_plan_reactive_callback.py @@ -187,10 +187,12 @@ def outer_plan(): inner_callback, activity_gated_start=DEFAULT, activity_gated_stop=DEFAULT ): root_mock = MagicMock() - root_mock.attach_mock(outer_callback.activity_gated_start, "outer_start") - root_mock.attach_mock(outer_callback.activity_gated_stop, "outer_stop") - root_mock.attach_mock(inner_callback.activity_gated_start, "inner_start") - root_mock.attach_mock(inner_callback.activity_gated_stop, "inner_stop") + # fmt: off + root_mock.attach_mock(outer_callback.activity_gated_start, "outer_start") # pyright: ignore + root_mock.attach_mock(outer_callback.activity_gated_stop, "outer_stop") # pyright: ignore + root_mock.attach_mock(inner_callback.activity_gated_start, "inner_start") # pyright: ignore + root_mock.attach_mock(inner_callback.activity_gated_stop, "inner_stop") # pyright: ignore + # fmt: on RE(outer_plan()) assert [call[0] for call in root_mock.mock_calls] == [