From c5bfc9157643c5c48dd111f78221ecc3c9125124 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 14 Mar 2023 10:23:12 +0000 Subject: [PATCH 01/23] use dodal.i03 devices in fast grid scan plan --- src/artemis/experiment_plans/fast_grid_scan_plan.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index e764011cf..211515418 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -7,10 +7,10 @@ import bluesky.preprocessors as bpp from bluesky import RunEngine from bluesky.utils import ProgressBarManager +from dodal import i03 from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard from dodal.devices.eiger import EigerDetector from dodal.devices.fast_grid_scan import FastGridScan, set_fast_grid_scan_params -from dodal.devices.fast_grid_scan_composite import FGSComposite from dodal.devices.s4_slit_gaps import S4SlitGaps from dodal.devices.synchrotron import Synchrotron from dodal.devices.undulator import Undulator @@ -59,18 +59,12 @@ def create_devices(): aperture_positions = AperturePositions.from_gda_beamline_params( get_beamline_parameters() ) - fast_grid_scan_composite = FGSComposite( - insertion_prefix=prefixes.insertion_prefix, - name="fgs", - prefix=prefixes.beamline_prefix, + fast_grid_scan_composite = i03.FGS( aperture_positions=aperture_positions, ) # Note, eiger cannot be currently waited on, see #166 - eiger = EigerDetector( - name="eiger", - prefix=f"{prefixes.beamline_prefix}-EA-EIGER-01:", - ) + eiger = i03.eiger() artemis.log.LOGGER.info("Connecting to EPICS devices...") fast_grid_scan_composite.wait_for_connection() From dc8f39fd7ebb1ee9695658de2bdd9432916281be Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 21 Mar 2023 16:40:11 +0000 Subject: [PATCH 02/23] update test for dodal change --- .../experiment_plans/fast_grid_scan_plan.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 211515418..34e842d01 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -14,6 +14,8 @@ from dodal.devices.s4_slit_gaps import S4SlitGaps from dodal.devices.synchrotron import Synchrotron from dodal.devices.undulator import Undulator +from dodal.devices.smargon import Smargon +from dodal.devices.zebra import Zebra import artemis.log from artemis.device_setup_plans.setup_zebra_for_fgs import ( @@ -41,6 +43,25 @@ ) from artemis.parameters.internal_parameters import InternalParameters + +class FGSComposite: + """A device consisting of all the Devices required for a fast gridscan.""" + + zebra: Zebra # = Component(Zebra, "-EA-ZEBRA-01:") + undulator: Undulator # = FormattedComponent(Undulator, "{insertion_prefix}-MO-SERVC-01:") + synchrotron: Synchrotron # = FormattedComponent(Synchrotron) + s4_slit_gaps: S4SlitGaps # = Component(S4SlitGaps, "-AL-SLITS-04:") + sample_motors: Smargon + aperture_scatterguard: ApertureScatterguard + + def __init__( + self, + aperture_positions: AperturePositions | None = None, + ): + if aperture_positions is not None: + self.aperture_scatterguard.load_aperture_positions(aperture_positions) + + fast_grid_scan_composite: FGSComposite = None eiger: EigerDetector = None From 9a95e038f4ac484e99d0cb6a14b649903c523ac8 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 21 Mar 2023 17:26:31 +0000 Subject: [PATCH 03/23] move fgs composite to plan --- .../experiment_plans/fast_grid_scan_plan.py | 88 +++++++++++-------- src/artemis/system_tests/test_main_system.py | 5 +- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 34e842d01..1236f8941 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -8,14 +8,22 @@ from bluesky import RunEngine from bluesky.utils import ProgressBarManager from dodal import i03 -from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard -from dodal.devices.eiger import EigerDetector -from dodal.devices.fast_grid_scan import FastGridScan, set_fast_grid_scan_params -from dodal.devices.s4_slit_gaps import S4SlitGaps -from dodal.devices.synchrotron import Synchrotron -from dodal.devices.undulator import Undulator -from dodal.devices.smargon import Smargon -from dodal.devices.zebra import Zebra +from dodal.devices.aperturescatterguard import AperturePositions +from dodal.devices.eiger import DetectorParams +from dodal.devices.fast_grid_scan import set_fast_grid_scan_params +from dodal.i03 import ( + DCM, + OAV, + ApertureScatterguard, + Backlight, + EigerDetector, + FastGridScan, + S4SlitGaps, + Smargon, + Synchrotron, + Undulator, + Zebra, +) import artemis.log from artemis.device_setup_plans.setup_zebra_for_fgs import ( @@ -36,8 +44,6 @@ from artemis.utils import Point3D if TYPE_CHECKING: - from dodal.devices.fast_grid_scan_composite import FGSComposite - from artemis.external_interaction.callbacks.fgs.fgs_callback_collection import ( FGSCallbackCollection, ) @@ -47,23 +53,37 @@ class FGSComposite: """A device consisting of all the Devices required for a fast gridscan.""" - zebra: Zebra # = Component(Zebra, "-EA-ZEBRA-01:") - undulator: Undulator # = FormattedComponent(Undulator, "{insertion_prefix}-MO-SERVC-01:") - synchrotron: Synchrotron # = FormattedComponent(Synchrotron) - s4_slit_gaps: S4SlitGaps # = Component(S4SlitGaps, "-AL-SLITS-04:") - sample_motors: Smargon + dcm: DCM + oav: OAV aperture_scatterguard: ApertureScatterguard + backlight: Backlight + eiger: EigerDetector + fast_grid_scan: FastGridScan + s4_slit_gaps: S4SlitGaps + sample_motors: Smargon + synchrotron: Synchrotron + undulator: Undulator + zebra: Zebra def __init__( self, - aperture_positions: AperturePositions | None = None, + aperture_positions: AperturePositions = None, + detector_params: DetectorParams = None, ): - if aperture_positions is not None: - self.aperture_scatterguard.load_aperture_positions(aperture_positions) + self.dcm = i03.dcm() + self.oav = i03.oav() + self.aperture_scatterguard = i03.aperture_scatterguard(aperture_positions) + self.backlight = i03.backlight() + self.eiger = i03.eiger(detector_params) + self.fast_grid_scan = i03.fast_grid_scan() + self.s4_slit_gaps = i03.s4_slip_gaps() + self.sample_motors = i03.smargon() + self.undulator = i03.undulator() + self.synchrotron = i03.synchrotron() + self.zebra = i03.zebra() -fast_grid_scan_composite: FGSComposite = None -eiger: EigerDetector = None +fast_grid_scan_composite: FGSComposite | None = None def get_beamline_parameters(): @@ -72,7 +92,7 @@ def get_beamline_parameters(): def create_devices(): """Creates the devices required for the plan and connect to them""" - global fast_grid_scan_composite, eiger + global fast_grid_scan_composite prefixes = get_beamline_prefixes() artemis.log.LOGGER.info( f"Creating devices for {prefixes.beamline_prefix} and {prefixes.insertion_prefix}" @@ -80,15 +100,8 @@ def create_devices(): aperture_positions = AperturePositions.from_gda_beamline_params( get_beamline_parameters() ) - fast_grid_scan_composite = i03.FGS( - aperture_positions=aperture_positions, - ) - - # Note, eiger cannot be currently waited on, see #166 - eiger = i03.eiger() - artemis.log.LOGGER.info("Connecting to EPICS devices...") - fast_grid_scan_composite.wait_for_connection() + fast_grid_scan_composite = FGSComposite(aperture_positions=aperture_positions) artemis.log.LOGGER.info("Connected.") @@ -172,7 +185,6 @@ def tidy_up_plans(fgs_composite: FGSComposite): @bpp.run_decorator(md={"subplan_name": "run_gridscan"}) def run_gridscan( fgs_composite: FGSComposite, - eiger: EigerDetector, parameters: InternalParameters, md={ "plan_name": "run_gridscan", @@ -202,7 +214,7 @@ def run_gridscan( @bpp.set_run_key_decorator("do_fgs") @bpp.run_decorator(md={"subplan_name": "do_fgs"}) - @bpp.stage_decorator([eiger]) + @bpp.stage_decorator([fgs_composite.eiger]) def do_fgs(): yield from bps.wait() # Wait for all moves to complete yield from bps.kickoff(fgs_motors) @@ -219,7 +231,6 @@ def do_fgs(): @bpp.run_decorator(md={"subplan_name": "run_gridscan_and_move"}) def run_gridscan_and_move( fgs_composite: FGSComposite, - eiger: EigerDetector, parameters: InternalParameters, subscriptions: FGSCallbackCollection, ): @@ -237,11 +248,11 @@ def run_gridscan_and_move( # While the gridscan is happening we want to write out nexus files and trigger zocalo @bpp.subs_decorator([subscriptions.nexus_handler, subscriptions.zocalo_handler]) - def gridscan_with_subscriptions(fgs_composite, detector, params): - yield from run_gridscan(fgs_composite, detector, params) + def gridscan_with_subscriptions(fgs_composite, params): + yield from run_gridscan(fgs_composite, params) artemis.log.LOGGER.info("Starting grid scan") - yield from gridscan_with_subscriptions(fgs_composite, eiger, parameters) + yield from gridscan_with_subscriptions(fgs_composite, parameters) # the data were submitted to zocalo by the zocalo callback during the gridscan, # but results may not be ready, and need to be collected regardless. @@ -278,7 +289,10 @@ def get_plan( Returns: Generator: The plan for the gridscan """ - eiger.set_detector_parameters(parameters.artemis_params.detector_params) + assert fast_grid_scan_composite is not None + fast_grid_scan_composite.eiger.set_detector_parameters( + parameters.artemis_params.detector_params + ) @bpp.finalize_decorator(lambda: tidy_up_plans(fast_grid_scan_composite)) @bpp.subs_decorator(subscriptions.ispyb_handler) @@ -286,7 +300,7 @@ def run_gridscan_and_move_and_tidy(fgs_composite, detector, params, comms): yield from run_gridscan_and_move(fgs_composite, detector, params, comms) return run_gridscan_and_move_and_tidy( - fast_grid_scan_composite, eiger, parameters, subscriptions + fast_grid_scan_composite, parameters, subscriptions ) diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index 38a68b0d4..c78a017f9 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -200,12 +200,11 @@ def test_cli_args_parse(): assert test_args == ("DEBUG", True, True) -@patch("artemis.experiment_plans.fast_grid_scan_plan.EigerDetector") -@patch("artemis.experiment_plans.fast_grid_scan_plan.FGSComposite") +@patch("dodal.i03.eiger") +@patch("dodal.i03.FGS") @patch("artemis.experiment_plans.fast_grid_scan_plan.get_beamline_parameters") def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected( mock_get_beamline_params, mock_fgs, mock_eiger ): BlueskyRunner(MagicMock()) - mock_fgs.return_value.wait_for_connection.assert_called_once() From 9609ee20be02f137163d4d750b0f1080b08ee3ce Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 22 Mar 2023 08:28:48 +0000 Subject: [PATCH 04/23] start on fallout of removing fgs composite --- .../experiment_plans/fast_grid_scan_plan.py | 6 +++--- .../fgs/tests/test_fgs_callback_collection.py | 13 ++++++------- src/artemis/system_tests/test_fgs_plan.py | 18 ++++++------------ .../unit_tests/test_fast_grid_scan_plan.py | 2 +- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 1236f8941..0c8ee6382 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -76,7 +76,7 @@ def __init__( self.backlight = i03.backlight() self.eiger = i03.eiger(detector_params) self.fast_grid_scan = i03.fast_grid_scan() - self.s4_slit_gaps = i03.s4_slip_gaps() + self.s4_slit_gaps = i03.s4_slit_gaps() self.sample_motors = i03.smargon() self.undulator = i03.undulator() self.synchrotron = i03.synchrotron() @@ -296,8 +296,8 @@ def get_plan( @bpp.finalize_decorator(lambda: tidy_up_plans(fast_grid_scan_composite)) @bpp.subs_decorator(subscriptions.ispyb_handler) - def run_gridscan_and_move_and_tidy(fgs_composite, detector, params, comms): - yield from run_gridscan_and_move(fgs_composite, detector, params, comms) + def run_gridscan_and_move_and_tidy(fgs_composite, params, comms): + yield from run_gridscan_and_move(fgs_composite, params, comms) return run_gridscan_and_move_and_tidy( fast_grid_scan_composite, parameters, subscriptions diff --git a/src/artemis/external_interaction/callbacks/fgs/tests/test_fgs_callback_collection.py b/src/artemis/external_interaction/callbacks/fgs/tests/test_fgs_callback_collection.py index be7168444..040fd0da3 100644 --- a/src/artemis/external_interaction/callbacks/fgs/tests/test_fgs_callback_collection.py +++ b/src/artemis/external_interaction/callbacks/fgs/tests/test_fgs_callback_collection.py @@ -3,13 +3,15 @@ import pytest from bluesky.run_engine import RunEngine from dodal.devices.eiger import DetectorParams, EigerDetector -from dodal.devices.fast_grid_scan_composite import FGSComposite -from artemis.experiment_plans.fast_grid_scan_plan import run_gridscan_and_move +from artemis.experiment_plans.fast_grid_scan_plan import ( + FGSComposite, + run_gridscan_and_move, +) from artemis.external_interaction.callbacks.fgs.fgs_callback_collection import ( FGSCallbackCollection, ) -from artemis.parameters.constants import SIM_BEAMLINE, SIM_INSERTION_PREFIX +from artemis.parameters.constants import SIM_BEAMLINE from artemis.parameters.internal_parameters import InternalParameters from artemis.utils import Point3D @@ -89,13 +91,10 @@ def test_communicator_in_composite_run( callbacks.zocalo_handler._run_start = MagicMock() callbacks.zocalo_handler.xray_centre_motor_position = Point3D(1, 2, 3) - fast_grid_scan_composite = FGSComposite( - insertion_prefix=SIM_INSERTION_PREFIX, name="fgs", prefix=SIM_BEAMLINE - ) + fast_grid_scan_composite = FGSComposite() # this is where it's currently getting stuck: # fast_grid_scan_composite.fast_grid_scan.is_invalid = lambda: False # but this is not a solution - fast_grid_scan_composite.wait_for_connection() # Would be better to use get_plan instead but eiger doesn't work well in S03 RE(run_gridscan_and_move(fast_grid_scan_composite, eiger, params, callbacks)) diff --git a/src/artemis/system_tests/test_fgs_plan.py b/src/artemis/system_tests/test_fgs_plan.py index 7b8cd34b3..9788471d7 100644 --- a/src/artemis/system_tests/test_fgs_plan.py +++ b/src/artemis/system_tests/test_fgs_plan.py @@ -8,11 +8,11 @@ from dodal.devices.aperturescatterguard import AperturePositions from dodal.devices.detector import DetectorParams from dodal.devices.eiger import DetectorParams, EigerDetector -from dodal.devices.fast_grid_scan_composite import FGSComposite import artemis.experiment_plans.fast_grid_scan_plan as fgs_plan from artemis.exceptions import WarningException from artemis.experiment_plans.fast_grid_scan_plan import ( + FGSComposite, get_plan, read_hardware_for_ispyb, run_gridscan, @@ -28,11 +28,7 @@ ISPYB_CONFIG, ) from artemis.parameters.beamline_parameters import GDABeamlineParameters -from artemis.parameters.constants import ( - I03_BEAMLINE_PARAMETER_PATH, - SIM_BEAMLINE, - SIM_INSERTION_PREFIX, -) +from artemis.parameters.constants import I03_BEAMLINE_PARAMETER_PATH, SIM_BEAMLINE from artemis.parameters.internal_parameters import InternalParameters @@ -78,12 +74,10 @@ def RE(): @pytest.fixture def fgs_composite(): - fast_grid_scan_composite = FGSComposite( - insertion_prefix=SIM_INSERTION_PREFIX, - name="fgs", - prefix=SIM_BEAMLINE, - ) - fast_grid_scan_composite.wait_for_connection() + with patch("dodal.i03.dcm"): + with patch("dodal.i03.oav"): + with patch("dodal.i03.undulator"): + fast_grid_scan_composite = FGSComposite() fgs_plan.fast_grid_scan_composite = fast_grid_scan_composite gda_beamline_parameters = GDABeamlineParameters.from_file( I03_BEAMLINE_PARAMETER_PATH diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index 74612cbc0..a06d1e70a 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -12,12 +12,12 @@ ) from dodal.devices.eiger import EigerDetector from dodal.devices.fast_grid_scan import FastGridScan -from dodal.devices.fast_grid_scan_composite import FGSComposite from ophyd.sim import make_fake_device from ophyd.status import Status from artemis.exceptions import WarningException from artemis.experiment_plans.fast_grid_scan_plan import ( + FGSComposite, read_hardware_for_ispyb, run_gridscan, run_gridscan_and_move, From 687270b5948f8d1f63794c44b3c19679aba86ece Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 22 Mar 2023 08:48:37 +0000 Subject: [PATCH 05/23] continue resolving removal of fgs_composite --- .../external_interaction/callbacks/fgs/ispyb_callback.py | 8 ++++---- .../external_interaction/callbacks/fgs/tests/conftest.py | 8 ++++---- src/artemis/system_tests/test_fgs_plan.py | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py b/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py index 95342a161..7ea7f5664 100644 --- a/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py +++ b/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py @@ -70,16 +70,16 @@ def event(self, doc: dict): if event_descriptor.get("name") == ISPYB_PLAN_NAME: self.params.artemis_params.ispyb_params.undulator_gap = doc["data"][ - "fgs_undulator_gap" + "undulator_gap" ] self.params.artemis_params.ispyb_params.synchrotron_mode = doc["data"][ - "fgs_synchrotron_machine_status_synchrotron_mode" + "synchrotron_machine_status_synchrotron_mode" ] self.params.artemis_params.ispyb_params.slit_gap_size_x = doc["data"][ - "fgs_s4_slit_gaps_xgap" + "s4_slit_gaps_xgap" ] self.params.artemis_params.ispyb_params.slit_gap_size_y = doc["data"][ - "fgs_s4_slit_gaps_ygap" + "s4_slit_gaps_ygap" ] LOGGER.info("Creating ispyb entry.") diff --git a/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py b/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py index 167ff5d4d..cad9600dd 100644 --- a/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py +++ b/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py @@ -92,10 +92,10 @@ class TestData: "descriptor": "bd45c2e5-2b85-4280-95d7-a9a15800a78b", "time": 1666604299.828203, "data": { - "fgs_s4_slit_gaps_xgap": 0.1234, - "fgs_s4_slit_gaps_ygap": 0.2345, - "fgs_synchrotron_machine_status_synchrotron_mode": "test", - "fgs_undulator_gap": 1.234, + "s4_slit_gaps_xgap": 0.1234, + "s4_slit_gaps_ygap": 0.2345, + "synchrotron_machine_status_synchrotron_mode": "test", + "undulator_gap": 1.234, }, "timestamps": {"det1": 1666604299.8220396, "det2": 1666604299.8235943}, "seq_num": 1, diff --git a/src/artemis/system_tests/test_fgs_plan.py b/src/artemis/system_tests/test_fgs_plan.py index 9788471d7..6519d3de0 100644 --- a/src/artemis/system_tests/test_fgs_plan.py +++ b/src/artemis/system_tests/test_fgs_plan.py @@ -76,8 +76,8 @@ def RE(): def fgs_composite(): with patch("dodal.i03.dcm"): with patch("dodal.i03.oav"): - with patch("dodal.i03.undulator"): - fast_grid_scan_composite = FGSComposite() + # with patch("dodal.i03.undulator"): + fast_grid_scan_composite = FGSComposite() fgs_plan.fast_grid_scan_composite = fast_grid_scan_composite gda_beamline_parameters = GDABeamlineParameters.from_file( I03_BEAMLINE_PARAMETER_PATH @@ -130,7 +130,6 @@ def test_read_hardware_for_ispyb( def read_run(u, s, g): yield from read_hardware_for_ispyb(u, s, g) - fgs_composite.wait_for_connection() RE(read_run(undulator, synchrotron, slit_gaps)) From 4b28279dbf03ca2dc8336b3674992885f9e538b5 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 23 Mar 2023 07:49:44 +0000 Subject: [PATCH 06/23] update dodal req hash --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 87462b255..798b15306 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@1a7f45c26af27e53dc27e01593b1df895d28d6e8 + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@5305ec9b37f9233d87fc59a02b7dc928a10f94e3 [options.extras_require] dev = From 01b49996d714a08334eaebfdbf3fde0d1e488419 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 23 Mar 2023 17:51:45 +0000 Subject: [PATCH 07/23] update FGS composite with simulation arg --- .../experiment_plans/fast_grid_scan_plan.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 0c8ee6382..ae60f33d4 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -69,18 +69,21 @@ def __init__( self, aperture_positions: AperturePositions = None, detector_params: DetectorParams = None, + fake: bool = False, ): - self.dcm = i03.dcm() - self.oav = i03.oav() - self.aperture_scatterguard = i03.aperture_scatterguard(aperture_positions) - self.backlight = i03.backlight() - self.eiger = i03.eiger(detector_params) - self.fast_grid_scan = i03.fast_grid_scan() - self.s4_slit_gaps = i03.s4_slit_gaps() - self.sample_motors = i03.smargon() - self.undulator = i03.undulator() - self.synchrotron = i03.synchrotron() - self.zebra = i03.zebra() + self.dcm = i03.dcm(fake_with_ophyd_sim=fake) + self.oav = i03.oav(fake_with_ophyd_sim=fake) + self.aperture_scatterguard = i03.aperture_scatterguard( + fake_with_ophyd_sim=fake, aperture_positions=aperture_positions + ) + self.backlight = i03.backlight(fake_with_ophyd_sim=fake) + self.eiger = i03.eiger(fake_with_ophyd_sim=fake, params=detector_params) + self.fast_grid_scan = i03.fast_grid_scan(fake_with_ophyd_sim=fake) + self.s4_slit_gaps = i03.s4_slit_gaps(fake_with_ophyd_sim=fake) + self.sample_motors = i03.smargon(fake_with_ophyd_sim=fake) + self.undulator = i03.undulator(fake_with_ophyd_sim=fake) + self.synchrotron = i03.synchrotron(fake_with_ophyd_sim=fake) + self.zebra = i03.zebra(fake_with_ophyd_sim=fake) fast_grid_scan_composite: FGSComposite | None = None From 91000e9886f5b17ea7a79a5007af2e22e3efab50 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 23 Mar 2023 18:06:58 +0000 Subject: [PATCH 08/23] update tests and dodal req --- setup.cfg | 2 +- src/artemis/system_tests/test_main_system.py | 1 - .../unit_tests/test_fast_grid_scan_plan.py | 63 +++++++------------ 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/setup.cfg b/setup.cfg index 798b15306..d9a2d7e3a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@5305ec9b37f9233d87fc59a02b7dc928a10f94e3 + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@376a220a345553517fab6534b788af6f5fcce7ae [options.extras_require] dev = diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index c78a017f9..6570ed57f 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -201,7 +201,6 @@ def test_cli_args_parse(): @patch("dodal.i03.eiger") -@patch("dodal.i03.FGS") @patch("artemis.experiment_plans.fast_grid_scan_plan.get_beamline_parameters") def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected( mock_get_beamline_params, mock_fgs, mock_eiger diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index a06d1e70a..53f6abf61 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -10,7 +10,6 @@ EIGER_TYPE_EIGER2_X_4M, EIGER_TYPE_EIGER2_X_16M, ) -from dodal.devices.eiger import EigerDetector from dodal.devices.fast_grid_scan import FastGridScan from ophyd.sim import make_fake_device from ophyd.status import Status @@ -49,9 +48,17 @@ def test_params(): @pytest.fixture -def fake_fgs_composite(): - FakeComposite = make_fake_device(FGSComposite) - fake_composite: FGSComposite = FakeComposite("test", name="fgs") +def fake_fgs_composite(test_params: InternalParameters): + fake_composite = FGSComposite( + aperture_positions=AperturePositions( + LARGE=(1, 2, 3, 4, 5), + MEDIUM=(2, 3, 3, 5, 6), + SMALL=(3, 4, 3, 6, 7), + ROBOT_LOAD=(0, 0, 3, 0, 0), + ), + detector_params=test_params.artemis_params.detector_params, + fake=True, + ) fake_composite.aperture_scatterguard.aperture.x.user_setpoint._use_limits = False fake_composite.aperture_scatterguard.aperture.y.user_setpoint._use_limits = False fake_composite.aperture_scatterguard.aperture.z.user_setpoint._use_limits = False @@ -61,14 +68,6 @@ def fake_fgs_composite(): fake_composite.aperture_scatterguard.scatterguard.y.user_setpoint._use_limits = ( False ) - fake_composite.aperture_scatterguard.load_aperture_positions( - AperturePositions( - LARGE=(1, 2, 3, 4, 5), - MEDIUM=(2, 3, 3, 5, 6), - SMALL=(3, 4, 3, 6, 7), - ROBOT_LOAD=(0, 0, 3, 0, 0), - ) - ) fake_composite.fast_grid_scan.scan_invalid.sim_put(False) fake_composite.fast_grid_scan.position_counter.sim_put(0) @@ -94,15 +93,6 @@ def mock_subscriptions(test_params): return subscriptions -@pytest.fixture -def fake_eiger(test_params: InternalParameters): - FakeEiger: EigerDetector = make_fake_device(EigerDetector) - fake_eiger = FakeEiger.with_params( - params=test_params.artemis_params.detector_params, name="test" - ) - return fake_eiger - - def test_given_full_parameters_dict_when_detector_name_used_and_converted_then_detector_constants_correct(): params = InternalParameters(RawParameters()) assert ( @@ -181,7 +171,6 @@ def test_results_adjusted_and_passed_to_move_xyz( move_aperture: MagicMock, fake_fgs_composite: FGSComposite, mock_subscriptions: FGSCallbackCollection, - fake_eiger: EigerDetector, test_params: InternalParameters, ): RE = RunEngine({}) @@ -194,7 +183,6 @@ def test_results_adjusted_and_passed_to_move_xyz( RE( run_gridscan_and_move( fake_fgs_composite, - fake_eiger, test_params, mock_subscriptions, ) @@ -205,7 +193,6 @@ def test_results_adjusted_and_passed_to_move_xyz( RE( run_gridscan_and_move( fake_fgs_composite, - fake_eiger, test_params, mock_subscriptions, ) @@ -216,7 +203,6 @@ def test_results_adjusted_and_passed_to_move_xyz( RE( run_gridscan_and_move( fake_fgs_composite, - fake_eiger, test_params, mock_subscriptions, ) @@ -239,7 +225,9 @@ def test_results_adjusted_and_passed_to_move_xyz( @patch("bluesky.plan_stubs.mv") def test_results_passed_to_move_motors( - bps_mv: MagicMock, test_params: InternalParameters + bps_mv: MagicMock, + test_params: InternalParameters, + fake_fgs_composite: FGSComposite, ): from artemis.experiment_plans.fast_grid_scan_plan import move_xyz @@ -249,8 +237,7 @@ def test_results_passed_to_move_motors( motor_position = test_params.experiment_params.grid_position_to_motor_position( Point3D(1, 2, 3) ) - FakeComposite: FGSComposite = make_fake_device(FGSComposite) - RE(move_xyz(FakeComposite("test", name="fgs").sample_motors, motor_position)) + RE(move_xyz(fake_fgs_composite.sample_motors, motor_position)) bps_mv.assert_called_once_with( ANY, motor_position.x, ANY, motor_position.y, ANY, motor_position.z ) @@ -269,7 +256,6 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run( move_aperture: MagicMock, mock_subscriptions: FGSCallbackCollection, fake_fgs_composite: FGSComposite, - fake_eiger: EigerDetector, test_params: FGSComposite, ): RE = RunEngine({}) @@ -280,13 +266,12 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run( RE( run_gridscan_and_move( fake_fgs_composite, - fake_eiger, test_params, mock_subscriptions, ) ) - run_gridscan.assert_called_once_with(fake_fgs_composite, fake_eiger, params) + run_gridscan.assert_called_once_with(fake_fgs_composite, params) move_xyz.assert_called_once_with(ANY, Point3D(0.05, 0.15000000000000002, 0.25)) @@ -303,7 +288,6 @@ def test_logging_within_plan( move_aperture: MagicMock, mock_subscriptions: FGSCallbackCollection, fake_fgs_composite: FGSComposite, - fake_eiger: EigerDetector, test_params: InternalParameters, ): RE = RunEngine({}) @@ -313,13 +297,12 @@ def test_logging_within_plan( RE( run_gridscan_and_move( fake_fgs_composite, - fake_eiger, test_params, mock_subscriptions, ) ) - run_gridscan.assert_called_once_with(fake_fgs_composite, fake_eiger, test_params) + run_gridscan.assert_called_once_with(fake_fgs_composite, test_params) move_xyz.assert_called_once_with(ANY, Point3D(0.05, 0.15000000000000002, 0.25)) @@ -365,7 +348,6 @@ def test_when_grid_scan_ran_then_eiger_disarmed_before_zocalo_end( mock_kickoff, mock_abs_set, fake_fgs_composite: FGSComposite, - fake_eiger: EigerDetector, test_params: InternalParameters, mock_subscriptions: FGSCallbackCollection, ): @@ -374,19 +356,18 @@ def test_when_grid_scan_ran_then_eiger_disarmed_before_zocalo_end( # Put both mocks in a parent to easily capture order mock_parent = MagicMock() - fake_eiger.disarm_detector = mock_parent.disarm + fake_fgs_composite.eiger.disarm_detector = mock_parent.disarm - fake_eiger.filewriters_finished = Status() - fake_eiger.filewriters_finished.set_finished() - fake_eiger.odin.check_odin_state = MagicMock(return_value=True) - fake_eiger.stage = MagicMock() + fake_fgs_composite.eiger.filewriters_finished = Status() + fake_fgs_composite.eiger.filewriters_finished.set_finished() + fake_fgs_composite.eiger.odin.check_odin_state = MagicMock(return_value=True) + fake_fgs_composite.eiger.stage = MagicMock() mock_subscriptions.zocalo_handler.zocalo_interactor.run_end = mock_parent.run_end RE( run_gridscan_and_move( fake_fgs_composite, - fake_eiger, test_params, mock_subscriptions, ) From 51cd509a13b765d9db07bd41a2973d34e9fa0af3 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 23 Mar 2023 18:25:05 +0000 Subject: [PATCH 09/23] update tests --- .../experiment_plans/fast_grid_scan_plan.py | 4 +- src/artemis/system_tests/test_fgs_plan.py | 73 +++++++------------ 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index ae60f33d4..6ac2716ae 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -77,7 +77,9 @@ def __init__( fake_with_ophyd_sim=fake, aperture_positions=aperture_positions ) self.backlight = i03.backlight(fake_with_ophyd_sim=fake) - self.eiger = i03.eiger(fake_with_ophyd_sim=fake, params=detector_params) + self.eiger = i03.eiger( + wait_for_connection=False, fake_with_ophyd_sim=fake, params=detector_params + ) self.fast_grid_scan = i03.fast_grid_scan(fake_with_ophyd_sim=fake) self.s4_slit_gaps = i03.s4_slit_gaps(fake_with_ophyd_sim=fake) self.sample_motors = i03.smargon(fake_with_ophyd_sim=fake) diff --git a/src/artemis/system_tests/test_fgs_plan.py b/src/artemis/system_tests/test_fgs_plan.py index 6519d3de0..51c80ff12 100644 --- a/src/artemis/system_tests/test_fgs_plan.py +++ b/src/artemis/system_tests/test_fgs_plan.py @@ -7,7 +7,7 @@ from bluesky.run_engine import RunEngine from dodal.devices.aperturescatterguard import AperturePositions from dodal.devices.detector import DetectorParams -from dodal.devices.eiger import DetectorParams, EigerDetector +from dodal.devices.eiger import DetectorParams import artemis.experiment_plans.fast_grid_scan_plan as fgs_plan from artemis.exceptions import WarningException @@ -31,38 +31,6 @@ from artemis.parameters.constants import I03_BEAMLINE_PARAMETER_PATH, SIM_BEAMLINE from artemis.parameters.internal_parameters import InternalParameters - -@pytest.fixture() -def eiger() -> EigerDetector: - detector_params: DetectorParams = DetectorParams( - current_energy=100, - exposure_time=0.1, - directory="/tmp", - prefix="file_name", - detector_distance=100.0, - omega_start=0.0, - omega_increment=0.1, - num_images=50, - use_roi_mode=False, - run_number=0, - det_dist_to_beam_converter_path="src/artemis/unit_tests/test_lookup_table.txt", - ) - eiger = EigerDetector.with_params( - params=detector_params, name="eiger", prefix="BL03S-EA-EIGER-01:" - ) - - # Otherwise odin moves too fast to be tested - eiger.cam.manual_trigger.put("Yes") - - # S03 currently does not have StaleParameters_RBV - eiger.wait_for_stale_parameters = lambda: None - eiger.odin.check_odin_initialised = lambda: (True, "") - - fgs_plan.eiger = eiger - - yield eiger - - params = InternalParameters() params.artemis_params.beamline = SIM_BEAMLINE @@ -76,8 +44,22 @@ def RE(): def fgs_composite(): with patch("dodal.i03.dcm"): with patch("dodal.i03.oav"): - # with patch("dodal.i03.undulator"): - fast_grid_scan_composite = FGSComposite() + with patch("dodal.i03.fast_grid_scan"): + fast_grid_scan_composite = FGSComposite( + detector_params=DetectorParams( + current_energy=100, + exposure_time=0.1, + directory="/tmp", + prefix="file_name", + detector_distance=100.0, + omega_start=0.0, + omega_increment=0.1, + num_images=50, + use_roi_mode=False, + run_number=0, + det_dist_to_beam_converter_path="src/artemis/unit_tests/test_lookup_table.txt", + ) + ) fgs_plan.fast_grid_scan_composite = fast_grid_scan_composite gda_beamline_parameters = GDABeamlineParameters.from_file( I03_BEAMLINE_PARAMETER_PATH @@ -91,6 +73,12 @@ def fgs_composite(): fast_grid_scan_composite.aperture_scatterguard.aperture.z.move( aperture_positions.LARGE[2], wait=True ) + fast_grid_scan_composite.eiger.cam.manual_trigger.put("Yes") + + # S03 currently does not have StaleParameters_RBV + fast_grid_scan_composite.eiger.wait_for_stale_parameters = lambda: None + fast_grid_scan_composite.eiger.odin.check_odin_initialised = lambda: (True, "") + fast_grid_scan_composite.aperture_scatterguard.scatterguard.x.set_lim(-4.8, 5.7) return fast_grid_scan_composite @@ -106,19 +94,16 @@ def test_run_gridscan( complete: MagicMock, kickoff: MagicMock, wait: MagicMock, - eiger: EigerDetector, RE: RunEngine, fgs_composite: FGSComposite, ): - eiger.unstage = lambda: True - fgs_composite.wait_for_connection() + fgs_composite.eiger.unstage = lambda: True # Would be better to use get_plan instead but eiger doesn't work well in S03 - RE(run_gridscan(fgs_composite, eiger, params)) + RE(run_gridscan(fgs_composite, params)) @pytest.mark.s03 def test_read_hardware_for_ispyb( - eiger: EigerDetector, RE: RunEngine, fgs_composite: FGSComposite, ): @@ -147,7 +132,6 @@ def test_full_plan_tidies_at_end( complete: MagicMock, kickoff: MagicMock, wait: MagicMock, - eiger: EigerDetector, fgs_composite: FGSComposite, RE: RunEngine, ): @@ -170,7 +154,6 @@ def test_full_plan_tidies_at_end_when_plan_fails( complete: MagicMock, kickoff: MagicMock, wait: MagicMock, - eiger: EigerDetector, fgs_composite: FGSComposite, RE: RunEngine, ): @@ -184,7 +167,6 @@ def test_full_plan_tidies_at_end_when_plan_fails( @pytest.mark.s03 def test_GIVEN_scan_invalid_WHEN_plan_run_THEN_ispyb_entry_made_but_no_zocalo_entry( - eiger: EigerDetector, RE: RunEngine, fgs_composite: FGSComposite, fetch_comment: Callable, @@ -219,7 +201,6 @@ def test_GIVEN_scan_invalid_WHEN_plan_run_THEN_ispyb_entry_made_but_no_zocalo_en def test_WHEN_plan_run_THEN_move_to_centre_returned_from_zocalo_expected_centre( complete: MagicMock, kickoff: MagicMock, - eiger: EigerDetector, RE: RunEngine, fgs_composite: FGSComposite, zocalo_env: None, @@ -235,8 +216,8 @@ def test_WHEN_plan_run_THEN_move_to_centre_returned_from_zocalo_expected_centre( # Currently s03 calls anything with z_steps > 1 invalid parameters.experiment_params.z_steps = 1 - eiger.stage = MagicMock() - eiger.unstage = MagicMock() + fgs_composite.eiger.stage = MagicMock() + fgs_composite.eiger.unstage = MagicMock() callbacks = FGSCallbackCollection.from_params(parameters) callbacks.ispyb_handler.ispyb.ISPYB_CONFIG_PATH = ISPYB_CONFIG From 88a905e61f6a40b4904bff3f60ff44669c0dba74 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 24 Mar 2023 12:21:51 +0000 Subject: [PATCH 10/23] update system tests --- .../experiment_plans/fast_grid_scan_plan.py | 4 +- src/artemis/system_tests/test_fgs_plan.py | 32 +++++++--------- src/artemis/system_tests/test_main_system.py | 37 +++++++++++++++++-- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 6ac2716ae..1f740dbd2 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -156,6 +156,7 @@ def move_xyz( ): """Move 'sample motors' to a specific motor position (e.g. a position obtained from gridscan processing results)""" + artemis.log.LOGGER.info(f"Moving Smargon x, y, z to: {xray_centre_motor_position}") yield from bps.mv( sample_motors.x, xray_centre_motor_position.x, @@ -183,6 +184,7 @@ def wait_for_fgs_valid(fgs_motors: FastGridScan, timeout=0.5): def tidy_up_plans(fgs_composite: FGSComposite): + artemis.log.LOGGER.info("Tidying up Zebra") yield from set_zebra_shutter_to_manual(fgs_composite.zebra) @@ -254,9 +256,9 @@ def run_gridscan_and_move( # While the gridscan is happening we want to write out nexus files and trigger zocalo @bpp.subs_decorator([subscriptions.nexus_handler, subscriptions.zocalo_handler]) def gridscan_with_subscriptions(fgs_composite, params): + artemis.log.LOGGER.info("Starting grid scan") yield from run_gridscan(fgs_composite, params) - artemis.log.LOGGER.info("Starting grid scan") yield from gridscan_with_subscriptions(fgs_composite, parameters) # the data were submitted to zocalo by the zocalo callback during the gridscan, diff --git a/src/artemis/system_tests/test_fgs_plan.py b/src/artemis/system_tests/test_fgs_plan.py index 51c80ff12..3ea948287 100644 --- a/src/artemis/system_tests/test_fgs_plan.py +++ b/src/artemis/system_tests/test_fgs_plan.py @@ -44,22 +44,21 @@ def RE(): def fgs_composite(): with patch("dodal.i03.dcm"): with patch("dodal.i03.oav"): - with patch("dodal.i03.fast_grid_scan"): - fast_grid_scan_composite = FGSComposite( - detector_params=DetectorParams( - current_energy=100, - exposure_time=0.1, - directory="/tmp", - prefix="file_name", - detector_distance=100.0, - omega_start=0.0, - omega_increment=0.1, - num_images=50, - use_roi_mode=False, - run_number=0, - det_dist_to_beam_converter_path="src/artemis/unit_tests/test_lookup_table.txt", - ) + fast_grid_scan_composite = FGSComposite( + detector_params=DetectorParams( + current_energy=100, + exposure_time=0.1, + directory="/tmp", + prefix="file_name", + detector_distance=100.0, + omega_start=0.0, + omega_increment=0.1, + num_images=50, + use_roi_mode=False, + run_number=0, + det_dist_to_beam_converter_path="src/artemis/unit_tests/test_lookup_table.txt", ) + ) fgs_plan.fast_grid_scan_composite = fast_grid_scan_composite gda_beamline_parameters = GDABeamlineParameters.from_file( I03_BEAMLINE_PARAMETER_PATH @@ -120,7 +119,6 @@ def read_run(u, s, g): @pytest.mark.s03 @patch("artemis.experiment_plans.fast_grid_scan_plan.fast_grid_scan_composite") -@patch("artemis.experiment_plans.fast_grid_scan_plan.eiger") @patch("bluesky.plan_stubs.wait") @patch("bluesky.plan_stubs.kickoff") @patch("bluesky.plan_stubs.complete") @@ -142,7 +140,6 @@ def test_full_plan_tidies_at_end( @pytest.mark.s03 @patch("artemis.experiment_plans.fast_grid_scan_plan.fast_grid_scan_composite") -@patch("artemis.experiment_plans.fast_grid_scan_plan.eiger") @patch("bluesky.plan_stubs.wait") @patch("bluesky.plan_stubs.kickoff") @patch("bluesky.plan_stubs.complete") @@ -162,7 +159,6 @@ def test_full_plan_tidies_at_end_when_plan_fails( with pytest.raises(Exception): RE(get_plan(params, callbacks)) set_shutter_to_manual.assert_called_once() - # tidy_plans.assert_called_once() @pytest.mark.s03 diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index 6570ed57f..1fb221c7c 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -200,10 +200,41 @@ def test_cli_args_parse(): assert test_args == ("DEBUG", True, True) -@patch("dodal.i03.eiger") +@patch("dodal.i03.ApertureScatterguard") +@patch("dodal.i03.Backlight") +@patch("dodal.i03.DCM") +@patch("dodal.i03.EigerDetector") +@patch("dodal.i03.FastGridScan") +@patch("dodal.i03.OAV") +@patch("dodal.i03.S4SlitGaps") +@patch("dodal.i03.Smargon") +@patch("dodal.i03.Synchrotron") +@patch("dodal.i03.Undulator") +@patch("dodal.i03.Zebra") @patch("artemis.experiment_plans.fast_grid_scan_plan.get_beamline_parameters") def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected( - mock_get_beamline_params, mock_fgs, mock_eiger + mock_get_beamline_params, + zebra, + undulator, + synchrotron, + smargon, + s4_slits, + oav, + fast_grid_scan, + eiger, + dcm, + backlight, + aperture_scatterguard, ): BlueskyRunner(MagicMock()) - mock_fgs.return_value.wait_for_connection.assert_called_once() + zebra.return_value.wait_for_connection.assert_called_once() + undulator.return_value.wait_for_connection.assert_called_once() + synchrotron.return_value.wait_for_connection.assert_called_once() + smargon.return_value.wait_for_connection.assert_called_once() + s4_slits.return_value.wait_for_connection.assert_called_once() + oav.return_value.wait_for_connection.assert_called_once() + fast_grid_scan.return_value.wait_for_connection.assert_called_once() + eiger.return_value.wait_for_connection.assert_not_called() # can't wait on eiger + dcm.return_value.wait_for_connection.assert_called_once() + backlight.return_value.wait_for_connection.assert_called_once() + aperture_scatterguard.return_value.wait_for_connection.assert_called_once() From f85bb3c0e44cb3a1bc527009f3b3d5d56210014e Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 24 Mar 2023 13:17:50 +0000 Subject: [PATCH 11/23] update dodal rq --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index d9a2d7e3a..40acb7b00 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@376a220a345553517fab6534b788af6f5fcce7ae + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@76f42df09bdb1afce243096fdd24c64559ae6338 [options.extras_require] dev = From fcf8c40118bd5ea13c17633a05b6ba2c9626cddc Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 24 Mar 2023 13:35:50 +0000 Subject: [PATCH 12/23] mock our bps.rd in unit tests --- .../callbacks/fgs/zocalo_callback.py | 2 +- src/artemis/unit_tests/test_fast_grid_scan_plan.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/artemis/external_interaction/callbacks/fgs/zocalo_callback.py b/src/artemis/external_interaction/callbacks/fgs/zocalo_callback.py index 6aa035b3f..2e047216e 100644 --- a/src/artemis/external_interaction/callbacks/fgs/zocalo_callback.py +++ b/src/artemis/external_interaction/callbacks/fgs/zocalo_callback.py @@ -139,7 +139,7 @@ def wait_for_results(self, fallback_xyz: Point3D) -> Point3D: self.ispyb.append_to_comment("Found no diffraction.") xray_centre = fallback_xyz bbox_size = None - LOGGER.warn(log_msg) + LOGGER.warning(log_msg) self.processing_time = time.time() - self.processing_start_time self.ispyb.append_to_comment( diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index 53f6abf61..943876026 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -116,7 +116,9 @@ def test_when_run_gridscan_called_then_generator_returned(): assert isinstance(plan, types.GeneratorType) +@patch("bluesky.plan_stubs.rd") def test_read_hardware_for_ispyb_updates_from_ophyd_devices( + rd, fake_fgs_composite: FGSComposite, ): RE = RunEngine({}) @@ -249,7 +251,9 @@ def test_results_passed_to_move_motors( @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan.do_fgs") @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @patch("artemis.experiment_plans.fast_grid_scan_plan.move_xyz") +@patch("bluesky.plan_stubs.rd") def test_individual_plans_triggered_once_and_only_once_in_composite_run( + rd: MagicMock, move_xyz: MagicMock, run_gridscan: MagicMock, do_fgs: MagicMock, @@ -281,7 +285,9 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run( @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan.do_fgs") @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @patch("artemis.experiment_plans.fast_grid_scan_plan.move_xyz") +@patch("bluesky.plan_stubs.rd") def test_logging_within_plan( + rd: MagicMock, move_xyz: MagicMock, run_gridscan: MagicMock, do_fgs: MagicMock, @@ -342,7 +348,11 @@ def test_GIVEN_scan_not_valid_THEN_wait_for_FGS_raises_and_sleeps_called( @patch("artemis.experiment_plans.fast_grid_scan_plan.bps.kickoff") @patch("artemis.experiment_plans.fast_grid_scan_plan.bps.complete") @patch("artemis.experiment_plans.fast_grid_scan_plan.bps.mv") +@patch("artemis.experiment_plans.fast_grid_scan_plan.bps.rd") +@patch("artemis.experiment_plans.fast_grid_scan_plan.wait_for_fgs_valid") def test_when_grid_scan_ran_then_eiger_disarmed_before_zocalo_end( + wait_for_valid, + mock_rd, mock_mv, mock_complete, mock_kickoff, From 27bee619281ad9af37f10935f35d7698ea3c970f Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 24 Mar 2023 13:45:03 +0000 Subject: [PATCH 13/23] give rd side effect --- src/artemis/unit_tests/test_fast_grid_scan_plan.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index 943876026..3993d47e9 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -167,7 +167,9 @@ def standalone_read_hardware_for_ispyb(und, syn, slits): ) @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @patch("artemis.experiment_plans.fast_grid_scan_plan.move_xyz") +@patch("bluesky.plan_stubs.rd") def test_results_adjusted_and_passed_to_move_xyz( + rd: MagicMock, move_xyz: MagicMock, run_gridscan: MagicMock, move_aperture: MagicMock, @@ -175,6 +177,7 @@ def test_results_adjusted_and_passed_to_move_xyz( mock_subscriptions: FGSCallbackCollection, test_params: InternalParameters, ): + rd.side_effect = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] RE = RunEngine({}) set_up_logging_handlers(logging_level="INFO", dev_mode=True) RE.subscribe(VerbosePlanExecutionLoggingCallback()) From 81c6fb657f396b2a1ec95fd4a748781ee1d4512c Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 24 Mar 2023 14:35:01 +0000 Subject: [PATCH 14/23] nevermind --- src/artemis/unit_tests/test_fast_grid_scan_plan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index 3993d47e9..996bb078a 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -3,6 +3,7 @@ import bluesky.plan_stubs as bps import pytest +from bluesky import Msg from bluesky.run_engine import RunEngine from dodal.devices.aperturescatterguard import AperturePositions from dodal.devices.det_dim_constants import ( @@ -177,7 +178,6 @@ def test_results_adjusted_and_passed_to_move_xyz( mock_subscriptions: FGSCallbackCollection, test_params: InternalParameters, ): - rd.side_effect = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] RE = RunEngine({}) set_up_logging_handlers(logging_level="INFO", dev_mode=True) RE.subscribe(VerbosePlanExecutionLoggingCallback()) From 0a0809f7303c235905718526327c8f3924a48472 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 24 Mar 2023 14:36:14 +0000 Subject: [PATCH 15/23] remove unused import --- src/artemis/unit_tests/test_fast_grid_scan_plan.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index 996bb078a..a9b1a1800 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -3,7 +3,6 @@ import bluesky.plan_stubs as bps import pytest -from bluesky import Msg from bluesky.run_engine import RunEngine from dodal.devices.aperturescatterguard import AperturePositions from dodal.devices.det_dim_constants import ( From 2ae14275d10f78a7ba324c26ec512589bb34fa5b Mon Sep 17 00:00:00 2001 From: David Perl Date: Mon, 27 Mar 2023 11:30:18 +0100 Subject: [PATCH 16/23] clean up mocked i03 --- src/artemis/system_tests/test_main_system.py | 2 ++ src/artemis/unit_tests/test_fast_grid_scan_plan.py | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index 1fb221c7c..af3ef9f2e 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -7,6 +7,7 @@ from unittest.mock import MagicMock, patch import pytest +from dodal import i03 from flask.testing import FlaskClient from artemis.__main__ import Actions, BlueskyRunner, Status, cli_arg_parse, create_app @@ -238,3 +239,4 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected dcm.return_value.wait_for_connection.assert_called_once() backlight.return_value.wait_for_connection.assert_called_once() aperture_scatterguard.return_value.wait_for_connection.assert_called_once() + i03.clear_devices() diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index a9b1a1800..97fda58f8 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -71,6 +71,7 @@ def fake_fgs_composite(test_params: InternalParameters): fake_composite.fast_grid_scan.scan_invalid.sim_put(False) fake_composite.fast_grid_scan.position_counter.sim_put(0) + return fake_composite @@ -116,9 +117,7 @@ def test_when_run_gridscan_called_then_generator_returned(): assert isinstance(plan, types.GeneratorType) -@patch("bluesky.plan_stubs.rd") def test_read_hardware_for_ispyb_updates_from_ophyd_devices( - rd, fake_fgs_composite: FGSComposite, ): RE = RunEngine({}) @@ -167,9 +166,7 @@ def standalone_read_hardware_for_ispyb(und, syn, slits): ) @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @patch("artemis.experiment_plans.fast_grid_scan_plan.move_xyz") -@patch("bluesky.plan_stubs.rd") def test_results_adjusted_and_passed_to_move_xyz( - rd: MagicMock, move_xyz: MagicMock, run_gridscan: MagicMock, move_aperture: MagicMock, @@ -350,11 +347,9 @@ def test_GIVEN_scan_not_valid_THEN_wait_for_FGS_raises_and_sleeps_called( @patch("artemis.experiment_plans.fast_grid_scan_plan.bps.kickoff") @patch("artemis.experiment_plans.fast_grid_scan_plan.bps.complete") @patch("artemis.experiment_plans.fast_grid_scan_plan.bps.mv") -@patch("artemis.experiment_plans.fast_grid_scan_plan.bps.rd") @patch("artemis.experiment_plans.fast_grid_scan_plan.wait_for_fgs_valid") def test_when_grid_scan_ran_then_eiger_disarmed_before_zocalo_end( wait_for_valid, - mock_rd, mock_mv, mock_complete, mock_kickoff, From 2bd568e9820afe96f8919a4f76bd9f513dd2688d Mon Sep 17 00:00:00 2001 From: David Perl Date: Mon, 27 Mar 2023 11:32:22 +0100 Subject: [PATCH 17/23] update dodal req --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 40acb7b00..16994f7e8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@76f42df09bdb1afce243096fdd24c64559ae6338 + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@98e75b52dbb8ab360d216ed95522ca81fd28a696 [options.extras_require] dev = From b260f10f25fe1bc8d0bbeebd08c70ae119af0681 Mon Sep 17 00:00:00 2001 From: David Perl Date: Mon, 27 Mar 2023 12:47:34 +0100 Subject: [PATCH 18/23] move clear devices to global conftest teardown --- src/artemis/conftest.py | 6 ++++++ src/artemis/system_tests/test_main_system.py | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 src/artemis/conftest.py diff --git a/src/artemis/conftest.py b/src/artemis/conftest.py new file mode 100644 index 000000000..c66598c30 --- /dev/null +++ b/src/artemis/conftest.py @@ -0,0 +1,6 @@ +import sys + + +def pytest_runtest_teardown(): + if "dodal.i03" in sys.modules: + sys.modules["dodal.i03"].clear_devices() diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index af3ef9f2e..1fb221c7c 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -7,7 +7,6 @@ from unittest.mock import MagicMock, patch import pytest -from dodal import i03 from flask.testing import FlaskClient from artemis.__main__ import Actions, BlueskyRunner, Status, cli_arg_parse, create_app @@ -239,4 +238,3 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected dcm.return_value.wait_for_connection.assert_called_once() backlight.return_value.wait_for_connection.assert_called_once() aperture_scatterguard.return_value.wait_for_connection.assert_called_once() - i03.clear_devices() From a3fbe1143e2ae658a621007438489ea57449ed1c Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Mon, 3 Apr 2023 16:58:35 +0100 Subject: [PATCH 19/23] (#561) Update dodal version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 16994f7e8..50b73f1c0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@98e75b52dbb8ab360d216ed95522ca81fd28a696 + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@1ccf0938f635e199f64ad8ca33ce22cb880d0677 [options.extras_require] dev = From 7df14f9c69ab079c7c13267b0ddb06bd634fe7c8 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 4 Apr 2023 08:21:02 +0100 Subject: [PATCH 20/23] remove oav and dcm from fgs composite --- .../experiment_plans/fast_grid_scan_plan.py | 6 ---- src/artemis/system_tests/test_fgs_plan.py | 34 +++++++++---------- src/artemis/system_tests/test_main_system.py | 5 +-- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 1f740dbd2..8009a93c3 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -12,8 +12,6 @@ from dodal.devices.eiger import DetectorParams from dodal.devices.fast_grid_scan import set_fast_grid_scan_params from dodal.i03 import ( - DCM, - OAV, ApertureScatterguard, Backlight, EigerDetector, @@ -53,8 +51,6 @@ class FGSComposite: """A device consisting of all the Devices required for a fast gridscan.""" - dcm: DCM - oav: OAV aperture_scatterguard: ApertureScatterguard backlight: Backlight eiger: EigerDetector @@ -71,8 +67,6 @@ def __init__( detector_params: DetectorParams = None, fake: bool = False, ): - self.dcm = i03.dcm(fake_with_ophyd_sim=fake) - self.oav = i03.oav(fake_with_ophyd_sim=fake) self.aperture_scatterguard = i03.aperture_scatterguard( fake_with_ophyd_sim=fake, aperture_positions=aperture_positions ) diff --git a/src/artemis/system_tests/test_fgs_plan.py b/src/artemis/system_tests/test_fgs_plan.py index a55964b57..a5349a6c1 100644 --- a/src/artemis/system_tests/test_fgs_plan.py +++ b/src/artemis/system_tests/test_fgs_plan.py @@ -42,24 +42,22 @@ def RE(): @pytest.fixture def fgs_composite(): - with patch("dodal.i03.dcm"): - with patch("dodal.i03.oav"): - fast_grid_scan_composite = FGSComposite( - detector_params=DetectorParams( - current_energy=100, - exposure_time=0.1, - directory="/tmp", - prefix="file_name", - detector_distance=100.0, - omega_start=0.0, - omega_increment=0.1, - num_images_per_trigger=1, - num_triggers=50, - use_roi_mode=False, - run_number=0, - det_dist_to_beam_converter_path="src/artemis/unit_tests/test_lookup_table.txt", - ) - ) + fast_grid_scan_composite = FGSComposite( + detector_params=DetectorParams( + current_energy=100, + exposure_time=0.1, + directory="/tmp", + prefix="file_name", + detector_distance=100.0, + omega_start=0.0, + omega_increment=0.1, + num_images_per_trigger=1, + num_triggers=50, + use_roi_mode=False, + run_number=0, + det_dist_to_beam_converter_path="src/artemis/unit_tests/test_lookup_table.txt", + ) + ) fgs_plan.fast_grid_scan_composite = fast_grid_scan_composite gda_beamline_parameters = GDABeamlineParameters.from_file( I03_BEAMLINE_PARAMETER_PATH diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index 1fb221c7c..be57b20ba 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -232,9 +232,10 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected synchrotron.return_value.wait_for_connection.assert_called_once() smargon.return_value.wait_for_connection.assert_called_once() s4_slits.return_value.wait_for_connection.assert_called_once() - oav.return_value.wait_for_connection.assert_called_once() fast_grid_scan.return_value.wait_for_connection.assert_called_once() eiger.return_value.wait_for_connection.assert_not_called() # can't wait on eiger - dcm.return_value.wait_for_connection.assert_called_once() backlight.return_value.wait_for_connection.assert_called_once() aperture_scatterguard.return_value.wait_for_connection.assert_called_once() + + oav.return_value.wait_for_connection.assert_not_called() # not used in fgs + dcm.return_value.wait_for_connection.assert_not_called() From ff2480be3d774f267f76cf8f13a7b7a376b92d0b Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 4 Apr 2023 08:40:40 +0100 Subject: [PATCH 21/23] update dodal req --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 50b73f1c0..a5f5831ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@1ccf0938f635e199f64ad8ca33ce22cb880d0677 + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@9f82cf522fddbdb415d36ead204ead380ab0648a [options.extras_require] dev = From 7aadb1acf22d3352883ea05ffa0ae6e9f356753d Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 5 Apr 2023 15:55:18 +0100 Subject: [PATCH 22/23] fix main system tests --- src/artemis/system_tests/test_main_system.py | 69 +++++++++++++------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index a99f9ec20..5ff766cb3 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -46,12 +46,16 @@ class ClientAndRunEngine: mock_run_engine: MockRunEngine +def mock_dict_values(d: dict): + return {k: MagicMock() for k, _ in d.items()} + + @pytest.fixture def test_env(): mock_run_engine = MockRunEngine() with patch.dict( "artemis.__main__.PLAN_REGISTRY", - {(k, MagicMock()) for k, _ in PLAN_REGISTRY.items()}, + {k: mock_dict_values(v) for k, v in PLAN_REGISTRY.items()}, ): app, runner = create_app({"TESTING": True}, mock_run_engine) runner_thread = threading.Thread(target=runner.wait_on_queue) @@ -59,7 +63,7 @@ def test_env(): with app.test_client() as client: with patch.dict( "artemis.__main__.PLAN_REGISTRY", - {(k, MagicMock()) for k, _ in PLAN_REGISTRY.items()}, + {k: mock_dict_values(v) for k, v in PLAN_REGISTRY.items()}, ): yield ClientAndRunEngine(client, mock_run_engine) @@ -210,10 +214,8 @@ def test_cli_args_parse(): @patch("dodal.i03.ApertureScatterguard") @patch("dodal.i03.Backlight") -@patch("dodal.i03.DCM") @patch("dodal.i03.EigerDetector") @patch("dodal.i03.FastGridScan") -@patch("dodal.i03.OAV") @patch("dodal.i03.S4SlitGaps") @patch("dodal.i03.Smargon") @patch("dodal.i03.Synchrotron") @@ -227,15 +229,21 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected synchrotron, smargon, s4_slits, - oav, fast_grid_scan, eiger, - dcm, backlight, aperture_scatterguard, ): BlueskyRunner(MagicMock(), skip_startup_connection=False) - mock_fgs.return_value.wait_for_connection.assert_called_once() + zebra.return_value.wait_for_connection.assert_called_once() + undulator.return_value.wait_for_connection.assert_called_once() + synchrotron.return_value.wait_for_connection.assert_called_once() + smargon.return_value.wait_for_connection.assert_called_once() + s4_slits.return_value.wait_for_connection.assert_called_once() + fast_grid_scan.return_value.wait_for_connection.assert_called_once() + eiger.return_value.wait_for_connection.assert_not_called() # can't wait on eiger + backlight.return_value.wait_for_connection.assert_called_once() + aperture_scatterguard.return_value.wait_for_connection.assert_called_once() @patch("artemis.experiment_plans.fast_grid_scan_plan.EigerDetector") @@ -253,32 +261,43 @@ def test_when_blueskyrunner_initiated_and_skip_flag_is_set_then_plans_are_setup_ @patch("artemis.experiment_plans.fast_grid_scan_plan.get_beamline_parameters") @patch("artemis.experiment_plans.fast_grid_scan_plan.create_devices") def test_when_blueskyrunner_initiated_and_skip_flag_is_set_then_setup_called_upon_start( - mock_get_beamline_params, mock_fgs, mock_eiger, mock_setup + mock_setup, mock_get_beamline_params, mock_fgs, mock_eiger ): - runner = BlueskyRunner(MagicMock(), skip_startup_connection=True) - mock_setup.assert_not_called() - runner.start(MagicMock(), MagicMock(), "fast_grid_scan") - mock_setup.assert_called_once() - zebra.return_value.wait_for_connection.assert_called_once() - undulator.return_value.wait_for_connection.assert_called_once() - synchrotron.return_value.wait_for_connection.assert_called_once() - smargon.return_value.wait_for_connection.assert_called_once() - s4_slits.return_value.wait_for_connection.assert_called_once() - fast_grid_scan.return_value.wait_for_connection.assert_called_once() - eiger.return_value.wait_for_connection.assert_not_called() # can't wait on eiger - backlight.return_value.wait_for_connection.assert_called_once() - aperture_scatterguard.return_value.wait_for_connection.assert_called_once() + mock_setup = MagicMock() + with patch.dict( + "artemis.__main__.PLAN_REGISTRY", + { + "fast_grid_scan": { + "setup": mock_setup, + "run": MagicMock(), + "param_type": MagicMock(), + }, + }, + ): + runner = BlueskyRunner(MagicMock(), skip_startup_connection=True) + mock_setup.assert_not_called() + runner.start(MagicMock(), MagicMock(), "fast_grid_scan") + mock_setup.assert_called_once() @patch("artemis.experiment_plans.fast_grid_scan_plan.EigerDetector") @patch("artemis.experiment_plans.fast_grid_scan_plan.FGSComposite") @patch("artemis.experiment_plans.fast_grid_scan_plan.get_beamline_parameters") -@patch("artemis.experiment_plans.fast_grid_scan_plan.create_devices") def test_when_blueskyrunner_initiated_and_skip_flag_is_not_set_then_all_plans_setup( mock_get_beamline_params, mock_fgs, mock_eiger, - mock_setup, ): - BlueskyRunner(MagicMock(), skip_startup_connection=False) - mock_setup.assert_called() + mock_setup = MagicMock() + with patch.dict( + "artemis.__main__.PLAN_REGISTRY", + { + "fast_grid_scan": { + "setup": mock_setup, + "run": MagicMock(), + "param_type": MagicMock(), + }, + }, + ): + BlueskyRunner(MagicMock(), skip_startup_connection=False) + mock_setup.assert_called() From 2f5324e0c5536e7b5310e131ede99bf5c01cf629 Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 5 Apr 2023 16:01:45 +0100 Subject: [PATCH 23/23] make test better reflect name --- src/artemis/system_tests/test_main_system.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index 5ff766cb3..cb4a1d91b 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -297,7 +297,17 @@ def test_when_blueskyrunner_initiated_and_skip_flag_is_not_set_then_all_plans_se "run": MagicMock(), "param_type": MagicMock(), }, + "other_plan": { + "setup": mock_setup, + "run": MagicMock(), + "param_type": MagicMock(), + }, + "yet_another_plan": { + "setup": mock_setup, + "run": MagicMock(), + "param_type": MagicMock(), + }, }, ): BlueskyRunner(MagicMock(), skip_startup_connection=False) - mock_setup.assert_called() + assert mock_setup.call_count == 3