From c3635f75f3087b4c7e06146c9147e7913f9852f1 Mon Sep 17 00:00:00 2001 From: Eva Lott Date: Fri, 31 May 2024 11:23:00 +0100 Subject: [PATCH] moved save and load to plan stubs --- src/ophyd_async/core/__init__.py | 16 ---------------- src/ophyd_async/plan_stubs/__init__.py | 8 +++++++- .../{core => plan_stubs}/device_save_loader.py | 4 ++-- tests/epics/test_signals.py | 3 ++- tests/panda/test_panda_utils.py | 4 ++-- .../test_device_save_loader.py | 12 +++++++----- 6 files changed, 20 insertions(+), 27 deletions(-) rename src/ophyd_async/{core => plan_stubs}/device_save_loader.py (99%) rename tests/{core => plan_stubs}/test_device_save_loader.py (96%) diff --git a/src/ophyd_async/core/__init__.py b/src/ophyd_async/core/__init__.py index a5351757ec..d890dca963 100644 --- a/src/ophyd_async/core/__init__.py +++ b/src/ophyd_async/core/__init__.py @@ -14,15 +14,6 @@ TriggerInfo, ) from .device import Device, DeviceCollector, DeviceVector -from .device_save_loader import ( - get_signal_values, - load_device, - load_from_yaml, - save_device, - save_to_yaml, - set_signal_values, - walk_rw_signals, -) from .flyer import HardwareTriggeredFlyable, TriggerLogic from .mock_signal_backend import MockSignalBackend from .mock_signal_utils import ( @@ -119,13 +110,6 @@ "get_unique", "merge_gathered_dicts", "wait_for_connection", - "get_signal_values", - "load_from_yaml", - "save_to_yaml", - "set_signal_values", - "walk_rw_signals", - "load_device", - "save_device", "assert_reading", "assert_value", "assert_configuration", diff --git a/src/ophyd_async/plan_stubs/__init__.py b/src/ophyd_async/plan_stubs/__init__.py index 360ee38b54..914614668e 100644 --- a/src/ophyd_async/plan_stubs/__init__.py +++ b/src/ophyd_async/plan_stubs/__init__.py @@ -1,3 +1,7 @@ +from .device_save_loader import ( + load_device, + save_device, +) from .ensure_connected import ensure_connected from .fly import ( fly_and_collect, @@ -6,8 +10,10 @@ ) __all__ = [ + "load_device", + "save_device", + "ensure_connected", "fly_and_collect", "prepare_static_seq_table_flyer_and_detectors_with_same_trigger", "time_resolved_fly_and_collect_with_static_seq_table", - "ensure_connected", ] diff --git a/src/ophyd_async/core/device_save_loader.py b/src/ophyd_async/plan_stubs/device_save_loader.py similarity index 99% rename from src/ophyd_async/core/device_save_loader.py rename to src/ophyd_async/plan_stubs/device_save_loader.py index 88168b462d..2012228b58 100644 --- a/src/ophyd_async/core/device_save_loader.py +++ b/src/ophyd_async/plan_stubs/device_save_loader.py @@ -10,8 +10,8 @@ from bluesky.utils import Msg from epicscorelibs.ca.dbr import ca_array, ca_float, ca_int, ca_str -from .device import Device -from .signal import SignalRW +from ..core.device import Device +from ..core.signal import SignalRW CaType = Union[ca_float, ca_int, ca_str, ca_array] diff --git a/tests/epics/test_signals.py b/tests/epics/test_signals.py index ff6fce24f6..97db248af1 100644 --- a/tests/epics/test_signals.py +++ b/tests/epics/test_signals.py @@ -28,7 +28,7 @@ from aioca import CANothing, purge_channel_caches from bluesky.protocols import Reading -from ophyd_async.core import SignalBackend, T, get_dtype, load_from_yaml, save_to_yaml +from ophyd_async.core import SignalBackend, T, get_dtype from ophyd_async.core.utils import NotConnected from ophyd_async.epics.signal._epics_transport import EpicsTransport from ophyd_async.epics.signal.signal import ( @@ -39,6 +39,7 @@ epics_signal_w, epics_signal_x, ) +from ophyd_async.plan_stubs.device_save_loader import load_from_yaml, save_to_yaml RECORDS = str(Path(__file__).parent / "test_records.db") PV_PREFIX = "".join(random.choice(string.ascii_lowercase) for _ in range(12)) diff --git a/tests/panda/test_panda_utils.py b/tests/panda/test_panda_utils.py index 4bae8a0a1c..a6da652ecd 100644 --- a/tests/panda/test_panda_utils.py +++ b/tests/panda/test_panda_utils.py @@ -3,7 +3,6 @@ import pytest from bluesky import RunEngine -from ophyd_async.core import save_device from ophyd_async.core.device import DeviceCollector from ophyd_async.core.utils import DEFAULT_TIMEOUT from ophyd_async.epics.pvi import fill_pvi_entries @@ -11,6 +10,7 @@ from ophyd_async.panda import CommonPandaBlocks, TimeUnits from ophyd_async.panda._common_blocks import DataBlock from ophyd_async.panda._utils import phase_sorter +from ophyd_async.plan_stubs import save_device @pytest.fixture @@ -35,7 +35,7 @@ async def connect(self, mock: bool = False, timeout: float = DEFAULT_TIMEOUT): yield mock_panda -@patch("ophyd_async.core.device_save_loader.save_to_yaml") +@patch("ophyd_async.plan_stubs.device_save_loader.save_to_yaml") async def test_save_panda(mock_save_to_yaml, mock_panda, RE: RunEngine): RE(save_device(mock_panda, "path", sorter=phase_sorter)) mock_save_to_yaml.assert_called_once() diff --git a/tests/core/test_device_save_loader.py b/tests/plan_stubs/test_device_save_loader.py similarity index 96% rename from tests/core/test_device_save_loader.py rename to tests/plan_stubs/test_device_save_loader.py index 688c0cdfb5..f173a59620 100644 --- a/tests/core/test_device_save_loader.py +++ b/tests/plan_stubs/test_device_save_loader.py @@ -13,6 +13,10 @@ Device, SignalR, SignalRW, +) +from ophyd_async.epics.signal import epics_signal_r, epics_signal_rw +from ophyd_async.plan_stubs.device_save_loader import ( + all_at_once, get_signal_values, load_device, load_from_yaml, @@ -21,8 +25,6 @@ set_signal_values, walk_rw_signals, ) -from ophyd_async.core.device_save_loader import all_at_once -from ophyd_async.epics.signal import epics_signal_r, epics_signal_rw class DummyChildDevice(Device): @@ -178,9 +180,9 @@ async def test_set_signal_values_restores_value(RE: RunEngine, device, tmp_path) assert np.array_equal(array_value, np.array([1, 1, 1, 1, 1])) -@patch("ophyd_async.core.device_save_loader.load_from_yaml") -@patch("ophyd_async.core.device_save_loader.walk_rw_signals") -@patch("ophyd_async.core.device_save_loader.set_signal_values") +@patch("ophyd_async.plan_stubs.device_save_loader.load_from_yaml") +@patch("ophyd_async.plan_stubs.device_save_loader.walk_rw_signals") +@patch("ophyd_async.plan_stubs.device_save_loader.set_signal_values") async def test_load_device( mock_set_signal_values, mock_walk_rw_signals, mock_load_from_yaml, device ):