Skip to content

Commit 400fe84

Browse files
authored
Update to use default motor mock in ophyd_async (#1724)
* Fix new import locations * Fix tests against default motor vals * Remove unnecessary motor patches * Pin to ophyd-async branch * Remove commented out import * Update ophyd-async version
1 parent 90a2fdd commit 400fe84

File tree

79 files changed

+196
-323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+196
-323
lines changed

docs/how-to/write-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Testing is essential to maintain the integrity and reliability of the codebase.
77
- **Unit Tests**: Place unit tests for individual components in the `tests` directory, but take care to mirror the file structure of the `src` folder with the corresponding code files. Use the `test_*.py` naming convention for test files.
88
- **System Tests**: Tests that interact with DLS infrastructure, network, and filesystem should be placed in the top-level `systems_test` folder. This separation ensures that these tests are easily identifiable and can be run independently from unit tests.
99

10-
Useful functions for testing that can be reused across multiple tests for common devices and for external plan repositories belong in the `dodal/testing` directory. For example, when mocking a `Motor` device, all of the signals will default to zero, which will cause errors when trying to move. The `patch_motor` and `patch_all_motors` functions, found in `dodal.testing`, will populate the mocked motor with useful default values for the signals so that it can still be used in tests.
10+
Useful functions for testing that can be reused across multiple tests for common devices and for external plan repositories belong in the `dodal/testing` directory.
1111

1212

1313
## Writing a test for a device

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description = "Ophyd devices and other utils that could be used across DLS beaml
1414
dependencies = [
1515
"click",
1616
"ophyd",
17-
"ophyd-async[ca,pva]>=0.13.7",
17+
"ophyd-async[ca,pva]>=v0.14.0",
1818
"bluesky>=1.14.5",
1919
"pyepics",
2020
"pillow",
@@ -48,7 +48,7 @@ dev = [
4848
# Commented out due to dependency version conflict with pydantic 1.x
4949
# "copier",
5050
"myst-parser",
51-
"ophyd_async[sim]>=v0.13.6",
51+
"ophyd_async[sim]>=v0.14.0",
5252
"pipdeptree",
5353
"pre-commit",
5454
"psutil",

src/dodal/devices/detector/det_resolution.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ def _get_detector_radius_mm(detector_params: DetectorParams):
1010
return 0.5 * _get_detector_max_size_mm(detector_params)
1111

1212

13-
def _get_detector_max_size_mm(detector_params):
13+
def _get_detector_max_size_mm(detector_params: DetectorParams):
1414
return max(
1515
detector_params.detector_size_constants.det_dimension.width,
1616
detector_params.detector_size_constants.det_dimension.height,
1717
)
1818

1919

20-
def _get_beam_xy_accounting_for_roi(detector_params, det_distance_mm):
20+
def _get_beam_xy_accounting_for_roi(
21+
detector_params: DetectorParams, det_distance_mm: float
22+
):
2123
beam_x = detector_params.beam_xy_converter.get_beam_xy_from_det_dist(
2224
det_distance_mm, Axis.X_AXIS
2325
)

src/dodal/testing/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/dodal/testing/setup.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

system_tests/test_oav_to_redis_system.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import pytest
88
from aiohttp.client_exceptions import ClientConnectorError
9-
from ophyd_async.core import init_devices
10-
from ophyd_async.testing import set_mock_value
9+
from ophyd_async.core import init_devices, set_mock_value
1110
from tests.devices.oav.conftest import (
1211
oav_beam_centre_pv_fs, # noqa: F401
1312
oav_beam_centre_pv_roi, # noqa: F401

tests/common/beamlines/test_commissioning_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from bluesky import RunEngine
33
from bluesky.utils import MsgGenerator
4-
from ophyd_async.testing import set_mock_value
4+
from ophyd_async.core import set_mock_value
55

66
from dodal.common.beamlines.commissioning_mode import read_commissioning_mode
77
from dodal.devices.baton import Baton

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from unittest.mock import patch
77

88
import pytest
9-
from ophyd_async.core import init_devices
10-
from ophyd_async.testing import set_mock_value
9+
from ophyd_async.core import init_devices, set_mock_value
1110

1211
from conftest import mock_attributes_table
1312
from dodal.common.beamlines import beamline_parameters, beamline_utils

tests/devices/aithre_lasershaping/test_goniometer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
from dodal.beamlines import aithre
77
from dodal.devices.aithre_lasershaping.goniometer import Goniometer
8-
from dodal.testing import patch_all_motors
98

109

1110
@pytest.fixture
1211
def goniometer() -> Goniometer:
1312
with init_devices(mock=True):
1413
gonio = aithre.goniometer(connect_immediately=True, mock=True)
15-
patch_all_motors(gonio)
1614
return gonio
1715

1816

tests/devices/b07_1/test_ccmc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ async def test_read_config_includes(mock_ccmc: ChannelCutMonochromator):
3535
{
3636
f"{mock_ccmc.name}-_xyz-x-motor_egu": partial_reading(""),
3737
f"{mock_ccmc.name}-_xyz-x-offset": partial_reading(0.0),
38-
f"{mock_ccmc.name}-_xyz-x-velocity": partial_reading(0.0),
38+
f"{mock_ccmc.name}-_xyz-x-velocity": partial_reading(1000.0),
3939
f"{mock_ccmc.name}-_xyz-y-motor_egu": partial_reading(""),
4040
f"{mock_ccmc.name}-_xyz-y-offset": partial_reading(0.0),
41-
f"{mock_ccmc.name}-_xyz-y-velocity": partial_reading(0.0),
41+
f"{mock_ccmc.name}-_xyz-y-velocity": partial_reading(1000.0),
4242
f"{mock_ccmc.name}-_xyz-z-motor_egu": partial_reading(""),
4343
f"{mock_ccmc.name}-_xyz-z-offset": partial_reading(0.0),
44-
f"{mock_ccmc.name}-_xyz-z-velocity": partial_reading(0.0),
44+
f"{mock_ccmc.name}-_xyz-z-velocity": partial_reading(1000.0),
4545
},
4646
)
4747

0 commit comments

Comments
 (0)