Skip to content

Commit 1225d5b

Browse files
authored
Merge branch 'main' into configure_config_server
2 parents f276cc6 + 2a43962 commit 1225d5b

7 files changed

Lines changed: 4 additions & 91 deletions

File tree

src/mx_bluesky/hyperion/utils/context.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from blueapi.core import BlueskyContext
2-
from dodal.common.beamlines.beamline_utils import clear_devices, get_config_client
3-
from dodal.utils import collect_factories, get_beamline_based_on_environment_variable
2+
from dodal.common.beamlines.beamline_utils import get_config_client
3+
from dodal.utils import get_beamline_based_on_environment_variable
44

55

66
def setup_context(dev_mode: bool = False) -> BlueskyContext:
@@ -11,12 +11,6 @@ def setup_context(dev_mode: bool = False) -> BlueskyContext:
1111

1212
def clear_all_device_caches(context: BlueskyContext):
1313
context.unregister_all_devices()
14-
clear_devices()
15-
16-
for f in collect_factories(get_beamline_based_on_environment_variable()).values():
17-
if hasattr(f, "cache_clear"):
18-
f.cache_clear() # type: ignore
19-
2014
get_config_client().reset_cache()
2115

2216

tests/conftest.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import json
44
import logging
55
import os
6-
import sys
76
from collections.abc import Callable, Generator, Sequence
87
from functools import partial
98
from pathlib import Path
10-
from types import ModuleType
119
from typing import Any, TypedDict, TypeVar
1210
from unittest.mock import MagicMock, patch
1311

@@ -20,10 +18,8 @@
2018
from bluesky.utils import Msg, MsgGenerator
2119
from daq_config_server import ConfigClient
2220
from dodal.beamlines import aithre, i03
23-
from dodal.common.beamlines import beamline_utils
2421
from dodal.common.beamlines.beamline_utils import (
2522
clear_config_client,
26-
clear_devices,
2723
set_config_client,
2824
)
2925
from dodal.common.beamlines.commissioning_mode import set_commissioning_signal
@@ -70,7 +66,6 @@
7066
from dodal.devices.zocalo.zocalo_results import _NO_SAMPLE_ID
7167
from dodal.log import LOGGER as DODAL_LOGGER
7268
from dodal.log import set_up_all_logging_handlers
73-
from dodal.utils import AnyDeviceFactory, collect_factories
7469
from event_model.documents import Event, EventDescriptor, RunStart, RunStop
7570
from ophyd_async.core import (
7671
AsyncStatus,
@@ -258,29 +253,6 @@ def ispyb_config_path():
258253
yield ispyb_config_path
259254

260255

261-
@pytest.fixture(scope="session")
262-
def active_device_factories() -> set[AnyDeviceFactory]:
263-
"""Obtain the set of device factories that should have their caches cleared
264-
after every test invocation.
265-
Override this in sub-packages for the specific beamlines under test."""
266-
return device_factories_for_beamline(i03)
267-
268-
269-
def device_factories_for_beamline(beamline_module: ModuleType) -> set[AnyDeviceFactory]:
270-
return {
271-
f
272-
for f in collect_factories(beamline_module, include_skipped=True).values()
273-
if hasattr(f, "cache_clear")
274-
}
275-
276-
277-
@pytest.fixture(scope="function", autouse=True)
278-
def clear_device_factory_caches_after_every_test(active_device_factories):
279-
yield None
280-
for f in active_device_factories:
281-
f.cache_clear() # type: ignore
282-
283-
284256
def replace_all_tmp_paths(d: dict[str, Any], tmp_path: Path):
285257
d = d.copy()
286258
for k, v in d.items():
@@ -361,8 +333,6 @@ def pytest_runtest_setup(item):
361333

362334

363335
def pytest_runtest_teardown(item):
364-
if "dodal.common.beamlines.beamline_utils" in sys.modules:
365-
sys.modules["dodal.common.beamlines.beamline_utils"].clear_devices()
366336
markers = [m.name for m in item.own_markers]
367337
if "skip_log_setup" in markers:
368338
_reset_loggers([*ALL_LOGGERS, DODAL_LOGGER])
@@ -411,7 +381,6 @@ def smargon() -> Generator[Smargon, None, None]:
411381
# Initial positions, needed for stub_offsets
412382
set_mock_value(smargon.stub_offsets.center_at_current_position.disp, 0)
413383
yield smargon
414-
clear_devices()
415384

416385

417386
@pytest.fixture
@@ -600,7 +569,6 @@ def locate_beamstop(_):
600569
)
601570

602571
yield beamstop
603-
beamline_utils.clear_devices()
604572

605573

606574
@pytest.fixture
@@ -610,7 +578,6 @@ def xbpm_feedback(
610578
xbpm = i03.xbpm_feedback.build(connect_immediately=True, mock=True)
611579
xbpm.trigger = MagicMock(side_effect=lambda: completed_status())
612580
yield xbpm
613-
beamline_utils.clear_devices()
614581

615582

616583
def set_up_dcm(dcm: DCM, sim_run_engine: RunEngineSimulator):
@@ -661,7 +628,6 @@ def mirror_voltages():
661628
for vc in voltages.horizontal_voltages.values():
662629
vc.set = MagicMock(side_effect=lambda _: completed_status())
663630
yield voltages
664-
beamline_utils.clear_devices()
665631

666632

667633
@pytest.fixture
@@ -675,7 +641,6 @@ def undulator_dcm(sim_run_engine, dcm, undulator) -> Generator[UndulatorDCM]:
675641
)
676642
set_up_dcm(undulator_dcm.dcm_ref(), sim_run_engine)
677643
yield undulator_dcm
678-
# beamline_utils.clear_devices()
679644

