From c781e27691efde1dd7b4d185252840566b01d041 Mon Sep 17 00:00:00 2001 From: "Tom C (DLS)" <101418278+coretl@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:35:45 +0000 Subject: [PATCH] Move contents of `sim`, and rename `demo` -> `sim` (#708) - `ophyd_async.sim.demo` -> `ophyd_async.demo` - `ophyd_async.sim.testing` -> `ophyd_async.testing` - `ophyd_async.*.demo` -> `ophyd_async.*.sim` --- docs/examples/epics_demo.py | 10 ++-- docs/examples/tango_demo.py | 10 ++-- .../0009-procedural-vs-declarative-devices.md | 2 +- docs/how-to/compound-devices.rst | 4 +- docs/how-to/make-a-simple-device.rst | 8 +-- docs/how-to/write-tests-for-devices.rst | 10 ++-- docs/tutorials/using-existing-devices.rst | 2 +- pyproject.toml | 14 ++--- src/ophyd_async/core/_device.py | 2 +- .../epics/{demo => sim}/__init__.py | 0 src/ophyd_async/epics/{demo => sim}/_mover.py | 0 .../epics/{demo => sim}/_sensor.py | 0 src/ophyd_async/epics/{demo => sim}/mover.db | 0 src/ophyd_async/epics/{demo => sim}/sensor.db | 0 src/ophyd_async/sim/__init__.py | 19 +++++++ .../{demo => }/_pattern_detector/__init__.py | 0 .../_pattern_detector/_pattern_detector.py | 0 .../_pattern_detector_controller.py | 0 .../_pattern_detector_writer.py | 0 .../_pattern_detector/_pattern_generator.py | 0 src/ophyd_async/sim/{demo => }/_sim_motor.py | 0 src/ophyd_async/sim/demo/__init__.py | 19 ------- src/ophyd_async/sim/testing/__init__.py | 13 ----- .../tango/{demo => sim}/__init__.py | 0 .../tango/{demo => sim}/_counter.py | 0 .../tango/{demo => sim}/_detector.py | 0 src/ophyd_async/tango/{demo => sim}/_mover.py | 0 .../tango/{demo => sim}/_tango/__init__.py | 0 .../tango/{demo => sim}/_tango/_servers.py | 0 src/ophyd_async/testing/__init__.py | 10 ++++ .../{sim => }/testing/_one_of_everything.py | 0 tests/core/test_protocol.py | 2 +- .../test_demo.py => sim/test_epics_sim.py} | 52 +++++++++---------- tests/plan_stubs/test_settings.py | 3 +- tests/sim/conftest.py | 2 +- tests/sim/demo/__init__.py | 0 tests/sim/test_pattern_generator.py | 2 +- tests/sim/test_sim_detector.py | 2 +- tests/sim/{demo => }/test_sim_motor.py | 2 +- tests/sim/test_sim_writer.py | 2 +- tests/sim/test_streaming_plan.py | 2 +- tests/tango/test_base_device.py | 16 +++--- 42 files changed, 99 insertions(+), 109 deletions(-) rename src/ophyd_async/epics/{demo => sim}/__init__.py (100%) rename src/ophyd_async/epics/{demo => sim}/_mover.py (100%) rename src/ophyd_async/epics/{demo => sim}/_sensor.py (100%) rename src/ophyd_async/epics/{demo => sim}/mover.db (100%) rename src/ophyd_async/epics/{demo => sim}/sensor.db (100%) rename src/ophyd_async/sim/{demo => }/_pattern_detector/__init__.py (100%) rename src/ophyd_async/sim/{demo => }/_pattern_detector/_pattern_detector.py (100%) rename src/ophyd_async/sim/{demo => }/_pattern_detector/_pattern_detector_controller.py (100%) rename src/ophyd_async/sim/{demo => }/_pattern_detector/_pattern_detector_writer.py (100%) rename src/ophyd_async/sim/{demo => }/_pattern_detector/_pattern_generator.py (100%) rename src/ophyd_async/sim/{demo => }/_sim_motor.py (100%) delete mode 100644 src/ophyd_async/sim/demo/__init__.py delete mode 100644 src/ophyd_async/sim/testing/__init__.py rename src/ophyd_async/tango/{demo => sim}/__init__.py (100%) rename src/ophyd_async/tango/{demo => sim}/_counter.py (100%) rename src/ophyd_async/tango/{demo => sim}/_detector.py (100%) rename src/ophyd_async/tango/{demo => sim}/_mover.py (100%) rename src/ophyd_async/tango/{demo => sim}/_tango/__init__.py (100%) rename src/ophyd_async/tango/{demo => sim}/_tango/_servers.py (100%) rename src/ophyd_async/{sim => }/testing/_one_of_everything.py (100%) rename tests/epics/{demo/test_demo.py => sim/test_epics_sim.py} (89%) delete mode 100644 tests/sim/demo/__init__.py rename tests/sim/{demo => }/test_sim_motor.py (98%) diff --git a/docs/examples/epics_demo.py b/docs/examples/epics_demo.py index 8e446ba2e5..20b7ba18a4 100644 --- a/docs/examples/epics_demo.py +++ b/docs/examples/epics_demo.py @@ -8,7 +8,7 @@ from ophyd import Component, Device, EpicsSignal, EpicsSignalRO from ophyd_async.core import init_devices -from ophyd_async.epics import demo +from ophyd_async.epics import sim # Create a run engine, with plotting, progressbar and transform RE = RunEngine({}, call_returns_result=True) @@ -19,7 +19,7 @@ register_transform("RE", prefix="<") # Start IOC with demo pvs in subprocess -pv_prefix = demo.start_ioc_subprocess() +pv_prefix = sim.start_ioc_subprocess() # Create ophyd devices @@ -32,6 +32,6 @@ class OldSensor(Device): # Create ophyd-async devices with init_devices(): - det = demo.Sensor(pv_prefix) - det_group = demo.SensorGroup(pv_prefix) - samp = demo.SampleStage(pv_prefix) + det = sim.Sensor(pv_prefix) + det_group = sim.SensorGroup(pv_prefix) + samp = sim.SampleStage(pv_prefix) diff --git a/docs/examples/tango_demo.py b/docs/examples/tango_demo.py index 503dccd1ec..05cb2348a1 100644 --- a/docs/examples/tango_demo.py +++ b/docs/examples/tango_demo.py @@ -4,7 +4,7 @@ import bluesky.plans as bp from bluesky import RunEngine -from ophyd_async.tango.demo import ( +from ophyd_async.tango.sim import ( DemoCounter, DemoMover, TangoDetector, @@ -14,11 +14,11 @@ content = ( { "class": DemoMover, - "devices": [{"name": "demo/motor/1"}], + "devices": [{"name": "sim/motor/1"}], }, { "class": DemoCounter, - "devices": [{"name": "demo/counter/1"}, {"name": "demo/counter/2"}], + "devices": [{"name": "sim/counter/1"}, {"name": "sim/counter/2"}], }, ) @@ -30,8 +30,8 @@ async def main(): detector = TangoDetector( trl="", name="detector", - counters_kwargs={"prefix": "demo/counter/", "count": 2}, - mover_kwargs={"trl": "demo/motor/1"}, + counters_kwargs={"prefix": "sim/counter/", "count": 2}, + mover_kwargs={"trl": "sim/motor/1"}, ) await detector.connect() diff --git a/docs/explanations/decisions/0009-procedural-vs-declarative-devices.md b/docs/explanations/decisions/0009-procedural-vs-declarative-devices.md index 9572b7b583..f29ecc7ced 100644 --- a/docs/explanations/decisions/0009-procedural-vs-declarative-devices.md +++ b/docs/explanations/decisions/0009-procedural-vs-declarative-devices.md @@ -62,7 +62,7 @@ The two approaches now look like: ```python class Sensor(StandardReadable, EpicsDevice): - """A demo sensor that produces a scalar value based on X and Y Movers""" + """A sim sensor that produces a scalar value based on X and Y Movers""" value: A[SignalR[float], PvSuffix("Value"), Format.HINTED_SIGNAL] mode: A[SignalRW[EnergyMode], PvSuffix("Mode"), Format.CONFIG_SIGNAL] diff --git a/docs/how-to/compound-devices.rst b/docs/how-to/compound-devices.rst index ef4aaf818a..ee95746b05 100644 --- a/docs/how-to/compound-devices.rst +++ b/docs/how-to/compound-devices.rst @@ -11,7 +11,7 @@ Assembly Compound assemblies can be used to group Devices into larger logical Devices: -.. literalinclude:: ../../src/ophyd_async/epics/demo/_mover.py +.. literalinclude:: ../../src/ophyd_async/epics/sim/_mover.py :pyobject: SampleStage This applies prefixes on construction: @@ -35,7 +35,7 @@ Grouping by Index Sometimes, it makes sense to group devices by number, say an array of sensors: -.. literalinclude:: ../../src/ophyd_async/epics/demo/_sensor.py +.. literalinclude:: ../../src/ophyd_async/epics/sim/_sensor.py :pyobject: SensorGroup :class:`~ophyd-async.core.DeviceVector` allows writing maintainable, arbitrary-length device groups instead of fixed classes for each possible grouping. A :class:`~ophyd-async.core.DeviceVector` can be accessed via indices, for example: ``my_sensor_group.sensors[2]``. Here ``sensors`` is a dictionary with integer indices rather than a list so that the most semantically sensible indices may be used, the sensor group above may be 1-indexed, for example, because the sensors' datasheet calls them "sensor 1", "sensor 2" etc. diff --git a/docs/how-to/make-a-simple-device.rst b/docs/how-to/make-a-simple-device.rst index 40edd36426..5d2170c9c0 100644 --- a/docs/how-to/make-a-simple-device.rst +++ b/docs/how-to/make-a-simple-device.rst @@ -13,7 +13,7 @@ To make a simple device, you need to subclass from the other suitable Bluesky `Protocols ` like :external+bluesky:py:class:`bluesky.protocols.Movable`. -The rest of this guide will show examples from ``src/ophyd_async/epics/demo/__init__.py`` +The rest of this guide will show examples from ``src/ophyd_async/epics/sim/__init__.py`` Readable -------- @@ -22,7 +22,7 @@ For a simple :external+bluesky:py:class:`bluesky.protocols.Readable` object like define some signals, then tell the superclass which signals should contribute to ``read()`` and ``read_configuration()``: -.. literalinclude:: ../../src/ophyd_async/epics/demo/_sensor.py +.. literalinclude:: ../../src/ophyd_async/epics/sim/_sensor.py :pyobject: Sensor First some Signals are constructed and stored on the Device. Each one is passed @@ -54,7 +54,7 @@ Movable For a more complicated device like a `Mover`, you can still use `StandardReadable` and implement some addition protocols: -.. literalinclude:: ../../src/ophyd_async/epics/demo/_mover.py +.. literalinclude:: ../../src/ophyd_async/epics/sim/_mover.py :pyobject: Mover The ``set()`` method implements :external+bluesky:py:class:`bluesky.protocols.Movable`. This @@ -71,7 +71,7 @@ Assembly Compound assemblies can be used to group Devices into larger logical Devices: -.. literalinclude:: ../../src/ophyd_async/epics/demo/_mover.py +.. literalinclude:: ../../src/ophyd_async/epics/sim/_mover.py :pyobject: SampleStage This applies prefixes on construction: diff --git a/docs/how-to/write-tests-for-devices.rst b/docs/how-to/write-tests-for-devices.rst index f42cf3af8b..596d141d71 100644 --- a/docs/how-to/write-tests-for-devices.rst +++ b/docs/how-to/write-tests-for-devices.rst @@ -26,7 +26,7 @@ Mock Backend Ophyd devices initialized with a mock backend behave in a similar way to mocks, without requiring you to mock out all the dependencies and internals. The `init_devices` can initialize any number of devices, and their signals and sub-devices (recursively), with a mock backend. -.. literalinclude:: ../../tests/epics/demo/test_demo.py +.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py :pyobject: mock_sensor @@ -37,26 +37,26 @@ Mock signals behave as simply as possible, holding a sensible default value when In addition this example also utilizes helper functions like ``assert_reading`` and ``assert_value`` to ensure the validity of device readings and values. For more information see: :doc:`API.core<../_api/ophyd_async.core>` -.. literalinclude:: ../../tests/epics/demo/test_demo.py +.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py :pyobject: test_sensor_reading_shows_value Given that the mock signal holds a ``unittest.mock.Mock`` object you can retrieve this object and assert that the device has been set correctly using ``get_mock_put``. You are also free to use any other behaviour that ``unittest.mock.Mock`` provides, such as in this example which sets the parent of the mock to allow ordering across signals to be asserted: -.. literalinclude:: ../../tests/epics/demo/test_demo.py +.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py :pyobject: test_retrieve_mock_and_assert There are several other test utility functions: Use ``callback_on_mock_put``, for hooking in logic when a mock value changes (e.g. because someone puts to it). This can be called directly, or used as a context, with the callbacks ending after exit. -.. literalinclude:: ../../tests/epics/demo/test_demo.py +.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py :pyobject: test_mover_stopped Testing a Device in a Plan with the RunEngine --------------------------------------------- -.. literalinclude:: ../../tests/epics/demo/test_demo.py +.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py :pyobject: test_sensor_in_plan diff --git a/docs/tutorials/using-existing-devices.rst b/docs/tutorials/using-existing-devices.rst index d8ff51f4da..77a031b39b 100644 --- a/docs/tutorials/using-existing-devices.rst +++ b/docs/tutorials/using-existing-devices.rst @@ -41,7 +41,7 @@ that you can mix Ophyd and Ophyd Async devices in the same RunEngine: :start-after: # Create ophyd devices :end-before: # Create ophyd-async devices -Finally we create the Ophyd Async devices imported from the `epics.demo` module: +Finally we create the Ophyd Async devices imported from the `epics.sim` module: .. literalinclude:: ../examples/epics_demo.py :language: python diff --git a/pyproject.toml b/pyproject.toml index f07aef8504..4ea06147cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -183,18 +183,12 @@ exhaustive = true exhaustive_ignores = ["testing", "_version", "__main__"] [[tool.importlinter.contracts]] -name = "Testing modules" -type = "layers" -containers = ["ophyd_async"] -layers = ["testing", "core"] - -[[tool.importlinter.contracts]] -name = "Testing modules are not used at runtime" +name = "Testing and sim modules are not used at runtime" type = "forbidden" -source_modules = "ophyd_async.testing" -forbidden_modules = [ +forbidden_modules = ["ophyd_async.testing", "ophyd_async.sim"] +source_modules = [ "ophyd_async.plan_stubs", - "ophyd_async.fastcs", + "ophyd_async.fast.*", "ophyd_async.epics", "ophyd_async.tango", ] diff --git a/src/ophyd_async/core/_device.py b/src/ophyd_async/core/_device.py index 54a70dc746..8f12607591 100644 --- a/src/ophyd_async/core/_device.py +++ b/src/ophyd_async/core/_device.py @@ -206,7 +206,7 @@ class DeviceVector(MutableMapping[int, DeviceT], Device): In the below example, foos becomes a dictionary on the parent device at runtime, so parent.foos[2] returns a FooDevice. For example usage see - :class:`~ophyd_async.epics.demo.DynamicSensorGroup` + :class:`~ophyd_async.epics.sim.DynamicSensorGroup` """ def __init__( diff --git a/src/ophyd_async/epics/demo/__init__.py b/src/ophyd_async/epics/sim/__init__.py similarity index 100% rename from src/ophyd_async/epics/demo/__init__.py rename to src/ophyd_async/epics/sim/__init__.py diff --git a/src/ophyd_async/epics/demo/_mover.py b/src/ophyd_async/epics/sim/_mover.py similarity index 100% rename from src/ophyd_async/epics/demo/_mover.py rename to src/ophyd_async/epics/sim/_mover.py diff --git a/src/ophyd_async/epics/demo/_sensor.py b/src/ophyd_async/epics/sim/_sensor.py similarity index 100% rename from src/ophyd_async/epics/demo/_sensor.py rename to src/ophyd_async/epics/sim/_sensor.py diff --git a/src/ophyd_async/epics/demo/mover.db b/src/ophyd_async/epics/sim/mover.db similarity index 100% rename from src/ophyd_async/epics/demo/mover.db rename to src/ophyd_async/epics/sim/mover.db diff --git a/src/ophyd_async/epics/demo/sensor.db b/src/ophyd_async/epics/sim/sensor.db similarity index 100% rename from src/ophyd_async/epics/demo/sensor.db rename to src/ophyd_async/epics/sim/sensor.db diff --git a/src/ophyd_async/sim/__init__.py b/src/ophyd_async/sim/__init__.py index e69de29bb2..fa19366c11 100644 --- a/src/ophyd_async/sim/__init__.py +++ b/src/ophyd_async/sim/__init__.py @@ -0,0 +1,19 @@ +from ._pattern_detector import ( + DATA_PATH, + SUM_PATH, + PatternDetector, + PatternDetectorController, + PatternDetectorWriter, + PatternGenerator, +) +from ._sim_motor import SimMotor + +__all__ = [ + "DATA_PATH", + "SUM_PATH", + "PatternGenerator", + "PatternDetector", + "PatternDetectorController", + "PatternDetectorWriter", + "SimMotor", +] diff --git a/src/ophyd_async/sim/demo/_pattern_detector/__init__.py b/src/ophyd_async/sim/_pattern_detector/__init__.py similarity index 100% rename from src/ophyd_async/sim/demo/_pattern_detector/__init__.py rename to src/ophyd_async/sim/_pattern_detector/__init__.py diff --git a/src/ophyd_async/sim/demo/_pattern_detector/_pattern_detector.py b/src/ophyd_async/sim/_pattern_detector/_pattern_detector.py similarity index 100% rename from src/ophyd_async/sim/demo/_pattern_detector/_pattern_detector.py rename to src/ophyd_async/sim/_pattern_detector/_pattern_detector.py diff --git a/src/ophyd_async/sim/demo/_pattern_detector/_pattern_detector_controller.py b/src/ophyd_async/sim/_pattern_detector/_pattern_detector_controller.py similarity index 100% rename from src/ophyd_async/sim/demo/_pattern_detector/_pattern_detector_controller.py rename to src/ophyd_async/sim/_pattern_detector/_pattern_detector_controller.py diff --git a/src/ophyd_async/sim/demo/_pattern_detector/_pattern_detector_writer.py b/src/ophyd_async/sim/_pattern_detector/_pattern_detector_writer.py similarity index 100% rename from src/ophyd_async/sim/demo/_pattern_detector/_pattern_detector_writer.py rename to src/ophyd_async/sim/_pattern_detector/_pattern_detector_writer.py diff --git a/src/ophyd_async/sim/demo/_pattern_detector/_pattern_generator.py b/src/ophyd_async/sim/_pattern_detector/_pattern_generator.py similarity index 100% rename from src/ophyd_async/sim/demo/_pattern_detector/_pattern_generator.py rename to src/ophyd_async/sim/_pattern_detector/_pattern_generator.py diff --git a/src/ophyd_async/sim/demo/_sim_motor.py b/src/ophyd_async/sim/_sim_motor.py similarity index 100% rename from src/ophyd_async/sim/demo/_sim_motor.py rename to src/ophyd_async/sim/_sim_motor.py diff --git a/src/ophyd_async/sim/demo/__init__.py b/src/ophyd_async/sim/demo/__init__.py deleted file mode 100644 index fa19366c11..0000000000 --- a/src/ophyd_async/sim/demo/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -from ._pattern_detector import ( - DATA_PATH, - SUM_PATH, - PatternDetector, - PatternDetectorController, - PatternDetectorWriter, - PatternGenerator, -) -from ._sim_motor import SimMotor - -__all__ = [ - "DATA_PATH", - "SUM_PATH", - "PatternGenerator", - "PatternDetector", - "PatternDetectorController", - "PatternDetectorWriter", - "SimMotor", -] diff --git a/src/ophyd_async/sim/testing/__init__.py b/src/ophyd_async/sim/testing/__init__.py deleted file mode 100644 index 90c6b8f836..0000000000 --- a/src/ophyd_async/sim/testing/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -from ._one_of_everything import ( - ExampleEnum, - ExampleTable, - OneOfEverythingDevice, - ParentOfEverythingDevice, -) - -__all__ = [ - "ExampleEnum", - "ExampleTable", - "OneOfEverythingDevice", - "ParentOfEverythingDevice", -] diff --git a/src/ophyd_async/tango/demo/__init__.py b/src/ophyd_async/tango/sim/__init__.py similarity index 100% rename from src/ophyd_async/tango/demo/__init__.py rename to src/ophyd_async/tango/sim/__init__.py diff --git a/src/ophyd_async/tango/demo/_counter.py b/src/ophyd_async/tango/sim/_counter.py similarity index 100% rename from src/ophyd_async/tango/demo/_counter.py rename to src/ophyd_async/tango/sim/_counter.py diff --git a/src/ophyd_async/tango/demo/_detector.py b/src/ophyd_async/tango/sim/_detector.py similarity index 100% rename from src/ophyd_async/tango/demo/_detector.py rename to src/ophyd_async/tango/sim/_detector.py diff --git a/src/ophyd_async/tango/demo/_mover.py b/src/ophyd_async/tango/sim/_mover.py similarity index 100% rename from src/ophyd_async/tango/demo/_mover.py rename to src/ophyd_async/tango/sim/_mover.py diff --git a/src/ophyd_async/tango/demo/_tango/__init__.py b/src/ophyd_async/tango/sim/_tango/__init__.py similarity index 100% rename from src/ophyd_async/tango/demo/_tango/__init__.py rename to src/ophyd_async/tango/sim/_tango/__init__.py diff --git a/src/ophyd_async/tango/demo/_tango/_servers.py b/src/ophyd_async/tango/sim/_tango/_servers.py similarity index 100% rename from src/ophyd_async/tango/demo/_tango/_servers.py rename to src/ophyd_async/tango/sim/_tango/_servers.py diff --git a/src/ophyd_async/testing/__init__.py b/src/ophyd_async/testing/__init__.py index f688107428..ac8e1bcf9e 100644 --- a/src/ophyd_async/testing/__init__.py +++ b/src/ophyd_async/testing/__init__.py @@ -14,6 +14,12 @@ set_mock_value, set_mock_values, ) +from ._one_of_everything import ( + ExampleEnum, + ExampleTable, + OneOfEverythingDevice, + ParentOfEverythingDevice, +) from ._wait_for_pending import wait_for_pending_wakeups __all__ = [ @@ -30,4 +36,8 @@ "set_mock_value", "set_mock_values", "wait_for_pending_wakeups", + "ExampleEnum", + "ExampleTable", + "OneOfEverythingDevice", + "ParentOfEverythingDevice", ] diff --git a/src/ophyd_async/sim/testing/_one_of_everything.py b/src/ophyd_async/testing/_one_of_everything.py similarity index 100% rename from src/ophyd_async/sim/testing/_one_of_everything.py rename to src/ophyd_async/testing/_one_of_everything.py diff --git a/tests/core/test_protocol.py b/tests/core/test_protocol.py index 5d584b2dd1..8bce162302 100644 --- a/tests/core/test_protocol.py +++ b/tests/core/test_protocol.py @@ -10,7 +10,7 @@ init_devices, ) from ophyd_async.epics import adsimdetector -from ophyd_async.sim.demo import SimMotor +from ophyd_async.sim import SimMotor async def make_detector(prefix: str, name: str, tmp_path: Path): diff --git a/tests/epics/demo/test_demo.py b/tests/epics/sim/test_epics_sim.py similarity index 89% rename from tests/epics/demo/test_demo.py rename to tests/epics/sim/test_epics_sim.py index 2fc6d3d808..7385fca843 100644 --- a/tests/epics/demo/test_demo.py +++ b/tests/epics/sim/test_epics_sim.py @@ -13,7 +13,7 @@ NotConnected, init_devices, ) -from ophyd_async.epics import demo +from ophyd_async.epics import sim from ophyd_async.testing import ( assert_emitted, assert_reading, @@ -27,9 +27,9 @@ @pytest.fixture -async def mock_mover() -> demo.Mover: +async def mock_mover() -> sim.Mover: async with init_devices(mock=True): - mock_mover = demo.Mover("BLxxI-MO-TABLE-01:X:") + mock_mover = sim.Mover("BLxxI-MO-TABLE-01:X:") # Signals connected here assert mock_mover.name == "mock_mover" @@ -40,9 +40,9 @@ async def mock_mover() -> demo.Mover: @pytest.fixture -async def mock_sensor() -> demo.Sensor: +async def mock_sensor() -> sim.Sensor: async with init_devices(mock=True): - mock_sensor = demo.Sensor("MOCK:SENSOR:") + mock_sensor = sim.Sensor("MOCK:SENSOR:") # Signals connected here assert mock_sensor.name == "mock_sensor" @@ -50,16 +50,16 @@ async def mock_sensor() -> demo.Sensor: @pytest.fixture -async def mock_sensor_group() -> demo.SensorGroup: +async def mock_sensor_group() -> sim.SensorGroup: async with init_devices(mock=True): - mock_sensor_group = demo.SensorGroup("MOCK:SENSOR:") + mock_sensor_group = sim.SensorGroup("MOCK:SENSOR:") # Signals connected here assert mock_sensor_group.name == "mock_sensor_group" return mock_sensor_group -async def test_mover_stopped(mock_mover: demo.Mover): +async def test_mover_stopped(mock_mover: sim.Mover): callbacks = [] callback_on_mock_put( mock_mover.stop_, lambda v, *args, **kwargs: callbacks.append(v) @@ -109,7 +109,7 @@ async def wait_for_call(self, *args, **kwargs): self._event.clear() -async def test_mover_moving_well(mock_mover: demo.Mover) -> None: +async def test_mover_moving_well(mock_mover: sim.Mover) -> None: s = mock_mover.set(0.55) watcher = DemoWatcher() s.watch(watcher) @@ -149,7 +149,7 @@ async def test_mover_moving_well(mock_mover: demo.Mover) -> None: done2.assert_called_once_with(s) -async def test_sensor_reading_shows_value(mock_sensor: demo.Sensor): +async def test_sensor_reading_shows_value(mock_sensor: sim.Sensor): # Check default value await assert_value(mock_sensor.value, pytest.approx(0.0)) assert (await mock_sensor.value.get_value()) == pytest.approx(0.0) @@ -177,7 +177,7 @@ async def test_sensor_reading_shows_value(mock_sensor: demo.Sensor): ) -async def test_retrieve_mock_and_assert(mock_mover: demo.Mover): +async def test_retrieve_mock_and_assert(mock_mover: sim.Mover): mover_setpoint_mock = get_mock_put(mock_mover.setpoint) await mock_mover.setpoint.set(10) mover_setpoint_mock.assert_called_once_with(10, wait=ANY) @@ -199,7 +199,7 @@ async def test_retrieve_mock_and_assert(mock_mover: demo.Mover): async def test_mocks_in_device_share_parent(): lm = LazyMock() - mock_mover = demo.Mover("BLxxI-MO-TABLE-01:Y:") + mock_mover = sim.Mover("BLxxI-MO-TABLE-01:Y:") await mock_mover.connect(mock=lm) mock = lm() @@ -221,7 +221,7 @@ async def test_mocks_in_device_share_parent(): ] -async def test_read_mover(mock_mover: demo.Mover): +async def test_read_mover(mock_mover: sim.Mover): await mock_mover.stage() assert (await mock_mover.read())["mock_mover"]["value"] == 0.0 assert (await mock_mover.read_configuration())["mock_mover-velocity"]["value"] == 1 @@ -237,7 +237,7 @@ async def test_read_mover(mock_mover: demo.Mover): assert await mock_mover.describe() -async def test_set_velocity(mock_mover: demo.Mover) -> None: +async def test_set_velocity(mock_mover: sim.Mover) -> None: v = mock_mover.velocity q: asyncio.Queue[dict[str, Reading]] = asyncio.Queue() v.subscribe(q.put_nowait) @@ -253,7 +253,7 @@ async def test_set_velocity(mock_mover: demo.Mover) -> None: async def test_mover_disconnected(): with pytest.raises(NotConnected): async with init_devices(timeout=0.1): - m = demo.Mover("ca://PRE:", name="mover") + m = sim.Mover("ca://PRE:", name="mover") assert m.name == "mover" @@ -261,7 +261,7 @@ async def test_sensor_disconnected(caplog): caplog.set_level(10) with pytest.raises(NotConnected): async with init_devices(timeout=0.1): - s = demo.Sensor("ca://PRE:", name="sensor") + s = sim.Sensor("ca://PRE:", name="sensor") logs = caplog.get_records("call") logs = [log for log in logs if "_signal" not in log.pathname] assert len(logs) == 2 @@ -274,21 +274,21 @@ async def test_sensor_disconnected(caplog): assert s.name == "sensor" -async def test_read_sensor(mock_sensor: demo.Sensor): +async def test_read_sensor(mock_sensor: sim.Sensor): assert (await mock_sensor.read())["mock_sensor-value"]["value"] == 0 assert (await mock_sensor.read_configuration())["mock_sensor-mode"][ "value" - ] == demo.EnergyMode.LOW + ] == sim.EnergyMode.LOW desc = (await mock_sensor.describe_configuration())["mock_sensor-mode"] assert desc["dtype"] == "string" assert desc["choices"] == ["Low Energy", "High Energy"] - set_mock_value(mock_sensor.mode, demo.EnergyMode.HIGH) + set_mock_value(mock_sensor.mode, sim.EnergyMode.HIGH) assert (await mock_sensor.read_configuration())["mock_sensor-mode"][ "value" - ] == demo.EnergyMode.HIGH + ] == sim.EnergyMode.HIGH -async def test_sensor_in_plan(RE: RunEngine, mock_sensor: demo.Sensor): +async def test_sensor_in_plan(RE: RunEngine, mock_sensor: sim.Sensor): """Tests mock sensor behavior within a RunEngine plan. This test verifies that the sensor emits the expected documents @@ -302,7 +302,7 @@ async def test_sensor_in_plan(RE: RunEngine, mock_sensor: demo.Sensor): async def test_assembly_renaming() -> None: - thing = demo.SampleStage("PRE") + thing = sim.SampleStage("PRE") await thing.connect(mock=True) assert thing.x.name == "" assert thing.x.velocity.name == "" @@ -318,7 +318,7 @@ async def test_assembly_renaming() -> None: async def test_dynamic_sensor_group_disconnected(): with pytest.raises(NotConnected) as e: async with init_devices(timeout=0.1): - mock_sensor_group_dynamic = demo.SensorGroup("MOCK:SENSOR:") + mock_sensor_group_dynamic = sim.SensorGroup("MOCK:SENSOR:") expected = """ mock_sensor_group_dynamic: NotConnected: sensors: NotConnected: @@ -338,7 +338,7 @@ async def test_dynamic_sensor_group_disconnected(): async def test_dynamic_sensor_group_read_and_describe( - mock_sensor_group: demo.SensorGroup, + mock_sensor_group: sim.SensorGroup, ): set_mock_value(mock_sensor_group.sensors[1].value, 0.0) set_mock_value(mock_sensor_group.sensors[2].value, 0.5) @@ -390,9 +390,9 @@ async def test_dynamic_sensor_group_read_and_describe( } -@patch("ophyd_async.epics.demo.subprocess.Popen") +@patch("ophyd_async.epics.sim.subprocess.Popen") async def test_ioc_starts(mock_popen: Mock): - demo.start_ioc_subprocess() + sim.start_ioc_subprocess() mock_popen.assert_called_once_with( ANY, stdin=subprocess.PIPE, diff --git a/tests/plan_stubs/test_settings.py b/tests/plan_stubs/test_settings.py index 4f8c7caf4a..6f49767d1f 100644 --- a/tests/plan_stubs/test_settings.py +++ b/tests/plan_stubs/test_settings.py @@ -13,8 +13,7 @@ retrieve_settings, store_settings, ) -from ophyd_async.sim.testing import ExampleTable, ParentOfEverythingDevice -from ophyd_async.testing import get_mock +from ophyd_async.testing import ExampleTable, ParentOfEverythingDevice, get_mock TEST_DATA = Path(__file__).absolute().parent.parent / "test_data" diff --git a/tests/sim/conftest.py b/tests/sim/conftest.py index b02740c082..75809dfb95 100644 --- a/tests/sim/conftest.py +++ b/tests/sim/conftest.py @@ -2,7 +2,7 @@ import pytest -from ophyd_async.sim.demo import PatternDetector +from ophyd_async.sim import PatternDetector @pytest.fixture diff --git a/tests/sim/demo/__init__.py b/tests/sim/demo/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/sim/test_pattern_generator.py b/tests/sim/test_pattern_generator.py index a8522c59c5..745e64cfc7 100644 --- a/tests/sim/test_pattern_generator.py +++ b/tests/sim/test_pattern_generator.py @@ -1,6 +1,6 @@ import pytest -from ophyd_async.sim.demo import PatternGenerator +from ophyd_async.sim import PatternGenerator @pytest.fixture diff --git a/tests/sim/test_sim_detector.py b/tests/sim/test_sim_detector.py index 2b05d652b2..4d8cd44cac 100644 --- a/tests/sim/test_sim_detector.py +++ b/tests/sim/test_sim_detector.py @@ -7,7 +7,7 @@ from bluesky import RunEngine from ophyd_async.plan_stubs import ensure_connected -from ophyd_async.sim.demo import PatternDetector +from ophyd_async.sim import PatternDetector from ophyd_async.testing import assert_emitted diff --git a/tests/sim/demo/test_sim_motor.py b/tests/sim/test_sim_motor.py similarity index 98% rename from tests/sim/demo/test_sim_motor.py rename to tests/sim/test_sim_motor.py index 0106c48cdb..cac4cb7106 100644 --- a/tests/sim/demo/test_sim_motor.py +++ b/tests/sim/test_sim_motor.py @@ -6,7 +6,7 @@ from bluesky.run_engine import RunEngine from ophyd_async.core import init_devices -from ophyd_async.sim.demo import SimMotor +from ophyd_async.sim import SimMotor async def test_move_sim_in_plan(): diff --git a/tests/sim/test_sim_writer.py b/tests/sim/test_sim_writer.py index fd0a1e6a77..9422eca0ef 100644 --- a/tests/sim/test_sim_writer.py +++ b/tests/sim/test_sim_writer.py @@ -3,7 +3,7 @@ import pytest from ophyd_async.core import init_devices -from ophyd_async.sim.demo import PatternDetectorWriter, PatternGenerator +from ophyd_async.sim import PatternDetectorWriter, PatternGenerator @pytest.fixture diff --git a/tests/sim/test_streaming_plan.py b/tests/sim/test_streaming_plan.py index 31611514d0..dfc8a1892f 100644 --- a/tests/sim/test_streaming_plan.py +++ b/tests/sim/test_streaming_plan.py @@ -4,7 +4,7 @@ from bluesky.run_engine import RunEngine from ophyd_async.plan_stubs import ensure_connected -from ophyd_async.sim.demo import PatternDetector +from ophyd_async.sim import PatternDetector from ophyd_async.testing import assert_emitted diff --git a/tests/tango/test_base_device.py b/tests/tango/test_base_device.py index 365fe7ee2b..6802952cc2 100644 --- a/tests/tango/test_base_device.py +++ b/tests/tango/test_base_device.py @@ -13,7 +13,7 @@ from ophyd_async.core import Array1D, SignalRW, T, init_devices from ophyd_async.core import StandardReadableFormat as Format from ophyd_async.tango.core import TangoReadable, get_python_type -from ophyd_async.tango.demo import ( +from ophyd_async.tango.sim import ( DemoCounter, DemoMover, TangoDetector, @@ -269,15 +269,15 @@ def tango_test_device(): # -------------------------------------------------------------------- @pytest.fixture(scope="module") -def demo_test_context(): +def sim_test_context(): content = ( { "class": DemoMover, - "devices": [{"name": "demo/motor/1"}], + "devices": [{"name": "sim/motor/1"}], }, { "class": DemoCounter, - "devices": [{"name": "demo/counter/1"}, {"name": "demo/counter/2"}], + "devices": [{"name": "sim/counter/1"}, {"name": "sim/counter/2"}], }, ) yield MultiDeviceTestContext(content, process=True) @@ -356,12 +356,12 @@ async def test_with_bluesky(tango_test_device): # -------------------------------------------------------------------- @pytest.mark.asyncio -async def test_tango_demo(demo_test_context): - with demo_test_context: +async def test_tango_sim(sim_test_context): + with sim_test_context: detector = TangoDetector( name="detector", - mover_trl="demo/motor/1", - counter_trls=["demo/counter/1", "demo/counter/2"], + mover_trl="sim/motor/1", + counter_trls=["sim/counter/1", "sim/counter/2"], ) await detector.connect() await detector.trigger()