Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
environ["HYPERION_TEST_MODE"] = "true"


pytest_plugins = ["dodal.testing.fixtures.run_engine"]
pytest_plugins = [
"dodal.testing.fixtures.run_engine",
"dodal.testing.fixtures.config_server",
]


def pytest_addoption(parser):
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ dependencies = [
# These dependencies may be issued as pre-release versions and should have a pin constraint
# as by default pip-install will not upgrade to a pre-release.
#
"daq-config-server>=v1.0.0-rc.2",
"daq-config-server>=v1.1.2",
"blueapi >= 1.8.0",
"ophyd >= 1.10.5",
"ophyd-async >= 0.14.0",
"bluesky >= 1.14.6",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@28c3f20f6108d2769e7995f1008e7d76446fb38b",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@mx_bluesky_1504_migrate_beamline_parameters_to_config_server",
]


Expand Down
5 changes: 3 additions & 2 deletions src/mx_bluesky/common/experiment_plans/beamstop_check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any

import pydantic
from bluesky import plan_stubs as bps
from bluesky.utils import MsgGenerator
from dodal.common.beamlines.beamline_parameters import GDABeamlineParameters
from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue
from dodal.devices.attenuator.attenuator import BinaryFilterAttenuator
from dodal.devices.backlight import Backlight
Expand Down Expand Up @@ -50,7 +51,7 @@ class BeamObstructedError(BeamlineCheckFailureError): ...

def move_beamstop_in_and_verify_using_diode(
devices: BeamstopCheckDevices,
beamline_parameters: GDABeamlineParameters,
beamline_parameters: dict[str, Any],
detector_min_z_mm: float,
detector_max_z_mm: float,
) -> MsgGenerator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def calculate_motion_profile(
)

# See https://github.com/DiamondLightSource/mx-bluesky/issues/1224
if get_beamline_name("i03") == "i24":
if get_beamline_name() == "i24":
acceleration_offset_deg = 10

return RotationMotionProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
run_number if run_number else parameters.detector_params.run_number
)
self.detector: Detector = create_detector_parameters(parameters.detector_params)
self.source: Source = Source(get_beamline_name("S03"))
self.source: Source = Source(get_beamline_name(""))
self.directory: Path = Path(parameters.storage_directory)
self.start_index: int = vds_start_index
self.full_num_of_images: int = full_num_of_images or parameters.num_images
Expand Down
4 changes: 1 addition & 3 deletions src/mx_bluesky/common/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ def detector_params(self):
"Detector distance must be filled before generating DetectorParams"
)
return DetectorParams(
detector_size_constants=DETECTOR_SIZE_PER_BEAMLINE[
get_beamline_name("dev")
],
detector_size_constants=DETECTOR_SIZE_PER_BEAMLINE[get_beamline_name()],
expected_energy_ev=self.demand_energy_ev,
exposure_time_s=self.exposure_time_s,
directory=self.storage_directory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import bluesky.plan_stubs as bps
import pydantic
from bluesky.utils import MsgGenerator
from dodal.beamlines.i03 import BL
from dodal.common.beamlines.beamline_parameters import (
get_beamline_parameters,
)
Expand Down Expand Up @@ -120,7 +121,7 @@ def move_to_udc_default_state(devices: UDCDefaultDevices):
get_hyperion_config_client().get_feature_flags()
)
if feature_flags.BEAMSTOP_DIODE_CHECK:
beamline_parameters = get_beamline_parameters()
beamline_parameters = get_beamline_parameters(BL)
config_client = get_hyperion_config_client()
features_settings: HyperionFeatureSettings = config_client.get_feature_flags()
detector_min_z = features_settings.DETECTOR_DISTANCE_LIMIT_MIN_MM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def activity_gated_event(self, doc: Event) -> Event | None:
):
current_container = int(doc["data"]["robot-current_puck"])
if self._new_container != current_container:
beamline = get_beamline_name("")
beamline = get_beamline_name()
get_alerting_service().raise_alert(
f"UDC moved on to puck {self._new_container} on {beamline}",
f"Hyperion finished container {current_container} and moved on to {self._new_container}",
Expand Down
34 changes: 11 additions & 23 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
from bluesky.utils import Msg, MsgGenerator
from dodal.beamlines import aithre, i03
from dodal.common.beamlines import beamline_utils
from dodal.common.beamlines.beamline_parameters import (
GDABeamlineParameters,
)
from dodal.common.beamlines.beamline_utils import clear_devices
from dodal.common.beamlines.commissioning_mode import set_commissioning_signal
from dodal.devices.aperturescatterguard import (
Expand Down Expand Up @@ -67,6 +64,7 @@
from dodal.devices.zocalo.zocalo_results import _NO_SAMPLE_ID
from dodal.log import LOGGER as DODAL_LOGGER
from dodal.log import set_up_all_logging_handlers
from dodal.testing.fixtures.config_server import fake_config_server_get_file_contents
from dodal.utils import AnyDeviceFactory, collect_factories
from event_model.documents import Event, EventDescriptor, RunStart, RunStop
from ophyd_async.core import (
Expand Down Expand Up @@ -363,8 +361,8 @@ def _pass_on_mock(value: float, wait: bool):

@pytest.fixture
def beamline_parameters():
return GDABeamlineParameters.from_file(
"tests/test_data/test_beamline_parameters.txt"
return fake_config_server_get_file_contents(
"tests/test_data/test_beamline_parameters.txt", dict
)


Expand Down Expand Up @@ -573,7 +571,7 @@ async def fake_attenuator_set(val):

@pytest.fixture
def beamstop_phase1(
beamline_parameters: GDABeamlineParameters,
beamline_parameters: dict[str, Any],
sim_run_engine: RunEngineSimulator,
) -> Generator[Beamstop, Any, Any]:
with patch(
Expand Down Expand Up @@ -1703,37 +1701,22 @@ def assert_images_pixelwise_equal(actual, expected):
)


def _fake_config_server_read(
filepath: str | Path,
desired_return_type: type[str] | type[dict] = str,
reset_cached_result=False,
):
filepath = Path(filepath)
# Minimal logic required for unit tests
with filepath.open("r") as f:
contents = f.read()
if desired_return_type is str:
return contents
elif desired_return_type is dict:
return json.loads(contents)


IMPLEMENTED_CONFIG_CLIENTS: list[Callable] = [
get_hyperion_config_client,
get_i04_config_client,
]


@pytest.fixture(autouse=True)
def mock_config_server():
def mock_mx_config_server():
# Don't actually talk to central service during unit tests, and reset caches between test

for client in IMPLEMENTED_CONFIG_CLIENTS:
client.cache_clear() # type: ignore - currently no option for "cachable" static type

with patch(
"mx_bluesky.common.external_interaction.config_server.MXConfigClient.get_file_contents",
side_effect=_fake_config_server_read,
side_effect=fake_config_server_get_file_contents,
):
yield

Expand All @@ -1745,3 +1728,8 @@ def mock_alert_service():
create=True,
) as service:
yield service


@pytest.fixture()
def patch_beamline_env_variable(monkeypatch):
monkeypatch.setenv("BEAMLINE", "dev")
Loading