From aef44e7785776e9fd41ce59d4e019e02d0b0e1e5 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Fri, 24 Jan 2025 14:02:11 +0000 Subject: [PATCH 1/9] Fixes for ophyd-async 0.9.0a2 --- pyproject.toml | 2 +- src/dodal/beamlines/adsim.py | 2 +- src/dodal/beamlines/b01_1.py | 2 +- src/dodal/beamlines/i13_1.py | 4 ++-- src/dodal/beamlines/i22.py | 6 +++--- src/dodal/beamlines/p38.py | 6 +++--- src/dodal/beamlines/p45.py | 4 ++-- src/dodal/beamlines/training_rig.py | 2 +- src/dodal/devices/i13_1/merlin.py | 4 ++-- src/dodal/devices/i22/nxsas.py | 8 ++++---- src/dodal/devices/motors.py | 4 ++-- .../test_aperturescatterguard_system.py | 4 ++-- system_tests/test_oav_system.py | 4 ++-- system_tests/test_oav_to_redis_system.py | 4 ++-- system_tests/test_undulator_system.py | 4 ++-- tests/devices/i04/test_transfocator.py | 4 ++-- tests/devices/i10/test_i10Apple2.py | 18 +++++++++--------- tests/devices/i13_1/test_merlin.py | 6 +++--- tests/devices/i22/test_dcm.py | 4 ++-- tests/devices/i22/test_fswitch.py | 4 ++-- tests/devices/i22/test_metadataholder.py | 6 +++--- tests/devices/test_diamond_filter.py | 6 +++--- .../devices/training_rig/test_sample_stage.py | 4 ++-- .../unit_tests/current_amplifier/test_femto.py | 8 ++++---- .../unit_tests/current_amplifier/test_sr570.py | 8 ++++---- tests/devices/unit_tests/oav/conftest.py | 4 ++-- .../oav/test_oav_to_redis_forwarder.py | 4 ++-- tests/devices/unit_tests/oav/test_snapshots.py | 6 +++--- tests/devices/unit_tests/p99/test_p99_stage.py | 6 +++--- .../unit_tests/test_aperture_scatterguard.py | 4 ++-- .../unit_tests/test_apple2_undulator.py | 8 ++++---- tests/devices/unit_tests/test_attenuator.py | 4 ++-- tests/devices/unit_tests/test_backlight.py | 4 ++-- .../devices/unit_tests/test_bimorph_mirror.py | 4 ++-- tests/devices/unit_tests/test_dcm.py | 4 ++-- .../devices/unit_tests/test_focusing_mirror.py | 8 ++++---- tests/devices/unit_tests/test_gridscan.py | 6 +++--- tests/devices/unit_tests/test_linkam3.py | 4 ++-- .../unit_tests/test_pressure_jump_cell.py | 4 ++-- tests/devices/unit_tests/test_qbpm.py | 4 ++-- tests/devices/unit_tests/test_shutter.py | 4 ++-- tests/devices/unit_tests/test_slits.py | 4 ++-- tests/devices/unit_tests/test_smargon.py | 4 ++-- tests/devices/unit_tests/test_synchrotron.py | 4 ++-- tests/devices/unit_tests/test_tetramm.py | 8 ++++---- tests/devices/unit_tests/test_thawer.py | 4 ++-- tests/devices/unit_tests/test_undulator.py | 8 ++++---- tests/devices/unit_tests/test_undulator_dcm.py | 4 ++-- .../unit_tests/test_watsonmarlow323_pump.py | 4 ++-- tests/devices/unit_tests/test_xbpm_feedback.py | 4 ++-- tests/devices/unit_tests/test_xspress3.py | 4 ++-- .../unit_tests/test_zebra_constants_mapping.py | 4 ++-- tests/plan_stubs/test_motor_util_plans.py | 6 +++--- tests/plan_stubs/test_wrapped_stubs.py | 8 ++++---- tests/plans/conftest.py | 10 +++++----- tests/plans/test_scanspec.py | 2 +- .../preprocessors/test_filesystem_metadata.py | 4 ++-- 57 files changed, 144 insertions(+), 144 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 28093ed942..7c1443543e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ description = "Ophyd devices and other utils that could be used across DLS beaml dependencies = [ "click", "ophyd", - "ophyd-async >= 0.9.0a1", + "ophyd-async >= 0.9.0a2", "bluesky", "pyepics", "dataclasses-json", diff --git a/src/dodal/beamlines/adsim.py b/src/dodal/beamlines/adsim.py index 6d99b16d3a..e9b60bb443 100644 --- a/src/dodal/beamlines/adsim.py +++ b/src/dodal/beamlines/adsim.py @@ -71,5 +71,5 @@ def det() -> SimDetector: f"{PREFIX.beamline_prefix}-DI-CAM-01:", path_provider=get_path_provider(), drv_suffix="DET:", - hdf_suffix="HDF:", + fileio_suffix="HDF:", ) diff --git a/src/dodal/beamlines/b01_1.py b/src/dodal/beamlines/b01_1.py index 27aab36ba1..5156abb86a 100644 --- a/src/dodal/beamlines/b01_1.py +++ b/src/dodal/beamlines/b01_1.py @@ -58,5 +58,5 @@ def manta() -> AravisDetector: f"{PREFIX.beamline_prefix}-DI-DCAM-02:", path_provider=get_path_provider(), drv_suffix="CAM:", - hdf_suffix=HDF5_PREFIX, + fileio_suffix=HDF5_PREFIX, ) diff --git a/src/dodal/beamlines/i13_1.py b/src/dodal/beamlines/i13_1.py index c32be50d1b..78cb9e2cd0 100644 --- a/src/dodal/beamlines/i13_1.py +++ b/src/dodal/beamlines/i13_1.py @@ -61,7 +61,7 @@ def side_camera( name="side_camera", bl_prefix=False, drv_suffix="CAM:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), wait=wait_for_connection, fake=fake_with_ophyd_sim, @@ -77,7 +77,7 @@ def merlin( name="merlin", bl_prefix=False, drv_suffix="CAM:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), wait=wait_for_connection, fake=fake_with_ophyd_sim, diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index b80c12e03e..58a9a14a78 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -64,7 +64,7 @@ def saxs() -> PilatusDetector: prefix=f"{PREFIX.beamline_prefix}-EA-PILAT-01:", path_provider=get_path_provider(), drv_suffix="CAM:", - hdf_suffix=HDF5_PREFIX, + fileio_suffix=HDF5_PREFIX, metadata_holder=metadata_holder, ) @@ -89,7 +89,7 @@ def waxs() -> PilatusDetector: prefix=f"{PREFIX.beamline_prefix}-EA-PILAT-03:", path_provider=get_path_provider(), drv_suffix="CAM:", - hdf_suffix=HDF5_PREFIX, + fileio_suffix=HDF5_PREFIX, metadata_holder=metadata_holder, ) @@ -249,7 +249,7 @@ def oav() -> AravisDetector: return NXSasOAV( prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:", drv_suffix="DET:", - hdf_suffix=HDF5_PREFIX, + fileio_suffix=HDF5_PREFIX, path_provider=get_path_provider(), metadata_holder=metadata_holder, ) diff --git a/src/dodal/beamlines/p38.py b/src/dodal/beamlines/p38.py index 30cb2e5a99..6e9f947b84 100644 --- a/src/dodal/beamlines/p38.py +++ b/src/dodal/beamlines/p38.py @@ -55,7 +55,7 @@ def d3( wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), ) @@ -72,7 +72,7 @@ def d11( wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), ) @@ -87,7 +87,7 @@ def d12( wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), ) diff --git a/src/dodal/beamlines/p45.py b/src/dodal/beamlines/p45.py index 4a55060f38..3abdb71560 100644 --- a/src/dodal/beamlines/p45.py +++ b/src/dodal/beamlines/p45.py @@ -61,7 +61,7 @@ def det( wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), ) @@ -78,7 +78,7 @@ def diff( wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", path_provider=get_path_provider(), ) diff --git a/src/dodal/beamlines/training_rig.py b/src/dodal/beamlines/training_rig.py index 7a75d14903..685e1a4bd7 100644 --- a/src/dodal/beamlines/training_rig.py +++ b/src/dodal/beamlines/training_rig.py @@ -51,7 +51,7 @@ def det() -> AravisDetector: f"{PREFIX.beamline_prefix}-EA-DET-01:", path_provider=get_path_provider(), drv_suffix="DET:", - hdf_suffix=HDF5_PREFIX, + fileio_suffix=HDF5_PREFIX, ) diff --git a/src/dodal/devices/i13_1/merlin.py b/src/dodal/devices/i13_1/merlin.py index 940175f127..81d954b4f1 100644 --- a/src/dodal/devices/i13_1/merlin.py +++ b/src/dodal/devices/i13_1/merlin.py @@ -14,11 +14,11 @@ def __init__( prefix: str, path_provider: PathProvider, drv_suffix="CAM:", - hdf_suffix="HDF:", + fileio_suffix="HDF:", name: str = "", ): self.drv = MerlinDriverIO(prefix + drv_suffix) - self.hdf = adcore.NDFileHDFIO(prefix + hdf_suffix) + self.hdf = adcore.NDFileHDFIO(prefix + fileio_suffix) super().__init__( MerlinController(self.drv), diff --git a/src/dodal/devices/i22/nxsas.py b/src/dodal/devices/i22/nxsas.py index 8520a85cf3..7be245f210 100644 --- a/src/dodal/devices/i22/nxsas.py +++ b/src/dodal/devices/i22/nxsas.py @@ -103,7 +103,7 @@ def __init__( prefix: str, path_provider: PathProvider, drv_suffix: str, - hdf_suffix: str, + fileio_suffix: str, metadata_holder: NXSasMetadataHolder, name: str = "", ): @@ -116,7 +116,7 @@ def __init__( prefix, path_provider, drv_suffix=drv_suffix, - hdf_suffix=hdf_suffix, + fileio_suffix=fileio_suffix, name=name, ) self._metadata_holder = metadata_holder @@ -146,7 +146,7 @@ def __init__( prefix: str, path_provider: PathProvider, drv_suffix: str, - hdf_suffix: str, + fileio_suffix: str, metadata_holder: NXSasMetadataHolder, name: str = "", gpio_number: AravisController.GPIO_NUMBER = 1, @@ -160,7 +160,7 @@ def __init__( prefix, path_provider, drv_suffix=drv_suffix, - hdf_suffix=hdf_suffix, + fileio_suffix=fileio_suffix, name=name, gpio_number=gpio_number, ) diff --git a/src/dodal/devices/motors.py b/src/dodal/devices/motors.py index c7b7911d91..18a2c1af39 100644 --- a/src/dodal/devices/motors.py +++ b/src/dodal/devices/motors.py @@ -19,10 +19,10 @@ class XYZPositioner(StandardReadable): Notes ----- Example usage:: - async with DeviceCollector(): + async with init_devices(): xyz_stage = XYZPositioner("BLXX-MO-STAGE-XX:") Or:: - with DeviceCollector(): + with init_devices(): xyz_stage = XYZPositioner("BLXX-MO-STAGE-XX:", infix = ("A", "B", "C")) """ diff --git a/system_tests/test_aperturescatterguard_system.py b/system_tests/test_aperturescatterguard_system.py index ba62f6a1e4..974c578255 100644 --- a/system_tests/test_aperturescatterguard_system.py +++ b/system_tests/test_aperturescatterguard_system.py @@ -5,7 +5,7 @@ from bluesky.callbacks import CallbackBase from bluesky.run_engine import RunEngine from event_model import Event -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from dodal.common.beamlines.beamline_parameters import GDABeamlineParameters from dodal.devices.aperturescatterguard import ( @@ -28,7 +28,7 @@ async def ap_sg(): positions = load_positions_from_beamline_parameters(params) tolerances = AperturePosition.tolerances_from_gda_params(params) - async with DeviceCollector(): + async with init_devices(): ap_sg = ApertureScatterguard( prefix="BL03S", name="ap_sg", diff --git a/system_tests/test_oav_system.py b/system_tests/test_oav_system.py index 3cdc816046..6fc5e4bc20 100644 --- a/system_tests/test_oav_system.py +++ b/system_tests/test_oav_system.py @@ -1,7 +1,7 @@ import bluesky.plan_stubs as bps import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from dodal.devices.oav.oav_detector import OAV, OAVConfig, ZoomController @@ -19,7 +19,7 @@ @pytest.fixture async def oav() -> OAV: oav_config = OAVConfig(ZOOM_LEVELS_XML, DISPLAY_CONFIGURATION) - async with DeviceCollector(connect=True): + async with init_devices(connect=True): oav = OAV("", config=oav_config, name="oav") return oav diff --git a/system_tests/test_oav_to_redis_system.py b/system_tests/test_oav_to_redis_system.py index ea0ca62aa3..6b4be183d8 100644 --- a/system_tests/test_oav_to_redis_system.py +++ b/system_tests/test_oav_to_redis_system.py @@ -3,14 +3,14 @@ import pytest from aiohttp.client_exceptions import ClientConnectorError -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source def _oav_to_redis_forwarder(mock): - with DeviceCollector(mock=mock): + with init_devices(mock=mock): oav_forwarder = OAVToRedisForwarder("BL04I-DI-OAV-01:", "", "") oav_forwarder.redis_client.hset = AsyncMock() oav_forwarder.redis_client.expire = AsyncMock() diff --git a/system_tests/test_undulator_system.py b/system_tests/test_undulator_system.py index 8ad4c7ce29..3c3d1989db 100644 --- a/system_tests/test_undulator_system.py +++ b/system_tests/test_undulator_system.py @@ -1,5 +1,5 @@ import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from dodal.devices.undulator import Undulator @@ -12,7 +12,7 @@ @pytest.mark.s03 def test_undulator_connects(): - with DeviceCollector(): + with init_devices(): undulator = Undulator( # noqa: F841 f"{SIM_INSERTION_PREFIX}-MO-SERVC-01:", id_gap_lookup_table_path=ID_GAP_LOOKUP_TABLE_PATH, diff --git a/tests/devices/i04/test_transfocator.py b/tests/devices/i04/test_transfocator.py index 313be37b51..4517a27101 100644 --- a/tests/devices/i04/test_transfocator.py +++ b/tests/devices/i04/test_transfocator.py @@ -3,7 +3,7 @@ import pytest from ophyd_async.core import ( - DeviceCollector, + init_devices, wait_for_value, ) from ophyd_async.testing import set_mock_value @@ -13,7 +13,7 @@ @pytest.fixture async def fake_transfocator() -> Transfocator: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): transfocator = Transfocator(prefix="", name="transfocator") return transfocator diff --git a/tests/devices/i10/test_i10Apple2.py b/tests/devices/i10/test_i10Apple2.py index 9960f42756..6ec93b8712 100644 --- a/tests/devices/i10/test_i10Apple2.py +++ b/tests/devices/i10/test_i10Apple2.py @@ -9,7 +9,7 @@ from bluesky.plans import scan from bluesky.run_engine import RunEngine from numpy import poly1d -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( assert_emitted, callback_on_mock_put, @@ -40,7 +40,7 @@ @pytest.fixture async def mock_id_gap(prefix: str = "BLXX-EA-DET-007:") -> UndulatorGap: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_id_gap = UndulatorGap(prefix, "mock_id_gap") assert mock_id_gap.name == "mock_id_gap" set_mock_value(mock_id_gap.gate, UndulatorGateStatus.CLOSE) @@ -53,7 +53,7 @@ async def mock_id_gap(prefix: str = "BLXX-EA-DET-007:") -> UndulatorGap: @pytest.fixture async def mock_phaseAxes(prefix: str = "BLXX-EA-DET-007:") -> UndulatorPhaseAxes: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_phaseAxes = UndulatorPhaseAxes( prefix=prefix, top_outer="RPQ1", @@ -81,14 +81,14 @@ async def mock_phaseAxes(prefix: str = "BLXX-EA-DET-007:") -> UndulatorPhaseAxes @pytest.fixture async def mock_pgm(prefix: str = "BLXX-EA-DET-007:") -> PGM: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_pgm = PGM(prefix=prefix, grating=I10Grating, gratingPv="NLINES2") return mock_pgm @pytest.fixture async def mock_jaw_phase(prefix: str = "BLXX-EA-DET-007:") -> UndulatorJawPhase: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_jaw_phase = UndulatorJawPhase( prefix=prefix, move_pv="RPQ1", jaw_phase="JAW" ) @@ -105,7 +105,7 @@ async def mock_id( mock_id_gap: UndulatorGap, mock_jaw_phase: UndulatorJawPhase, ) -> I10Apple2: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_id = I10Apple2( id_gap=mock_id_gap, id_phase=mock_phaseAxes, @@ -119,7 +119,7 @@ async def mock_id( @pytest.fixture async def mock_id_pgm(mock_id: I10Apple2, mock_pgm: PGM) -> I10Apple2PGM: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_id_pgm = I10Apple2PGM(id=mock_id, pgm=mock_pgm) set_mock_value(mock_id_pgm.pgm_ref().energy.velocity, 1) return mock_id_pgm @@ -127,7 +127,7 @@ async def mock_id_pgm(mock_id: I10Apple2, mock_pgm: PGM) -> I10Apple2PGM: @pytest.fixture async def mock_id_pol(mock_id: I10Apple2) -> I10Apple2Pol: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_id_pol = I10Apple2Pol(id=mock_id) return mock_id_pol @@ -137,7 +137,7 @@ async def mock_id_pol(mock_id: I10Apple2) -> I10Apple2Pol: async def mock_linear_arbitrary_angle( mock_id: I10Apple2, prefix: str = "BLXX-EA-DET-007:" ) -> LinearArbitraryAngle: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_linear_arbitrary_angle = LinearArbitraryAngle(id=mock_id) return mock_linear_arbitrary_angle diff --git a/tests/devices/i13_1/test_merlin.py b/tests/devices/i13_1/test_merlin.py index 2332f9f6c5..1b2db52d0f 100644 --- a/tests/devices/i13_1/test_merlin.py +++ b/tests/devices/i13_1/test_merlin.py @@ -4,9 +4,9 @@ from event_model import StreamDatum, StreamResource from ophyd_async.core import ( DetectorTrigger, - DeviceCollector, PathProvider, TriggerInfo, + init_devices, ) from ophyd_async.testing import set_mock_value @@ -26,12 +26,12 @@ def one_shot_trigger_info() -> TriggerInfo: @pytest.fixture async def merlin(static_path_provider: PathProvider) -> Merlin: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): merlin = Merlin( prefix="BL13J-EA-DET-04", # name="merlin", # drv_suffix="CAM:", - # hdf_suffix="HDF5:", + # fileio_suffix="HDF5:", path_provider=static_path_provider, ) diff --git a/tests/devices/i22/test_dcm.py b/tests/devices/i22/test_dcm.py index cd8dd0ebbc..651a0d9fdd 100644 --- a/tests/devices/i22/test_dcm.py +++ b/tests/devices/i22/test_dcm.py @@ -4,7 +4,7 @@ import bluesky.plans as bp import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( assert_configuration, assert_emitted, @@ -23,7 +23,7 @@ async def dcm() -> DoubleCrystalMonochromator: metadata_1 = make_crystal_metadata_from_material(MaterialsEnum.Si, (1, 1, 1)) metadata_2 = make_crystal_metadata_from_material(MaterialsEnum.Si, (1, 1, 1)) - async with DeviceCollector(mock=True): + async with init_devices(mock=True): dcm = DoubleCrystalMonochromator( prefix="FOO-MO", temperature_prefix="FOO-DI", diff --git a/tests/devices/i22/test_fswitch.py b/tests/devices/i22/test_fswitch.py index fbf4218775..2bc4264f2f 100644 --- a/tests/devices/i22/test_fswitch.py +++ b/tests/devices/i22/test_fswitch.py @@ -4,7 +4,7 @@ from bluesky.plans import count from bluesky.run_engine import RunEngine from event_model import DataKey -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.i22.fswitch import FilterState, FSwitch @@ -12,7 +12,7 @@ @pytest.fixture async def fswitch() -> FSwitch: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): fswitch = FSwitch( "DEMO-FSWT-01:", lens_geometry="paraboloid", diff --git a/tests/devices/i22/test_metadataholder.py b/tests/devices/i22/test_metadataholder.py index 74fcf87ebb..b5d4c13a02 100644 --- a/tests/devices/i22/test_metadataholder.py +++ b/tests/devices/i22/test_metadataholder.py @@ -1,5 +1,5 @@ import pytest -from ophyd_async.core import DeviceCollector, PathProvider +from ophyd_async.core import PathProvider, init_devices from ophyd_async.epics.adpilatus import PilatusDetector from dodal.devices.i22.nxsas import NXSasMetadataHolder, NXSasPilatus @@ -7,11 +7,11 @@ @pytest.fixture def saxs(static_path_provider: PathProvider, RE) -> PilatusDetector: - with DeviceCollector(mock=True): + with init_devices(mock=True): saxs = NXSasPilatus( prefix="-EA-PILAT-01:", drv_suffix="CAM:", - hdf_suffix="HDF5:", + fileio_suffix="HDF5:", metadata_holder=NXSasMetadataHolder( x_pixel_size=(1.72e-1, "mm"), y_pixel_size=(1.72e-1, "mm"), diff --git a/tests/devices/test_diamond_filter.py b/tests/devices/test_diamond_filter.py index f1a3d6d738..3692867d58 100644 --- a/tests/devices/test_diamond_filter.py +++ b/tests/devices/test_diamond_filter.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import assert_reading from dodal.devices.diamond_filter import DiamondFilter, I03Filters, I04Filters @@ -9,14 +9,14 @@ @pytest.fixture async def i03_diamond_filter() -> DiamondFilter[I03Filters]: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): i03_diamond_filter = DiamondFilter("", I03Filters, name="diamond_filter") return i03_diamond_filter @pytest.fixture async def i04_diamond_filter() -> DiamondFilter[I04Filters]: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): i04_diamond_filter = DiamondFilter("", I04Filters, name="diamond_filter") return i04_diamond_filter diff --git a/tests/devices/training_rig/test_sample_stage.py b/tests/devices/training_rig/test_sample_stage.py index 16ab15a295..739f1127c2 100644 --- a/tests/devices/training_rig/test_sample_stage.py +++ b/tests/devices/training_rig/test_sample_stage.py @@ -1,14 +1,14 @@ from unittest import mock import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from dodal.devices.training_rig.sample_stage import TrainingRigSampleStage @pytest.fixture async def stage() -> TrainingRigSampleStage: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): stage = TrainingRigSampleStage(prefix="DEMO-STAGE-01:") return stage diff --git a/tests/devices/unit_tests/current_amplifier/test_femto.py b/tests/devices/unit_tests/current_amplifier/test_femto.py index a645f878c5..3461361511 100644 --- a/tests/devices/unit_tests/current_amplifier/test_femto.py +++ b/tests/devices/unit_tests/current_amplifier/test_femto.py @@ -7,7 +7,7 @@ from bluesky.plan_stubs import abs_set from bluesky.plans import count from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( callback_on_mock_put, get_mock_put, @@ -33,7 +33,7 @@ async def mock_femto( prefix: str = "BLXX-EA-DET-007:", suffix: str = "Gain" ) -> FemtoDDPCA: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_femto = FemtoDDPCA( prefix=prefix, suffix=suffix, @@ -50,7 +50,7 @@ async def mock_femto( async def mock_StruckScaler( prefix: str = "BLXX-EA-DET-007:", suffix: str = ".s17" ) -> StruckScaler: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_StruckScaler = StruckScaler( prefix=prefix, suffix=suffix, @@ -66,7 +66,7 @@ async def mock_femto_struck_scaler_detector( mock_femto: FemtoDDPCA, prefix: str = "BLXX-EA-DET-007:", ) -> CurrentAmpDet: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_femto_struck_scaler_detector = CurrentAmpDet( current_amp=mock_femto, counter=mock_StruckScaler, diff --git a/tests/devices/unit_tests/current_amplifier/test_sr570.py b/tests/devices/unit_tests/current_amplifier/test_sr570.py index 3d304dbb3f..ec3a391b18 100644 --- a/tests/devices/unit_tests/current_amplifier/test_sr570.py +++ b/tests/devices/unit_tests/current_amplifier/test_sr570.py @@ -8,7 +8,7 @@ from bluesky.plans import count from bluesky.run_engine import RunEngine from ophyd_async.core import ( - DeviceCollector, + init_devices, ) from ophyd_async.testing import callback_on_mock_put, set_mock_value @@ -31,7 +31,7 @@ @pytest.fixture async def mock_sr570(prefix: str = "BLXX-EA-DET-007:", suffix: str = "Gain") -> SR570: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_sr570 = SR570( prefix, suffix=suffix, @@ -52,7 +52,7 @@ async def mock_sr570(prefix: str = "BLXX-EA-DET-007:", suffix: str = "Gain") -> async def mock_StruckScaler( prefix: str = "BLXX-EA-DET-007:", suffix: str = ".s17" ) -> StruckScaler: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_StruckScaler = StruckScaler( prefix=prefix, suffix=suffix, @@ -68,7 +68,7 @@ async def mock_sr570_struck_scaler_detector( mock_sr570: SR570, prefix: str = "BLXX-EA-DET-007:", ) -> CurrentAmpDet: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_sr570_struck_scaler_detector = CurrentAmpDet( current_amp=mock_sr570, counter=mock_StruckScaler, diff --git a/tests/devices/unit_tests/oav/conftest.py b/tests/devices/unit_tests/oav/conftest.py index 713bba134a..d4d3f4944c 100644 --- a/tests/devices/unit_tests/oav/conftest.py +++ b/tests/devices/unit_tests/oav/conftest.py @@ -1,7 +1,7 @@ from unittest.mock import AsyncMock import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.oav.oav_detector import OAV @@ -14,7 +14,7 @@ @pytest.fixture async def oav() -> OAV: oav_config = OAVConfig(ZOOM_LEVELS_XML, DISPLAY_CONFIGURATION) - async with DeviceCollector(mock=True, connect=True): + async with init_devices(mock=True, connect=True): oav = OAV("", config=oav_config, name="fake_oav") zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x"] oav.zoom_controller.level.describe = AsyncMock( diff --git a/tests/devices/unit_tests/oav/test_oav_to_redis_forwarder.py b/tests/devices/unit_tests/oav/test_oav_to_redis_forwarder.py index 0983621f2c..3df2982fc9 100644 --- a/tests/devices/unit_tests/oav/test_oav_to_redis_forwarder.py +++ b/tests/devices/unit_tests/oav/test_oav_to_redis_forwarder.py @@ -3,7 +3,7 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.oav.oav_to_redis_forwarder import ( @@ -16,7 +16,7 @@ @pytest.fixture @patch("dodal.devices.oav.oav_to_redis_forwarder.StrictRedis", new=AsyncMock) async def oav_forwarder(RE): - with DeviceCollector(mock=True): + with init_devices(mock=True): oav_forwarder = OAVToRedisForwarder("prefix", "host", "password") set_mock_value( oav_forwarder.sources[Source.FULL_SCREEN.value].url, diff --git a/tests/devices/unit_tests/oav/test_snapshots.py b/tests/devices/unit_tests/oav/test_snapshots.py index 0332dca9d2..794640edd5 100644 --- a/tests/devices/unit_tests/oav/test_snapshots.py +++ b/tests/devices/unit_tests/oav/test_snapshots.py @@ -3,7 +3,7 @@ import pytest from ophyd_async.core import ( - DeviceCollector, + init_devices, soft_signal_r_and_setter, ) from ophyd_async.testing import set_mock_value @@ -29,7 +29,7 @@ async def create_and_set_mock_signal_r(dtype, name, value): async def snapshot() -> SnapshotWithBeamCentre: mock_beam_x = await create_and_set_mock_signal_r(int, "mock_beam_x", 510) mock_beam_y = await create_and_set_mock_signal_r(int, "mock_beam_y", 380) - async with DeviceCollector(mock=True): + async with init_devices(mock=True): snapshot = SnapshotWithBeamCentre("", mock_beam_x, mock_beam_y, "fake_snapshot") set_mock_value(snapshot.directory, "/tmp/") set_mock_value(snapshot.filename, "test") @@ -39,7 +39,7 @@ async def snapshot() -> SnapshotWithBeamCentre: @pytest.fixture async def grid_snapshot() -> SnapshotWithGrid: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): grid_snapshot = SnapshotWithGrid("", "fake_grid") set_mock_value(grid_snapshot.top_left_x, 100) diff --git a/tests/devices/unit_tests/p99/test_p99_stage.py b/tests/devices/unit_tests/p99/test_p99_stage.py index 5bbb5d45b5..5b891bd5a9 100644 --- a/tests/devices/unit_tests/p99/test_p99_stage.py +++ b/tests/devices/unit_tests/p99/test_p99_stage.py @@ -1,5 +1,5 @@ import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.attenuator.filter import FilterMotor @@ -15,7 +15,7 @@ @pytest.fixture async def sim_sampleAngleStage(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): sim_sampleAngleStage = SampleAngleStage( "p99-MO-TABLE-01:", name="sim_sampleAngleStage" ) @@ -25,7 +25,7 @@ async def sim_sampleAngleStage(): @pytest.fixture async def sim_filter_wheel(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): sim_filter_wheel = FilterMotor( "p99-MO-TABLE-01:", P99FilterSelections, diff --git a/tests/devices/unit_tests/test_aperture_scatterguard.py b/tests/devices/unit_tests/test_aperture_scatterguard.py index a1ced3eec8..4b596f8b90 100644 --- a/tests/devices/unit_tests/test_aperture_scatterguard.py +++ b/tests/devices/unit_tests/test_aperture_scatterguard.py @@ -6,7 +6,7 @@ import bluesky.plan_stubs as bps import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( callback_on_mock_put, get_mock_put, @@ -88,7 +88,7 @@ async def ap_sg_and_call_log( aperture_tolerances: AperturePosition, ): call_log = MagicMock() - async with DeviceCollector(mock=True): + async with init_devices(mock=True): ap_sg = ApertureScatterguard( name="test_ap_sg", loaded_positions=aperture_positions, diff --git a/tests/devices/unit_tests/test_apple2_undulator.py b/tests/devices/unit_tests/test_apple2_undulator.py index 57df343044..80afbbb948 100644 --- a/tests/devices/unit_tests/test_apple2_undulator.py +++ b/tests/devices/unit_tests/test_apple2_undulator.py @@ -6,7 +6,7 @@ import pytest from bluesky.plans import scan from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( assert_emitted, callback_on_mock_put, @@ -25,7 +25,7 @@ @pytest.fixture async def mock_id_gap(prefix: str = "BLXX-EA-DET-007:") -> UndulatorGap: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_id_gap = UndulatorGap(prefix, "mock_id_gap") assert mock_id_gap.name == "mock_id_gap" set_mock_value(mock_id_gap.gate, UndulatorGateStatus.CLOSE) @@ -38,7 +38,7 @@ async def mock_id_gap(prefix: str = "BLXX-EA-DET-007:") -> UndulatorGap: @pytest.fixture async def mock_phaseAxes(prefix: str = "BLXX-EA-DET-007:") -> UndulatorPhaseAxes: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_phaseAxes = UndulatorPhaseAxes( prefix=prefix, top_outer="RPQ1", @@ -66,7 +66,7 @@ async def mock_phaseAxes(prefix: str = "BLXX-EA-DET-007:") -> UndulatorPhaseAxes @pytest.fixture async def mock_jaw_phase(prefix: str = "BLXX-EA-DET-007:") -> UndulatorJawPhase: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_jaw_phase = UndulatorJawPhase( prefix=prefix, move_pv="RPQ1", jaw_phase="JAW" ) diff --git a/tests/devices/unit_tests/test_attenuator.py b/tests/devices/unit_tests/test_attenuator.py index 40a14c87bd..47286a6d4a 100644 --- a/tests/devices/unit_tests/test_attenuator.py +++ b/tests/devices/unit_tests/test_attenuator.py @@ -3,7 +3,7 @@ import pytest from bluesky import plan_stubs as bps from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import callback_on_mock_put, set_mock_value from dodal.devices.attenuator.attenuator import BinaryFilterAttenuator @@ -13,7 +13,7 @@ @pytest.fixture async def fake_attenuator(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): fake_attenuator: BinaryFilterAttenuator = BinaryFilterAttenuator( "", "attenuator" ) diff --git a/tests/devices/unit_tests/test_backlight.py b/tests/devices/unit_tests/test_backlight.py index 33667a53ac..45ef9cfcd2 100644 --- a/tests/devices/unit_tests/test_backlight.py +++ b/tests/devices/unit_tests/test_backlight.py @@ -3,7 +3,7 @@ import pytest from bluesky import plan_stubs as bps from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import assert_reading, set_mock_value from dodal.devices.backlight import Backlight, BacklightPosition, BacklightPower @@ -11,7 +11,7 @@ @pytest.fixture def fake_backlight(RE: RunEngine): - with DeviceCollector(mock=True): + with init_devices(mock=True): backlight = Backlight("", "backlight") return backlight diff --git a/tests/devices/unit_tests/test_bimorph_mirror.py b/tests/devices/unit_tests/test_bimorph_mirror.py index 3caa42029d..7c1b5d39ee 100644 --- a/tests/devices/unit_tests/test_bimorph_mirror.py +++ b/tests/devices/unit_tests/test_bimorph_mirror.py @@ -2,7 +2,7 @@ import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import get_mock_put from dodal.devices.bimorph_mirror import BimorphMirror, BimorphMirrorStatus @@ -14,7 +14,7 @@ def mirror(request, RE: RunEngine) -> BimorphMirror: number_of_channels = request.param - with DeviceCollector(mock=True): + with init_devices(mock=True): bm = BimorphMirror( prefix="FAKE-PREFIX:", number_of_channels=number_of_channels, diff --git a/tests/devices/unit_tests/test_dcm.py b/tests/devices/unit_tests/test_dcm.py index 6c5c09fda5..63dba64c9e 100644 --- a/tests/devices/unit_tests/test_dcm.py +++ b/tests/devices/unit_tests/test_dcm.py @@ -1,6 +1,6 @@ import pytest from ophyd_async.core import ( - DeviceCollector, + init_devices, ) from dodal.devices.dcm import DCM @@ -8,7 +8,7 @@ @pytest.fixture async def dcm() -> DCM: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): dcm = DCM("DCM-01", name="dcm") return dcm diff --git a/tests/devices/unit_tests/test_focusing_mirror.py b/tests/devices/unit_tests/test_focusing_mirror.py index 0ad91ee5e0..7a91caa797 100644 --- a/tests/devices/unit_tests/test_focusing_mirror.py +++ b/tests/devices/unit_tests/test_focusing_mirror.py @@ -10,7 +10,7 @@ from bluesky import plan_stubs as bps from bluesky.run_engine import RunEngine from bluesky.utils import FailedStatus -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( callback_on_mock_put, get_mock_put, @@ -66,7 +66,7 @@ def not_ok_then_other_value(*args, **kwargs): @pytest.fixture def mirror_voltage(): - with DeviceCollector(mock=True): + with init_devices(mock=True): mirror_voltage = SingleMirrorVoltage() return mirror_voltage @@ -244,7 +244,7 @@ def plan(): def test_mirror_populates_voltage_channels(RE): - with DeviceCollector(mock=True): + with init_devices(mock=True): mirror_voltages = MirrorVoltages("", "", daq_configuration_path="") assert len(mirror_voltages.horizontal_voltages) == 14 assert len(mirror_voltages.vertical_voltages) == 8 @@ -261,6 +261,6 @@ def test_mirror_populates_voltage_channels(RE): async def test_given_striped_focussing_mirror_then_energy_to_stripe_returns_expected( RE, energy_kev: float, expected_config: MirrorStripeConfiguration ): - with DeviceCollector(mock=True): + with init_devices(mock=True): device = FocusingMirrorWithStripes(prefix="-OP-VFM-01:", name="mirror") assert device.energy_to_stripe(energy_kev) == expected_config diff --git a/tests/devices/unit_tests/test_gridscan.py b/tests/devices/unit_tests/test_gridscan.py index 87063d42c0..2cc25a9481 100644 --- a/tests/devices/unit_tests/test_gridscan.py +++ b/tests/devices/unit_tests/test_gridscan.py @@ -7,7 +7,7 @@ from bluesky import preprocessors as bpp from bluesky.run_engine import RunEngine from ophyd.status import DeviceStatus, Status -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import get_mock_put, set_mock_value from dodal.devices.fast_grid_scan import ( @@ -30,7 +30,7 @@ def discard_status(st: Status | DeviceStatus): @pytest.fixture async def zebra_fast_grid_scan(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): zebra_fast_grid_scan = ZebraFastGridScan(name="fake_FGS", prefix="FGS") return zebra_fast_grid_scan @@ -38,7 +38,7 @@ async def zebra_fast_grid_scan(): @pytest.fixture async def panda_fast_grid_scan(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): panda_fast_grid_scan = PandAFastGridScan(name="fake_PGS", prefix="PGS") return panda_fast_grid_scan diff --git a/tests/devices/unit_tests/test_linkam3.py b/tests/devices/unit_tests/test_linkam3.py index c2e531f5b6..96b5a527de 100644 --- a/tests/devices/unit_tests/test_linkam3.py +++ b/tests/devices/unit_tests/test_linkam3.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( callback_on_mock_put, get_mock_put, @@ -13,7 +13,7 @@ @pytest.fixture async def fake_linkam(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): fake_linkam: Linkam3 = Linkam3("", "linkam") def set_temp(value: float, *args, **kwargs): diff --git a/tests/devices/unit_tests/test_pressure_jump_cell.py b/tests/devices/unit_tests/test_pressure_jump_cell.py index 9c35c3a144..75f456c092 100644 --- a/tests/devices/unit_tests/test_pressure_jump_cell.py +++ b/tests/devices/unit_tests/test_pressure_jump_cell.py @@ -2,7 +2,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import assert_reading, set_mock_value from dodal.devices.pressure_jump_cell import ( @@ -18,7 +18,7 @@ @pytest.fixture async def cell() -> PressureJumpCell: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): pjump = PressureJumpCell("DEMO-PJUMPCELL-01:") return pjump diff --git a/tests/devices/unit_tests/test_qbpm.py b/tests/devices/unit_tests/test_qbpm.py index e8c9aad67b..afdb1169c2 100644 --- a/tests/devices/unit_tests/test_qbpm.py +++ b/tests/devices/unit_tests/test_qbpm.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import assert_reading from dodal.devices.qbpm import QBPM @@ -9,7 +9,7 @@ @pytest.fixture async def qbpm() -> QBPM: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): qbpm = QBPM("", name="qbpm") return qbpm diff --git a/tests/devices/unit_tests/test_shutter.py b/tests/devices/unit_tests/test_shutter.py index d8eafee18b..7caab684f7 100644 --- a/tests/devices/unit_tests/test_shutter.py +++ b/tests/devices/unit_tests/test_shutter.py @@ -1,5 +1,5 @@ import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import callback_on_mock_put, set_mock_value from dodal.devices.zebra.zebra_controlled_shutter import ( @@ -11,7 +11,7 @@ @pytest.fixture async def sim_shutter(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): sim_shutter = ZebraShutter( prefix="sim_shutter", name="shutter", diff --git a/tests/devices/unit_tests/test_slits.py b/tests/devices/unit_tests/test_slits.py index ae2dbcd096..fd5084f61b 100644 --- a/tests/devices/unit_tests/test_slits.py +++ b/tests/devices/unit_tests/test_slits.py @@ -3,7 +3,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector, StandardReadable +from ophyd_async.core import StandardReadable, init_devices from ophyd_async.testing import set_mock_value from dodal.devices.slits import Slits @@ -11,7 +11,7 @@ @pytest.fixture async def slits() -> Slits: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): slits = Slits("DEMO-SLITS-01:") return slits diff --git a/tests/devices/unit_tests/test_smargon.py b/tests/devices/unit_tests/test_smargon.py index 35612cbda9..0c85bdcbfd 100644 --- a/tests/devices/unit_tests/test_smargon.py +++ b/tests/devices/unit_tests/test_smargon.py @@ -1,7 +1,7 @@ import pytest from bluesky import plan_stubs as bps from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector, observe_value +from ophyd_async.core import init_devices, observe_value from ophyd_async.testing import set_mock_value from dodal.devices.smargon import Smargon, StubPosition @@ -9,7 +9,7 @@ @pytest.fixture async def smargon() -> Smargon: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): smargon = Smargon(name="smargon") return smargon diff --git a/tests/devices/unit_tests/test_synchrotron.py b/tests/devices/unit_tests/test_synchrotron.py index 51a5ff10c9..2fa1f6af37 100644 --- a/tests/devices/unit_tests/test_synchrotron.py +++ b/tests/devices/unit_tests/test_synchrotron.py @@ -5,7 +5,7 @@ import bluesky.plan_stubs as bps import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector, StandardReadable +from ophyd_async.core import StandardReadable, init_devices from ophyd_async.testing import set_mock_value from dodal.devices.synchrotron import ( @@ -112,7 +112,7 @@ @pytest.fixture async def sim_synchrotron() -> Synchrotron: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): sim_synchrotron = Synchrotron() set_mock_value(sim_synchrotron.current, CURRENT) set_mock_value(sim_synchrotron.machine_user_countdown, USER_COUNTDOWN) diff --git a/tests/devices/unit_tests/test_tetramm.py b/tests/devices/unit_tests/test_tetramm.py index 4d46510781..6a24ca3b55 100644 --- a/tests/devices/unit_tests/test_tetramm.py +++ b/tests/devices/unit_tests/test_tetramm.py @@ -1,6 +1,6 @@ import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DetectorTrigger, DeviceCollector, PathProvider, TriggerInfo +from ophyd_async.core import DetectorTrigger, PathProvider, TriggerInfo, init_devices from ophyd_async.epics.adcore import FileWriteMode from ophyd_async.testing import set_mock_value @@ -16,7 +16,7 @@ @pytest.fixture async def tetramm_driver(RE: RunEngine) -> TetrammDriver: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): driver = TetrammDriver("DRIVER:") return driver @@ -26,7 +26,7 @@ async def tetramm_driver(RE: RunEngine) -> TetrammDriver: async def tetramm_controller( RE: RunEngine, tetramm_driver: TetrammDriver ) -> TetrammController: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): controller = TetrammController( tetramm_driver, maximum_readings_per_frame=2_000, @@ -37,7 +37,7 @@ async def tetramm_controller( @pytest.fixture async def tetramm(static_path_provider: PathProvider) -> TetrammDetector: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): tetramm = TetrammDetector( "MY-TETRAMM:", static_path_provider, diff --git a/tests/devices/unit_tests/test_thawer.py b/tests/devices/unit_tests/test_thawer.py index 1501b5477d..d5ad38275d 100644 --- a/tests/devices/unit_tests/test_thawer.py +++ b/tests/devices/unit_tests/test_thawer.py @@ -2,7 +2,7 @@ from unittest.mock import ANY, AsyncMock, call, patch import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import get_mock_put from dodal.devices.thawer import Thawer, ThawerStates, ThawingException, ThawingTimer @@ -10,7 +10,7 @@ @pytest.fixture def thawer(RE): - with DeviceCollector(mock=True): + with init_devices(mock=True): thawer = Thawer("", name="thawer") return thawer diff --git a/tests/devices/unit_tests/test_undulator.py b/tests/devices/unit_tests/test_undulator.py index 7892676e4d..f2e73c2cbb 100644 --- a/tests/devices/unit_tests/test_undulator.py +++ b/tests/devices/unit_tests/test_undulator.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( assert_configuration, assert_reading, @@ -23,7 +23,7 @@ @pytest.fixture async def undulator() -> Undulator: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): undulator = Undulator( "UND-01", name="undulator", @@ -91,7 +91,7 @@ async def test_configuration_includes_configuration_fields(undulator: Undulator) async def test_poles_not_propagated_if_not_supplied(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): undulator = Undulator( "UND-01", name="undulator", @@ -103,7 +103,7 @@ async def test_poles_not_propagated_if_not_supplied(): async def test_length_not_propagated_if_not_supplied(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): undulator = Undulator( "UND-01", name="undulator", diff --git a/tests/devices/unit_tests/test_undulator_dcm.py b/tests/devices/unit_tests/test_undulator_dcm.py index fb7c79ccdf..83e5578c4c 100644 --- a/tests/devices/unit_tests/test_undulator_dcm.py +++ b/tests/devices/unit_tests/test_undulator_dcm.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from ophyd_async.core import AsyncStatus, DeviceCollector +from ophyd_async.core import AsyncStatus, init_devices from ophyd_async.testing import get_mock_put, set_mock_value from conftest import MOCK_DAQ_CONFIG_PATH @@ -30,7 +30,7 @@ def flush_event_loop_on_finish(event_loop): @pytest.fixture async def fake_undulator_dcm() -> UndulatorDCM: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): undulator = Undulator( "UND-01", name="undulator", diff --git a/tests/devices/unit_tests/test_watsonmarlow323_pump.py b/tests/devices/unit_tests/test_watsonmarlow323_pump.py index 4c8aaec1fc..2099bb6b94 100644 --- a/tests/devices/unit_tests/test_watsonmarlow323_pump.py +++ b/tests/devices/unit_tests/test_watsonmarlow323_pump.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import assert_reading, set_mock_value from dodal.devices.watsonmarlow323_pump import ( @@ -13,7 +13,7 @@ @pytest.fixture async def watsonmarlow323() -> WatsonMarlow323Pump: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): wm_pump = WatsonMarlow323Pump("DEMO-WMPUMP-01:") return wm_pump diff --git a/tests/devices/unit_tests/test_xbpm_feedback.py b/tests/devices/unit_tests/test_xbpm_feedback.py index f3079308ff..2044bb59ae 100644 --- a/tests/devices/unit_tests/test_xbpm_feedback.py +++ b/tests/devices/unit_tests/test_xbpm_feedback.py @@ -1,7 +1,7 @@ import pytest from bluesky import plan_stubs as bps from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.xbpm_feedback import XBPMFeedback @@ -9,7 +9,7 @@ @pytest.fixture async def fake_xbpm_feedback() -> XBPMFeedback: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): xbpm = XBPMFeedback() return xbpm diff --git a/tests/devices/unit_tests/test_xspress3.py b/tests/devices/unit_tests/test_xspress3.py index d79e5b607a..8c9f10fb84 100644 --- a/tests/devices/unit_tests/test_xspress3.py +++ b/tests/devices/unit_tests/test_xspress3.py @@ -5,7 +5,7 @@ import pytest from bluesky.run_engine import RunEngine from bluesky.utils import FailedStatus -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import ( callback_on_mock_put, get_mock_put, @@ -22,7 +22,7 @@ @pytest.fixture async def mock_xspress3mini(prefix: str = "BLXX-EA-DET-007:") -> Xspress3: - async with DeviceCollector(mock=True): + async with init_devices(mock=True): mock_xspress3mini = Xspress3(prefix, "Xspress3Mini", 2) assert mock_xspress3mini.channels[1].name == "Xspress3Mini-channels-1" assert mock_xspress3mini.channels[2].name == "Xspress3Mini-channels-2" diff --git a/tests/devices/unit_tests/test_zebra_constants_mapping.py b/tests/devices/unit_tests/test_zebra_constants_mapping.py index 4020bbf651..e8534098f7 100644 --- a/tests/devices/unit_tests/test_zebra_constants_mapping.py +++ b/tests/devices/unit_tests/test_zebra_constants_mapping.py @@ -1,5 +1,5 @@ import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from dodal.beamlines.i03 import I03_ZEBRA_MAPPING from dodal.devices.zebra.zebra import Zebra @@ -11,7 +11,7 @@ async def fake_zebra(zebra_mapping: ZebraMapping): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): zebra = Zebra(mapping=zebra_mapping, name="", prefix="") return zebra diff --git a/tests/plan_stubs/test_motor_util_plans.py b/tests/plan_stubs/test_motor_util_plans.py index c93e43fcac..745c3cf9e9 100644 --- a/tests/plan_stubs/test_motor_util_plans.py +++ b/tests/plan_stubs/test_motor_util_plans.py @@ -4,7 +4,7 @@ from bluesky import plan_stubs as bps from bluesky.run_engine import RunEngine from bluesky.utils import FailedStatus -from ophyd_async.core import Device, DeviceCollector, soft_signal_rw +from ophyd_async.core import Device, init_devices, soft_signal_rw from ophyd_async.epics.motor import Motor from ophyd_async.testing import ( get_mock_put, @@ -48,7 +48,7 @@ def __init__(self): @pytest.fixture def my_device(RE): - with DeviceCollector(mock=True): + with init_devices(mock=True): my_device = DeviceWithOnlyMotors() return my_device @@ -61,7 +61,7 @@ def my_device(RE): def test_given_types_of_device_when_home_and_reset_wrapper_called_then_motors_and_zeros_passed_to_move_and_reset_wrapper( patch_move_and_reset, device_type, RE ): - with DeviceCollector(mock=True): + with init_devices(mock=True): device = device_type() home_and_reset_wrapper(MagicMock(), device, 0, 0) diff --git a/tests/plan_stubs/test_wrapped_stubs.py b/tests/plan_stubs/test_wrapped_stubs.py index a8a58bc9f0..ef74708fc1 100644 --- a/tests/plan_stubs/test_wrapped_stubs.py +++ b/tests/plan_stubs/test_wrapped_stubs.py @@ -4,9 +4,9 @@ from bluesky.run_engine import RunEngine from bluesky.utils import Msg from ophyd_async.core import ( - DeviceCollector, + init_devices, ) -from ophyd_async.sim.demo import SimMotor +from ophyd_async.sim import SimMotor from dodal.plan_stubs.wrapped import ( move, @@ -20,14 +20,14 @@ @pytest.fixture def x_axis(RE: RunEngine) -> SimMotor: - with DeviceCollector(): + with init_devices(): x_axis = SimMotor() return x_axis @pytest.fixture def y_axis(RE: RunEngine) -> SimMotor: - with DeviceCollector(): + with init_devices(): y_axis = SimMotor() return y_axis diff --git a/tests/plans/conftest.py b/tests/plans/conftest.py index 45c7b944ee..23984a1f05 100644 --- a/tests/plans/conftest.py +++ b/tests/plans/conftest.py @@ -3,8 +3,8 @@ import pytest from bluesky.run_engine import RunEngine -from ophyd_async.core import DeviceCollector, PathProvider, StandardDetector -from ophyd_async.sim.demo import PatternDetector, SimMotor +from ophyd_async.core import PathProvider, StandardDetector, init_devices +from ophyd_async.sim import PatternDetector, SimMotor @pytest.fixture @@ -13,21 +13,21 @@ def det( tmp_path: Path, path_provider, ) -> StandardDetector: - with DeviceCollector(mock=True): + with init_devices(mock=True): det = PatternDetector(tmp_path / "foo.h5") return det @pytest.fixture def x_axis(RE: RunEngine) -> SimMotor: - with DeviceCollector(mock=True): + with init_devices(mock=True): x_axis = SimMotor() return x_axis @pytest.fixture def y_axis(RE: RunEngine) -> SimMotor: - with DeviceCollector(mock=True): + with init_devices(mock=True): y_axis = SimMotor() return y_axis diff --git a/tests/plans/test_scanspec.py b/tests/plans/test_scanspec.py index bfa0b6acb1..37adb5ee00 100644 --- a/tests/plans/test_scanspec.py +++ b/tests/plans/test_scanspec.py @@ -13,7 +13,7 @@ StreamResource, ) from ophyd_async.core import StandardDetector -from ophyd_async.sim.demo import SimMotor +from ophyd_async.sim import SimMotor from scanspec.specs import Line from dodal.plans import spec_scan diff --git a/tests/preprocessors/test_filesystem_metadata.py b/tests/preprocessors/test_filesystem_metadata.py index 24b66a0d34..f78d797019 100644 --- a/tests/preprocessors/test_filesystem_metadata.py +++ b/tests/preprocessors/test_filesystem_metadata.py @@ -16,7 +16,7 @@ from bluesky.run_engine import RunEngine from bluesky.utils import MsgGenerator from event_model.documents.event_descriptor import DataKey -from ophyd_async.core import AsyncStatus, DeviceCollector, PathProvider +from ophyd_async.core import AsyncStatus, PathProvider, init_devices from pydantic import BaseModel from dodal.common.types import UpdatingPathProvider @@ -112,7 +112,7 @@ def provider(client: DirectoryServiceClient, tmp_path: Path) -> UpdatingPathProv @pytest.fixture(params=[1, 2]) def detectors(request, provider: UpdatingPathProvider) -> list[Readable]: number_of_detectors = request.param - with DeviceCollector(mock=True): + with init_devices(mock=True): dets: list[Readable] = [ FakeDetector(name=f"det{i}", provider=provider) for i in range(number_of_detectors) From 56a931bc694b33b66cd455776c43a8cb1507d0ca Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Mon, 27 Jan 2025 12:03:20 +0000 Subject: [PATCH 2/9] Update save panda plan to use new save/load --- src/dodal/plans/save_panda.py | 41 ++++++---- .../unit_tests/util/test_save_panda.py | 76 +++++++++++++++---- 2 files changed, 88 insertions(+), 29 deletions(-) diff --git a/src/dodal/plans/save_panda.py b/src/dodal/plans/save_panda.py index af0ffaa8df..7dd5896549 100644 --- a/src/dodal/plans/save_panda.py +++ b/src/dodal/plans/save_panda.py @@ -6,8 +6,10 @@ from typing import cast from bluesky.run_engine import RunEngine -from ophyd_async.core import Device, save_device -from ophyd_async.fastcs.panda import phase_sorter +from ophyd_async.core import Device, YamlSettingsProvider +from ophyd_async.plan_stubs import ( + store_settings, +) from dodal.beamlines import module_name_for_beamline from dodal.utils import make_device @@ -17,27 +19,35 @@ def main(argv: list[str]): """CLI Utility to save the panda configuration.""" parser = ArgumentParser(description="Save an ophyd_async panda to yaml") parser.add_argument( - "--beamline", help="beamline to save from e.g. i03. Defaults to BEAMLINE" + "--beamline", help="Beamline to save from e.g. i03. Defaults to BEAMLINE" ) parser.add_argument( "--device-name", - help='name of the device. The default is "panda"', + help='Name of the device. The default is "panda"', default="panda", ) + parser.add_argument( + "--file-name", + help="Name of the output save file", + default="panda_settings.yaml", + ) + parser.add_argument( + "--output-directory", help="Directory in which save file is output" + ) parser.add_argument( "-f", "--force", action=argparse.BooleanOptionalAction, help="Force overwriting an existing file", ) - parser.add_argument("output_file", help="output filename") # this exit()s with message/help unless args parsed successfully args = parser.parse_args(argv[1:]) beamline = args.beamline device_name = args.device_name - output_file = args.output_file + file_name = args.file_name + output_directory = args.output_directory force = args.force if beamline: @@ -49,19 +59,19 @@ def main(argv: list[str]): sys.stderr.write("BEAMLINE not set and --beamline not specified\n") return 1 - if Path(output_file).exists() and not force: + if Path(file_name).exists() and not force: sys.stderr.write( - f"Output file {output_file} already exists and --force not specified." + f"Output file {file_name} already exists and --force not specified." ) return 1 - _save_panda(beamline, device_name, output_file) + _save_panda(beamline, device_name, output_directory, file_name) print("Done.") return 0 -def _save_panda(beamline, device_name, output_file): +def _save_panda(beamline, device_name, output_directory, file_name): RE = RunEngine() print("Creating devices...") module_name = module_name_for_beamline(beamline) @@ -72,13 +82,16 @@ def _save_panda(beamline, device_name, output_file): sys.exit(1) panda = devices[device_name] - print(f"Saving to {output_file} from {device_name} on {beamline}...") - _save_panda_to_file(RE, cast(Device, panda), output_file) + print(f"Saving to {file_name} from {device_name} on {beamline}...") + _save_panda_to_yaml(RE, cast(Device, panda), file_name, output_directory) -def _save_panda_to_file(RE: RunEngine, panda: Device, path: str): +def _save_panda_to_yaml( + RE: RunEngine, panda: Device, file_name: str, output_directory: str +): def save_to_file(): - yield from save_device(panda, path, sorter=phase_sorter) + provider = YamlSettingsProvider(output_directory) + yield from store_settings(provider, file_name, panda) RE(save_to_file()) diff --git a/tests/devices/unit_tests/util/test_save_panda.py b/tests/devices/unit_tests/util/test_save_panda.py index 867effa50c..62b8ae673f 100644 --- a/tests/devices/unit_tests/util/test_save_panda.py +++ b/tests/devices/unit_tests/util/test_save_panda.py @@ -3,7 +3,6 @@ import pytest from bluesky.simulators import RunEngineSimulator -from ophyd_async.fastcs.panda import phase_sorter from dodal.plans.save_panda import _save_panda, main @@ -11,6 +10,8 @@ def test_save_panda(): sim_run_engine = RunEngineSimulator() panda = MagicMock() + directory = "test" + filename = "file.yml" with ( patch( "dodal.plans.save_panda.make_device", return_value={"panda": panda} @@ -19,64 +20,97 @@ def test_save_panda(): "dodal.plans.save_panda.RunEngine", return_value=MagicMock(side_effect=sim_run_engine.simulate_plan), ), - patch("dodal.plans.save_panda.save_device") as mock_save_device, + patch("dodal.plans.save_panda.store_settings") as mock_store_settings, + patch("dodal.plans.save_panda.YamlSettingsProvider") as mock_settings_provider, ): - _save_panda("i03", "panda", "test/file.yml") + _save_panda("i03", "panda", directory, filename) mock_make_device.assert_called_with("dodal.beamlines.i03", "panda") - mock_save_device.assert_called_with(panda, "test/file.yml", sorter=phase_sorter) + mock_store_settings.assert_called_with( + mock_settings_provider(), + "file.yml", + panda, + ) @patch( "dodal.plans.save_panda.sys.exit", side_effect=AssertionError("This exception expected"), ) -def test_save_panda_failure_to_create_device_exits_with_failure_code(mock_exit): +def test_save_panda_failure_to_create_device_exits_with_failure_code(mock_exit, tmpdir): with patch( "dodal.plans.save_panda.make_device", side_effect=ValueError("device does not exist"), ): with pytest.raises(AssertionError): - _save_panda("i03", "panda", "test/file.yml") + _save_panda("i03", "panda", tmpdir, "filename") mock_exit.assert_called_once_with(1) @patch("dodal.plans.save_panda._save_panda") @pytest.mark.parametrize( - "beamline, args, expected_beamline, expected_device_name, expected_output_file, " + "beamline, args, expected_beamline, expected_device_name, expected_output_dir, expected_output_file, " "expected_return_value", [ - ("i03", ["my_file_name.yml"], "i03", "panda", "my_file_name.yml", 0), + ( + "i03", + ["--file-name=my_file_name.yml", "--output-directory=my_dir"], + "i03", + "panda", + "my_dir", + "my_file_name.yml", + 0, + ), ( "i02", - ["--beamline=i04", "my_file_name.yml"], + [ + "--beamline=i04", + "--file-name=my_file_name.yml", + "--output-directory=my_dir", + ], "i04", "panda", + "my_dir", "my_file_name.yml", 0, ), ( None, - ["--beamline=i04", "my_file_name.yml"], + [ + "--beamline=i04", + "--file-name=my_file_name.yml", + "--output-directory=my_dir", + ], "i04", "panda", + "my_dir", "my_file_name.yml", 0, ), ( "i03", - ["--device-name=my_panda", "my_file_name.yml"], + [ + "--device-name=my_panda", + "--file-name=my_file_name.yml", + "--output-directory=my_dir", + ], "i03", "my_panda", + "my_dir", "my_file_name.yml", 0, ), ( None, - ["--device-name=my_panda", "my_file_name.yml"], + [ + "--device-name=my_panda", + "--file-name=my_file_name.yml", + "--output-directory=my_dir", + ], "i03", "my_panda", + "my_dir", "my_file_name.yml", 1, ), @@ -88,6 +122,7 @@ def test_main( args: list[str], expected_beamline, expected_device_name, + expected_output_dir, expected_output_file, expected_return_value, ): @@ -102,7 +137,10 @@ def test_main( assert return_value == expected_return_value if not expected_return_value: mock_save_panda.assert_called_with( - expected_beamline, expected_device_name, expected_output_file + expected_beamline, + expected_device_name, + expected_output_dir, + expected_output_file, ) @@ -124,10 +162,16 @@ def test_file_exists_check( force: bool, save_panda_called: bool, expected_return_value: int, + tmpdir, ): exists = mock_path.return_value.exists exists.return_value = file_exists - argv = ["save_panda", "--beamline=i03", "test_output_file.yml"] + argv = [ + "save_panda", + "--beamline=i03", + "--file-name=test_output_file.yml", + f"--output-directory={tmpdir}", + ] if force: argv.insert(1, "--force") @@ -137,7 +181,9 @@ def test_file_exists_check( mock_path.assert_called_with("test_output_file.yml") exists.assert_called_once() if save_panda_called: - mock_save_panda.assert_called_with("i03", "panda", "test_output_file.yml") + mock_save_panda.assert_called_with( + "i03", "panda", tmpdir, "test_output_file.yml" + ) else: mock_save_panda.assert_not_called() From da2aeb4cd488b42ba00d7f7601d4de2deadfd435 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Mon, 27 Jan 2025 18:07:29 +0000 Subject: [PATCH 3/9] Remaining fiddly changes --- src/dodal/devices/i13_1/merlin_controller.py | 9 +-- tests/devices/i13_1/test_merlin.py | 4 +- tests/devices/i22/test_dcm.py | 70 ++++++++++---------- tests/devices/i22/test_metadataholder.py | 2 +- tests/devices/test_diamond_filter.py | 4 +- tests/devices/unit_tests/test_qbpm.py | 2 +- tests/devices/unit_tests/test_tetramm.py | 8 +-- tests/devices/unit_tests/test_undulator.py | 21 +++--- 8 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/dodal/devices/i13_1/merlin_controller.py b/src/dodal/devices/i13_1/merlin_controller.py index 66f9e84ec9..33e1711056 100644 --- a/src/dodal/devices/i13_1/merlin_controller.py +++ b/src/dodal/devices/i13_1/merlin_controller.py @@ -4,15 +4,15 @@ from ophyd_async.core import ( DEFAULT_TIMEOUT, AsyncStatus, - DetectorController, TriggerInfo, ) from ophyd_async.epics import adcore +from ophyd_async.epics.adcore import ADBaseController from dodal.devices.i13_1.merlin_io import MerlinDriverIO, MerlinImageMode -class MerlinController(DetectorController): +class MerlinController(ADBaseController): def __init__( self, driver: MerlinDriverIO, @@ -37,11 +37,6 @@ async def prepare(self, trigger_info: TriggerInfo): self.driver.image_mode.set(MerlinImageMode.MULTIPLE), ) - async def arm(self): - self._arm_status = await adcore.start_acquiring_driver_and_ensure_status( - self.driver, good_states=self.good_states, timeout=self.frame_timeout - ) - async def wait_for_idle(self): if self._arm_status: await self._arm_status diff --git a/tests/devices/i13_1/test_merlin.py b/tests/devices/i13_1/test_merlin.py index 1b2db52d0f..2f94f9f736 100644 --- a/tests/devices/i13_1/test_merlin.py +++ b/tests/devices/i13_1/test_merlin.py @@ -46,11 +46,11 @@ async def test_trigger( await merlin.stage() await merlin.prepare(one_shot_trigger_info) - await merlin.controller.arm() + await merlin._controller.arm() assert await merlin.drv.acquire.get_value() - await merlin.controller.wait_for_idle() + await merlin._controller.wait_for_idle() async def test_can_collect( diff --git a/tests/devices/i22/test_dcm.py b/tests/devices/i22/test_dcm.py index 651a0d9fdd..02827ec0df 100644 --- a/tests/devices/i22/test_dcm.py +++ b/tests/devices/i22/test_dcm.py @@ -72,67 +72,67 @@ async def test_reading(dcm: DoubleCrystalMonochromator): dcm, { "dcm-backplate_temp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-bragg": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_1_heater_temp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_1_roll": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_1_temp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_2_heater_temp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_2_pitch": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_2_roll": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-crystal_2_temp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-energy": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-offset": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-perp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, "dcm-perp_temp": { - "alarm_severity": ANY, + "alarm_severity": 0, "timestamp": ANY, "value": 0.0, }, @@ -155,112 +155,112 @@ async def test_configuration(dcm: DoubleCrystalMonochromator): "dcm-bragg-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-bragg-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-energy-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-energy-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_1_roll-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_1_roll-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-offset-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-offset-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_pitch-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_pitch-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_roll-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_roll-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-perp-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-perp-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_d_spacing": { "value": 0.31356, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_usage": { "value": "Bragg", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_type": { "value": "silicon", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_1_reflection": { "value": [1, 1, 1], "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_2_reflection": { "value": [1, 1, 1], "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_1_d_spacing": { "value": 0.31356, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_1_usage": { "value": "Bragg", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "dcm-crystal_1_type": { "value": "silicon", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, }, ) diff --git a/tests/devices/i22/test_metadataholder.py b/tests/devices/i22/test_metadataholder.py index b5d4c13a02..accd78e6dc 100644 --- a/tests/devices/i22/test_metadataholder.py +++ b/tests/devices/i22/test_metadataholder.py @@ -34,4 +34,4 @@ async def test_config_data_present(saxs: PilatusDetector): assert config["source"] == "calibration" assert config["dtype"] == "number" assert not hasattr(dc, f"{saxs.name}-type") - assert dc[f"{saxs.name}-drv-acquire_time"] is not None + assert dc[f"{saxs.name}-driver-acquire_time"] is not None diff --git a/tests/devices/test_diamond_filter.py b/tests/devices/test_diamond_filter.py index 3692867d58..dbfcdf4bea 100644 --- a/tests/devices/test_diamond_filter.py +++ b/tests/devices/test_diamond_filter.py @@ -30,12 +30,12 @@ async def test_reading_includes_read_fields( "diamond_filter-y_motor": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "diamond_filter-thickness": { "value": I03Filters.EMPTY, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, }, ) diff --git a/tests/devices/unit_tests/test_qbpm.py b/tests/devices/unit_tests/test_qbpm.py index afdb1169c2..4804ae9a30 100644 --- a/tests/devices/unit_tests/test_qbpm.py +++ b/tests/devices/unit_tests/test_qbpm.py @@ -21,7 +21,7 @@ async def test_reading_includes_read_fields(qbpm: QBPM): "qbpm-intensity_uA": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, }, ) diff --git a/tests/devices/unit_tests/test_tetramm.py b/tests/devices/unit_tests/test_tetramm.py index 6a24ca3b55..b010fc92bc 100644 --- a/tests/devices/unit_tests/test_tetramm.py +++ b/tests/devices/unit_tests/test_tetramm.py @@ -273,7 +273,7 @@ async def test_disarm_disarms_driver( ) ) assert (await tetramm_driver.acquire.get_value()) == 1 - await tetramm.controller.disarm() + await tetramm._controller.disarm() assert (await tetramm_driver.acquire.get_value()) == 0 @@ -285,7 +285,7 @@ async def test_prepare_with_too_low_a_deadtime_raises_error( tetramm: TetrammDetector, ): with pytest.raises( - AssertionError, + ValueError, match=r"Detector .* needs at least 2e-05s deadtime, but trigger logic " "provides only 1e-05s", ): @@ -327,7 +327,7 @@ async def test_prepare_sets_up_writer( assert (await tetramm.hdf.num_extra_dims.get_value()) == 0 assert await tetramm.hdf.lazy_open.get_value() assert await tetramm.hdf.swmr_mode.get_value() - assert (await tetramm.hdf.file_template.get_value()) == "%s/%s.h5" + assert (await tetramm.hdf.file_template.get_value()) == "%s%s.h5" assert (await tetramm.hdf.file_write_mode.get_value()) == FileWriteMode.STREAM @@ -362,7 +362,7 @@ async def test_pilatus_controller( RE, tetramm: TetrammDetector, ): - controller = tetramm.controller + controller = tetramm._controller driver = tetramm.drv await controller.prepare( TriggerInfo( diff --git a/tests/devices/unit_tests/test_undulator.py b/tests/devices/unit_tests/test_undulator.py index f2e73c2cbb..b1b7c966bd 100644 --- a/tests/devices/unit_tests/test_undulator.py +++ b/tests/devices/unit_tests/test_undulator.py @@ -41,17 +41,17 @@ async def test_reading_includes_read_fields(undulator: Undulator): "undulator-gap_access": { "value": UndulatorGapAccess.ENABLED, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "undulator-gap_motor": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "undulator-current_gap": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, }, ) @@ -64,27 +64,32 @@ async def test_configuration_includes_configuration_fields(undulator: Undulator) "undulator-gap_motor-motor_egu": { "value": "", "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "undulator-gap_motor-velocity": { "value": 0.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "undulator-length": { "value": 2.0, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "undulator-poles": { "value": 80, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, }, "undulator-gap_discrepancy_tolerance_mm": { "value": 0.002, "timestamp": ANY, - "alarm_severity": ANY, + "alarm_severity": 0, + }, + "undulator-gap_motor-offset": { + "alarm_severity": 0, + "timestamp": ANY, + "value": 0.0, }, }, ) From 23e0c70fbd6d52fa58d75a05af58ab584112451d Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Tue, 28 Jan 2025 10:17:45 +0000 Subject: [PATCH 4/9] Type checking fixes --- src/dodal/devices/tetramm.py | 11 ++++++++--- tests/devices/i22/test_dcm.py | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dodal/devices/tetramm.py b/src/dodal/devices/tetramm.py index 3990b0f2cd..54091704c2 100644 --- a/src/dodal/devices/tetramm.py +++ b/src/dodal/devices/tetramm.py @@ -13,7 +13,12 @@ set_and_wait_for_value, soft_signal_r_and_setter, ) -from ophyd_async.epics.adcore import ADHDFWriter, NDFileHDFIO, stop_busy_record +from ophyd_async.epics.adcore import ( + ADHDFWriter, + NDFileHDFIO, + NDPluginBaseIO, + stop_busy_record, +) from ophyd_async.epics.core import ( epics_signal_r, epics_signal_rw, @@ -221,7 +226,7 @@ def __init__( path_provider: PathProvider, name: str = "", type: str | None = None, - **scalar_sigs: str, + plugins: dict[str, NDPluginBaseIO] | None = None, ) -> None: self.drv = TetrammDriver(prefix + "DRV:") self.hdf = NDFileHDFIO(prefix + "HDF5:") @@ -243,7 +248,7 @@ def __init__( path_provider, lambda: self.name, TetrammDatasetDescriber(controller), - **scalar_sigs, + plugins=plugins, ), config_signals, name, diff --git a/tests/devices/i22/test_dcm.py b/tests/devices/i22/test_dcm.py index 02827ec0df..46caaf6947 100644 --- a/tests/devices/i22/test_dcm.py +++ b/tests/devices/i22/test_dcm.py @@ -1,4 +1,3 @@ -from collections.abc import Mapping from unittest.mock import ANY import bluesky.plans as bp @@ -36,7 +35,7 @@ async def dcm() -> DoubleCrystalMonochromator: def test_count_dcm( RE: RunEngine, - run_engine_documents: Mapping[str, list[dict]], + run_engine_documents: dict[str, list[dict]], dcm: DoubleCrystalMonochromator, ): RE(bp.count([dcm])) From a9e0285e0a6cd01f0092a871de0bb54047d830bc Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Tue, 28 Jan 2025 11:44:22 +0000 Subject: [PATCH 5/9] Make output directory required argument for save panda plan --- src/dodal/plans/save_panda.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dodal/plans/save_panda.py b/src/dodal/plans/save_panda.py index 7dd5896549..88bf74933d 100644 --- a/src/dodal/plans/save_panda.py +++ b/src/dodal/plans/save_panda.py @@ -32,7 +32,9 @@ def main(argv: list[str]): default="panda_settings.yaml", ) parser.add_argument( - "--output-directory", help="Directory in which save file is output" + "--output-directory", + help="Directory in which save file is output", + required=True, ) parser.add_argument( "-f", From a6a3286e9b7890e534604c9cd2bdaa20604714d5 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Tue, 4 Feb 2025 14:35:02 +0000 Subject: [PATCH 6/9] Replace new DeviceCollectors with init_devices --- tests/devices/i18/test_table.py | 6 +++--- tests/devices/i18/test_thor_labs_stage.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/devices/i18/test_table.py b/tests/devices/i18/test_table.py index 587cd0a358..410df17c0f 100644 --- a/tests/devices/i18/test_table.py +++ b/tests/devices/i18/test_table.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.i18.table import Table @@ -9,8 +9,8 @@ @pytest.fixture async def table() -> Table: - """Fixture to set up a mock Table device using DeviceCollector.""" - async with DeviceCollector(mock=True): + """Fixture to set up a mock Table device using init_devices.""" + async with init_devices(mock=True): table = Table(prefix="MIRROR:") return table diff --git a/tests/devices/i18/test_thor_labs_stage.py b/tests/devices/i18/test_thor_labs_stage.py index 3958eef9cc..f44fe68d1c 100644 --- a/tests/devices/i18/test_thor_labs_stage.py +++ b/tests/devices/i18/test_thor_labs_stage.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.i18.thor_labs_stage import ThorLabsStage @@ -9,7 +9,7 @@ @pytest.fixture async def thor_labs_stage(): - async with DeviceCollector(mock=True): + async with init_devices(mock=True): thor_labs_stage = ThorLabsStage("") return thor_labs_stage From b0f01b6fca039fa39c816529a962b280c38f0c64 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Tue, 4 Feb 2025 14:38:03 +0000 Subject: [PATCH 7/9] Add forgotten file to previous commit --- tests/devices/i18/test_kb_mirror.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/devices/i18/test_kb_mirror.py b/tests/devices/i18/test_kb_mirror.py index 736c0d590c..2bbced0831 100644 --- a/tests/devices/i18/test_kb_mirror.py +++ b/tests/devices/i18/test_kb_mirror.py @@ -1,7 +1,7 @@ from unittest.mock import ANY import pytest -from ophyd_async.core import DeviceCollector +from ophyd_async.core import init_devices from ophyd_async.testing import set_mock_value from dodal.devices.i18.KBMirror import KBMirror @@ -9,8 +9,8 @@ @pytest.fixture async def kbmirror() -> KBMirror: - """Fixture to set up a mock KBMirror device using DeviceCollector.""" - async with DeviceCollector(mock=True): + """Fixture to set up a mock KBMirror device using init_devices.""" + async with init_devices(mock=True): kbmirror = KBMirror(prefix="MIRROR:") return kbmirror From 658870ee4bb99bbd259417d8de94d04cceda13d2 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Tue, 4 Feb 2025 16:46:17 +0000 Subject: [PATCH 8/9] Use constants for Suffixes --- src/dodal/beamlines/adsim.py | 5 +++-- src/dodal/beamlines/b01_1.py | 6 +++--- src/dodal/beamlines/i13_1.py | 9 +++++---- src/dodal/beamlines/i22.py | 14 +++++++------- src/dodal/beamlines/p38.py | 18 +++++++++++------- src/dodal/beamlines/p45.py | 9 +++++---- src/dodal/beamlines/training_rig.py | 6 +++--- src/dodal/common/beamlines/device_helpers.py | 4 +++- src/dodal/devices/i13_1/merlin.py | 5 +++-- tests/devices/i22/test_metadataholder.py | 5 +++-- 10 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/dodal/beamlines/adsim.py b/src/dodal/beamlines/adsim.py index e9b60bb443..0c1302cb9a 100644 --- a/src/dodal/beamlines/adsim.py +++ b/src/dodal/beamlines/adsim.py @@ -8,6 +8,7 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline +from dodal.common.beamlines.device_helpers import DET_SUFFIX, HDF5_SUFFIX from dodal.common.visit import LocalDirectoryServiceClient, StaticVisitPathProvider from dodal.devices.adsim import SimStage from dodal.log import set_beamline as set_log_beamline @@ -70,6 +71,6 @@ def det() -> SimDetector: return SimDetector( f"{PREFIX.beamline_prefix}-DI-CAM-01:", path_provider=get_path_provider(), - drv_suffix="DET:", - fileio_suffix="HDF:", + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, ) diff --git a/src/dodal/beamlines/b01_1.py b/src/dodal/beamlines/b01_1.py index 5156abb86a..0f25bfecf0 100644 --- a/src/dodal/beamlines/b01_1.py +++ b/src/dodal/beamlines/b01_1.py @@ -9,7 +9,7 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline -from dodal.common.beamlines.device_helpers import HDF5_PREFIX +from dodal.common.beamlines.device_helpers import CAM_SUFFIX, HDF5_SUFFIX from dodal.common.visit import LocalDirectoryServiceClient, StaticVisitPathProvider from dodal.devices.synchrotron import Synchrotron from dodal.log import set_beamline as set_log_beamline @@ -57,6 +57,6 @@ def manta() -> AravisDetector: return AravisDetector( f"{PREFIX.beamline_prefix}-DI-DCAM-02:", path_provider=get_path_provider(), - drv_suffix="CAM:", - fileio_suffix=HDF5_PREFIX, + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, ) diff --git a/src/dodal/beamlines/i13_1.py b/src/dodal/beamlines/i13_1.py index 78cb9e2cd0..b1d1b444a1 100644 --- a/src/dodal/beamlines/i13_1.py +++ b/src/dodal/beamlines/i13_1.py @@ -8,6 +8,7 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline +from dodal.common.beamlines.device_helpers import CAM_SUFFIX, HDF5_SUFFIX from dodal.common.visit import LocalDirectoryServiceClient, StaticVisitPathProvider from dodal.devices.i13_1.merlin import Merlin from dodal.devices.motors import XYZPositioner @@ -60,8 +61,8 @@ def side_camera( prefix="BL13J-OP-FLOAT-03:", name="side_camera", bl_prefix=False, - drv_suffix="CAM:", - fileio_suffix="HDF5:", + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), wait=wait_for_connection, fake=fake_with_ophyd_sim, @@ -76,8 +77,8 @@ def merlin( prefix="BL13J-EA-DET-04:", name="merlin", bl_prefix=False, - drv_suffix="CAM:", - fileio_suffix="HDF5:", + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), wait=wait_for_connection, fake=fake_with_ophyd_sim, diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 58a9a14a78..9b2d9cf3c6 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -10,7 +10,7 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline -from dodal.common.beamlines.device_helpers import HDF5_PREFIX +from dodal.common.beamlines.device_helpers import CAM_SUFFIX, DET_SUFFIX, HDF5_SUFFIX from dodal.common.crystal_metadata import ( MaterialsEnum, make_crystal_metadata_from_material, @@ -63,8 +63,8 @@ def saxs() -> PilatusDetector: return NXSasPilatus( prefix=f"{PREFIX.beamline_prefix}-EA-PILAT-01:", path_provider=get_path_provider(), - drv_suffix="CAM:", - fileio_suffix=HDF5_PREFIX, + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, metadata_holder=metadata_holder, ) @@ -88,8 +88,8 @@ def waxs() -> PilatusDetector: return NXSasPilatus( prefix=f"{PREFIX.beamline_prefix}-EA-PILAT-03:", path_provider=get_path_provider(), - drv_suffix="CAM:", - fileio_suffix=HDF5_PREFIX, + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, metadata_holder=metadata_holder, ) @@ -248,8 +248,8 @@ def oav() -> AravisDetector: ) return NXSasOAV( prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:", - drv_suffix="DET:", - fileio_suffix=HDF5_PREFIX, + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), metadata_holder=metadata_holder, ) diff --git a/src/dodal/beamlines/p38.py b/src/dodal/beamlines/p38.py index 6e9f947b84..affbed493d 100644 --- a/src/dodal/beamlines/p38.py +++ b/src/dodal/beamlines/p38.py @@ -9,7 +9,11 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline -from dodal.common.beamlines.device_helpers import numbered_slits +from dodal.common.beamlines.device_helpers import ( + DET_SUFFIX, + HDF5_SUFFIX, + numbered_slits, +) from dodal.common.crystal_metadata import ( MaterialsEnum, make_crystal_metadata_from_material, @@ -54,8 +58,8 @@ def d3( "-DI-DCAM-01:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:", - fileio_suffix="HDF5:", + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), ) @@ -71,8 +75,8 @@ def d11( "-DI-DCAM-03:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:", - fileio_suffix="HDF5:", + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), ) @@ -86,8 +90,8 @@ def d12( "-DI-DCAM-04:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:", - fileio_suffix="HDF5:", + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), ) diff --git a/src/dodal/beamlines/p45.py b/src/dodal/beamlines/p45.py index 3abdb71560..162efb55d5 100644 --- a/src/dodal/beamlines/p45.py +++ b/src/dodal/beamlines/p45.py @@ -9,6 +9,7 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline +from dodal.common.beamlines.device_helpers import DET_SUFFIX, HDF5_SUFFIX from dodal.common.visit import StaticVisitPathProvider from dodal.devices.p45 import Choppers, TomoStageWithStretchAndSkew from dodal.log import set_beamline as set_log_beamline @@ -60,8 +61,8 @@ def det( "-EA-MAP-01:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:", - fileio_suffix="HDF5:", + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), ) @@ -77,8 +78,8 @@ def diff( "-EA-DIFF-01:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:", - fileio_suffix="HDF5:", + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, path_provider=get_path_provider(), ) diff --git a/src/dodal/beamlines/training_rig.py b/src/dodal/beamlines/training_rig.py index 685e1a4bd7..5f689bba74 100644 --- a/src/dodal/beamlines/training_rig.py +++ b/src/dodal/beamlines/training_rig.py @@ -9,7 +9,7 @@ set_path_provider, ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline -from dodal.common.beamlines.device_helpers import HDF5_PREFIX +from dodal.common.beamlines.device_helpers import DET_SUFFIX, HDF5_SUFFIX from dodal.common.visit import LocalDirectoryServiceClient, StaticVisitPathProvider from dodal.devices.training_rig.sample_stage import TrainingRigSampleStage from dodal.log import set_beamline as set_log_beamline @@ -50,8 +50,8 @@ def det() -> AravisDetector: return AravisDetector( f"{PREFIX.beamline_prefix}-EA-DET-01:", path_provider=get_path_provider(), - drv_suffix="DET:", - fileio_suffix=HDF5_PREFIX, + drv_suffix=DET_SUFFIX, + fileio_suffix=HDF5_SUFFIX, ) diff --git a/src/dodal/common/beamlines/device_helpers.py b/src/dodal/common/beamlines/device_helpers.py index 43c3c88e4c..9b18f693ad 100644 --- a/src/dodal/common/beamlines/device_helpers.py +++ b/src/dodal/common/beamlines/device_helpers.py @@ -2,7 +2,9 @@ from dodal.devices.slits import Slits from dodal.utils import skip_device -HDF5_PREFIX = "HDF5:" +HDF5_SUFFIX = "HDF5:" +CAM_SUFFIX = "CAM:" +DET_SUFFIX = "DET:" @skip_device() diff --git a/src/dodal/devices/i13_1/merlin.py b/src/dodal/devices/i13_1/merlin.py index 81d954b4f1..768374f319 100644 --- a/src/dodal/devices/i13_1/merlin.py +++ b/src/dodal/devices/i13_1/merlin.py @@ -1,6 +1,7 @@ from ophyd_async.core import PathProvider, StandardDetector from ophyd_async.epics import adcore +from dodal.common.beamlines.device_helpers import CAM_SUFFIX, HDF5_SUFFIX from dodal.devices.i13_1.merlin_controller import MerlinController from dodal.devices.i13_1.merlin_io import MerlinDriverIO @@ -13,8 +14,8 @@ def __init__( self, prefix: str, path_provider: PathProvider, - drv_suffix="CAM:", - fileio_suffix="HDF:", + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, name: str = "", ): self.drv = MerlinDriverIO(prefix + drv_suffix) diff --git a/tests/devices/i22/test_metadataholder.py b/tests/devices/i22/test_metadataholder.py index accd78e6dc..9a59de51c1 100644 --- a/tests/devices/i22/test_metadataholder.py +++ b/tests/devices/i22/test_metadataholder.py @@ -2,6 +2,7 @@ from ophyd_async.core import PathProvider, init_devices from ophyd_async.epics.adpilatus import PilatusDetector +from dodal.common.beamlines.device_helpers import CAM_SUFFIX, HDF5_SUFFIX from dodal.devices.i22.nxsas import NXSasMetadataHolder, NXSasPilatus @@ -10,8 +11,8 @@ def saxs(static_path_provider: PathProvider, RE) -> PilatusDetector: with init_devices(mock=True): saxs = NXSasPilatus( prefix="-EA-PILAT-01:", - drv_suffix="CAM:", - fileio_suffix="HDF5:", + drv_suffix=CAM_SUFFIX, + fileio_suffix=HDF5_SUFFIX, metadata_holder=NXSasMetadataHolder( x_pixel_size=(1.72e-1, "mm"), y_pixel_size=(1.72e-1, "mm"), From ecad97fdd135407e405a2b0aa9eda359fb84bc63 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Wed, 5 Feb 2025 10:27:23 +0000 Subject: [PATCH 9/9] Tidy up save panda plan --- src/dodal/plans/save_panda.py | 27 +++++++------ tests/devices/i13_1/test_merlin.py | 2 +- .../unit_tests/util/test_save_panda.py | 40 ++++++++++--------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/dodal/plans/save_panda.py b/src/dodal/plans/save_panda.py index 88bf74933d..352a0c59e5 100644 --- a/src/dodal/plans/save_panda.py +++ b/src/dodal/plans/save_panda.py @@ -27,13 +27,8 @@ def main(argv: list[str]): default="panda", ) parser.add_argument( - "--file-name", - help="Name of the output save file", - default="panda_settings.yaml", - ) - parser.add_argument( - "--output-directory", - help="Directory in which save file is output", + "--output-file", + help="Path to output file, including filename, eg '/scratch/panda_settings'. '.yaml' is appended to the file name automatically", required=True, ) parser.add_argument( @@ -48,10 +43,12 @@ def main(argv: list[str]): beamline = args.beamline device_name = args.device_name - file_name = args.file_name - output_directory = args.output_directory + output_file = args.output_file force = args.force + p = Path(output_file) + output_directory, file_name = str(p.parent), str(p.name) + if beamline: os.environ["BEAMLINE"] = beamline else: @@ -61,9 +58,9 @@ def main(argv: list[str]): sys.stderr.write("BEAMLINE not set and --beamline not specified\n") return 1 - if Path(file_name).exists() and not force: + if Path(f"{output_directory}/{file_name}").exists() and not force: sys.stderr.write( - f"Output file {file_name} already exists and --force not specified." + f"Output file {output_directory}/{file_name} already exists and --force not specified." ) return 1 @@ -78,13 +75,17 @@ def _save_panda(beamline, device_name, output_directory, file_name): print("Creating devices...") module_name = module_name_for_beamline(beamline) try: - devices = make_device(f"dodal.beamlines.{module_name}", device_name) + devices = make_device( + f"dodal.beamlines.{module_name}", device_name, connect_immediately=True + ) except Exception as error: sys.stderr.write(f"Couldn't create device {device_name}: {error}\n") sys.exit(1) panda = devices[device_name] - print(f"Saving to {file_name} from {device_name} on {beamline}...") + print( + f"Saving to {output_directory}/{file_name} from {device_name} on {beamline}..." + ) _save_panda_to_yaml(RE, cast(Device, panda), file_name, output_directory) diff --git a/tests/devices/i13_1/test_merlin.py b/tests/devices/i13_1/test_merlin.py index 2f94f9f736..f62bf25577 100644 --- a/tests/devices/i13_1/test_merlin.py +++ b/tests/devices/i13_1/test_merlin.py @@ -97,7 +97,7 @@ async def test_can_decribe_collect(merlin: Merlin, one_shot_trigger_info: Trigge await merlin.prepare(one_shot_trigger_info) assert (await merlin.describe_collect()) == { "merlin": { - "source": "mock+ca://BL13J-EA-DET-04HDF:FullFileName_RBV", + "source": "mock+ca://BL13J-EA-DET-04HDF5:FullFileName_RBV", "shape": [20, 10], "dtype": "array", "dtype_numpy": "|i1", diff --git a/tests/devices/unit_tests/util/test_save_panda.py b/tests/devices/unit_tests/util/test_save_panda.py index 62b8ae673f..c766e3fd8d 100644 --- a/tests/devices/unit_tests/util/test_save_panda.py +++ b/tests/devices/unit_tests/util/test_save_panda.py @@ -25,7 +25,9 @@ def test_save_panda(): ): _save_panda("i03", "panda", directory, filename) - mock_make_device.assert_called_with("dodal.beamlines.i03", "panda") + mock_make_device.assert_called_with( + "dodal.beamlines.i03", "panda", connect_immediately=True + ) mock_store_settings.assert_called_with( mock_settings_provider(), "file.yml", @@ -55,63 +57,59 @@ def test_save_panda_failure_to_create_device_exits_with_failure_code(mock_exit, [ ( "i03", - ["--file-name=my_file_name.yml", "--output-directory=my_dir"], + ["--output-file=my_dir/my_file_name"], "i03", "panda", "my_dir", - "my_file_name.yml", + "my_file_name", 0, ), ( "i02", [ "--beamline=i04", - "--file-name=my_file_name.yml", - "--output-directory=my_dir", + "--output-file=my_dir/my_file_name", ], "i04", "panda", "my_dir", - "my_file_name.yml", + "my_file_name", 0, ), ( None, [ "--beamline=i04", - "--file-name=my_file_name.yml", - "--output-directory=my_dir", + "--output-file=my_dir/my_file_name", ], "i04", "panda", "my_dir", - "my_file_name.yml", + "my_file_name", 0, ), ( "i03", [ "--device-name=my_panda", - "--file-name=my_file_name.yml", - "--output-directory=my_dir", + "--output-file=my_dir/my_file_name", ], "i03", "my_panda", "my_dir", - "my_file_name.yml", + "my_file_name", 0, ), ( None, [ "--device-name=my_panda", - "--file-name=my_file_name.yml", - "--output-directory=my_dir", + "--output-file=my_dir/my_file_name", ], "i03", "my_panda", "my_dir", - "my_file_name.yml", + "my_file_name", 1, ), ], @@ -169,8 +167,7 @@ def test_file_exists_check( argv = [ "save_panda", "--beamline=i03", - "--file-name=test_output_file.yml", - f"--output-directory={tmpdir}", + f"--output-file={tmpdir}/test_output_file.yml", ] if force: argv.insert(1, "--force") @@ -178,11 +175,16 @@ def test_file_exists_check( with patch.dict("os.environ"): return_value = main(argv) - mock_path.assert_called_with("test_output_file.yml") + mock_path.assert_called_with( + f"{mock_path.return_value.parent}/{mock_path.return_value.name}" + ) exists.assert_called_once() if save_panda_called: mock_save_panda.assert_called_with( - "i03", "panda", tmpdir, "test_output_file.yml" + "i03", + "panda", + str(mock_path.return_value.parent), + str(mock_path.return_value.name), ) else: mock_save_panda.assert_not_called()