680645

681646
@pytest.fixture

tests/unit_tests/beamlines/i24/serial/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from dodal.devices.attenuator.attenuator import ReadOnlyAttenuator
99
from dodal.devices.beamlines.i24.beam_center import DetectorBeamCenter
1010
from dodal.devices.zebra.zebra import Zebra
11-
from dodal.utils import AnyDeviceFactory
1211
from ophyd_async.core import set_mock_value
1312

1413
from mx_bluesky.beamlines.i24.serial.fixed_target.ft_utils import ChipType
@@ -19,8 +18,6 @@
1918
)
2019
from mx_bluesky.beamlines.i24.serial.parameters.constants import DetectorName
2120

22-
from .....conftest import device_factories_for_beamline
23-
2421
TEST_PATH = Path("tests/test_data/test_daq_configuration")
2522

2623
TEST_LUT = {
@@ -33,11 +30,6 @@ def fake_generator(value):
3330
return value
3431

3532

36-
@pytest.fixture(scope="session")
37-
def active_device_factories(active_device_factories) -> set[AnyDeviceFactory]:
38-
return active_device_factories | device_factories_for_beamline(i24)
39-
40-
4133
@pytest.fixture
4234
def dummy_params_without_pp():
4335
oxford_defaults = get_chip_format(ChipType.Oxford)

tests/unit_tests/common/experiment_plans/test_grid_detection_plan.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ def do_grid_and_edge_detect(composite, parameters, tmp_dir):
108108
)
109109

110110

111-
@patch(
112-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
113-
lambda a, b: True,
114-
)
115111
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
116112
def test_grid_detection_plan_runs_and_triggers_snapshots(
117113
run_engine: RunEngine,
@@ -132,10 +128,6 @@ def test_grid_detection_plan_runs_and_triggers_snapshots(
132128
assert mock_save.call_count == 2
133129

134130

135-
@patch(
136-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
137-
lambda a, b: True,
138-
)
139131
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
140132
async def test_grid_detection_plan_gives_warning_error_if_tip_not_found(
141133
run_engine: RunEngine,
@@ -165,10 +157,6 @@ async def test_grid_detection_plan_gives_warning_error_if_tip_not_found(
165157
assert "No pin found" in excinfo.value.args[0]
166158

167159

168-
@patch(
169-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
170-
lambda a, b: True,
171-
)
172160
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
173161
async def test_given_when_grid_detect_then_start_position_as_expected(
174162
fake_devices: tuple[OavGridDetectionComposite, MagicMock],
@@ -209,10 +197,6 @@ def decorated():
209197
assert gridscan_params["z_start_um"] == pytest.approx(-534, abs=1)
210198

211199

212-
@patch(
213-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
214-
lambda a, b: True,
215-
)
216200
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
217201
async def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_values(
218202
fake_devices: tuple[OavGridDetectionComposite, MagicMock],
@@ -280,10 +264,6 @@ async def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_val
280264
)
281265

282266

283-
@patch(
284-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
285-
lambda a, b: True,
286-
)
287267
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
288268
def test_when_grid_detection_plan_run_then_grid_detection_callback_gets_correct_values(
289269
fake_devices: tuple[OavGridDetectionComposite, MagicMock],
@@ -322,10 +302,6 @@ def test_when_grid_detection_plan_run_then_grid_detection_callback_gets_correct_
322302
assert cb.x_step_size_um == cb.y_step_size_um == cb.z_step_size_um == box_size_um
323303

324304

325-
@patch(
326-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
327-
lambda a, b: True,
328-
)
329305
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
330306
def test_when_grid_detection_plan_run_with_different_omega_order_then_grid_detection_callback_gets_correct_values(
331307
fake_devices: tuple[OavGridDetectionComposite, MagicMock],
@@ -405,10 +381,6 @@ def test_given_unexpected_omega_then_grid_detect_raises(tmp_path: Path):
405381
"odd",
406382
[(True), (False)],
407383
)
408-
@patch(
409-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
410-
lambda a, b: True,
411-
)
412384
@patch("bluesky.plan_stubs.sleep", new=MagicMock())
413385
@patch("mx_bluesky.common.experiment_plans.oav_grid_detection_plan.LOGGER")
414386
async def test_when_detected_grid_has_odd_y_steps_then_add_a_y_step_and_shift_grid(

tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ def test_calculate_motion_profile_computes_values_for_wrapped_axis(
261261
assert motion_values.distance_to_move_deg == 180.3075 * -sign
262262

263263

264-
@patch(
265-
"dodal.common.beamlines.beamline_utils.active_device_is_same_type",
266-
lambda a, b: True,
267-
)
268264
@patch(
269265
"mx_bluesky.hyperion.experiment_plans.rotation_scan_plan.rotation_scan_plan",
270266
autospec=True,

tests/unit_tests/hyperion/test_baton_handler.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,7 @@ def run_plan_in_sim(plan):
181181

182182
faked_run_engine = MagicMock(spec=RunEngine, side_effect=run_plan_in_sim) # type: ignore
183183

184-
# wait_for_connection in ensure_connected creates a bunch of awaitables
185-
# that will never be awaited by the simulator, let's not create them
186-
def dont_connect(*args, **kwargs):
187-
yield from bps.null()
188-
189184
with (
190-
patch("blueapi.utils.connect_devices.ensure_connected", dont_connect),
191185
patch.dict(os.environ, {"BEAMLINE": "i03"}),
192186
):
193187
context = BlueskyContext(run_engine=faked_run_engine)

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)