Skip to content

Commit

Permalink
Merge branch 'main' into 871_remove_i04_1
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram authored Oct 28, 2024
2 parents 27359b6 + ff12610 commit b9f0ec8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/dodal/beamlines/i22.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ def dcm(
return device_instantiation(
DoubleCrystalMonochromator,
"dcm",
"",
f"{BeamlinePrefix(BL).beamline_prefix}-MO-DCM-01:",
wait_for_connection,
fake_with_ophyd_sim,
bl_prefix=False,
motion_prefix=f"{BeamlinePrefix(BL).beamline_prefix}-MO-DCM-01:",
temperature_prefix=f"{BeamlinePrefix(BL).beamline_prefix}-DI-DCM-01:",
crystal_1_metadata=CrystalMetadata(
usage="Bragg",
Expand Down
3 changes: 1 addition & 2 deletions src/dodal/beamlines/p38.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ def dcm(
return device_instantiation(
DoubleCrystalMonochromator,
"dcm",
"",
f"{BeamlinePrefix(BL).beamline_prefix}-MO-DCM-01:",
wait_for_connection,
fake_with_ophyd_sim,
bl_prefix=False,
motion_prefix=f"{BeamlinePrefix(BL).beamline_prefix}-MO-DCM-01:",
temperature_prefix=f"{BeamlinePrefix(BL).beamline_prefix}-DI-DCM-01:",
crystal_1_metadata=CrystalMetadata(
usage="Bragg",
Expand Down
15 changes: 7 additions & 8 deletions src/dodal/devices/i22/dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class DoubleCrystalMonochromator(StandardReadable):

def __init__(
self,
motion_prefix: str,
temperature_prefix: str,
crystal_1_metadata: CrystalMetadata | None = None,
crystal_2_metadata: CrystalMetadata | None = None,
Expand All @@ -48,13 +47,13 @@ def __init__(
) -> None:
with self.add_children_as_readables():
# Positionable Parameters
self.bragg = Motor(motion_prefix + "BRAGG")
self.offset = Motor(motion_prefix + "OFFSET")
self.perp = Motor(motion_prefix + "PERP")
self.energy = Motor(motion_prefix + "ENERGY")
self.crystal_1_roll = Motor(motion_prefix + "XTAL1:ROLL")
self.crystal_2_roll = Motor(motion_prefix + "XTAL2:ROLL")
self.crystal_2_pitch = Motor(motion_prefix + "XTAL2:PITCH")
self.bragg = Motor(prefix + "BRAGG")
self.offset = Motor(prefix + "OFFSET")
self.perp = Motor(prefix + "PERP")
self.energy = Motor(prefix + "ENERGY")
self.crystal_1_roll = Motor(prefix + "XTAL1:ROLL")
self.crystal_2_roll = Motor(prefix + "XTAL2:ROLL")
self.crystal_2_pitch = Motor(prefix + "XTAL2:PITCH")

# Temperatures
self.backplate_temp = epics_signal_r(float, temperature_prefix + "PT100-7")
Expand Down
3 changes: 2 additions & 1 deletion src/dodal/devices/undulator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from enum import Enum

import numpy as np
Expand Down Expand Up @@ -54,7 +55,7 @@ class Undulator(StandardReadable, Movable):
def __init__(
self,
prefix: str,
id_gap_lookup_table_path: str,
id_gap_lookup_table_path: str = os.devnull,
name: str = "",
poles: int | None = None,
length: float | None = None,
Expand Down
3 changes: 2 additions & 1 deletion tests/beamlines/unit_tests/test_i24.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

@pytest.mark.parametrize("module_and_devices_for_beamline", ["i24"], indirect=True)
def test_device_creation(RE, module_and_devices_for_beamline):
_, devices = module_and_devices_for_beamline
_, devices, exceptions = module_and_devices_for_beamline
assert not exceptions
vgonio: VGonio = devices["vgonio"] # type: ignore
assert vgonio.prefix == "BL24I-MO-VGON-01:"
assert vgonio.kappa.prefix == "BL24I-MO-VGON-01:KAPPA"
5 changes: 3 additions & 2 deletions tests/common/beamlines/test_device_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def test_device_creation(RE, module_and_devices_for_beamline):
Ensures that for every beamline all device factories are using valid args
and creating types that conform to Bluesky protocols.
"""
module, devices = module_and_devices_for_beamline
module, devices, exceptions = module_and_devices_for_beamline
assert not exceptions
for device_name, device in devices.items():
assert device_name in beamline_utils.ACTIVE_DEVICES, (
f"No device named {device_name} was created for {module}, "
Expand All @@ -40,7 +41,7 @@ def test_devices_are_identical(RE, module_and_devices_for_beamline):
"""
Ensures that for every beamline all device functions prevent duplicate instantiation.
"""
bl_mod, devices_a = module_and_devices_for_beamline
bl_mod, devices_a, _ = module_and_devices_for_beamline
devices_b, _ = make_all_devices(
bl_mod,
include_skipped=True,
Expand Down
32 changes: 29 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
PathProvider,
)

from dodal.common.beamlines import beamline_utils
from dodal.common.beamlines import beamline_parameters, beamline_utils
from dodal.common.visit import (
DirectoryServiceClient,
LocalDirectoryServiceClient,
Expand All @@ -31,14 +31,37 @@
("DAQ_CONFIGURATION_PATH", MOCK_DAQ_CONFIG_PATH),
("ZOOM_PARAMS_FILE", "tests/devices/unit_tests/test_jCameraManZoomLevels.xml"),
("DISPLAY_CONFIG", "tests/devices/unit_tests/test_display.configuration"),
("LOOK_UPTABLE_DIR", "tests/devices/i10/lookupTables/"),
]
mock_attributes_table = {
"i03": mock_paths,
"i10": mock_paths,
"s03": mock_paths,
"i04": mock_paths,
"s04": mock_paths,
"i24": mock_paths,
}

BANNED_PATHS = [Path("/dls"), Path("/dls_sw")]


@pytest.fixture(autouse=True)
def patch_open_to_prevent_dls_reads_in_tests():
unpatched_open = open

def patched_open(*args, **kwargs):
requested_path = Path(args[0])
if requested_path.is_absolute():
for p in BANNED_PATHS:
assert not requested_path.is_relative_to(
p
), f"Attempt to open {requested_path} from inside a unit test"
return unpatched_open(*args, **kwargs)

with patch("builtins.open", side_effect=patched_open):
yield []


# Prevent pytest from catching exceptions when debugging in vscode so that break on
# exception works correctly (see: https://github.com/pytest-dev/pytest/issues/7409)
if os.getenv("PYTEST_RAISE", "0") == "1":
Expand All @@ -55,6 +78,9 @@ def pytest_internalerror(excinfo):
def mock_beamline_module_filepaths(bl_name, bl_module):
if mock_attributes := mock_attributes_table.get(bl_name):
[bl_module.__setattr__(attr[0], attr[1]) for attr in mock_attributes]
beamline_parameters.BEAMLINE_PARAMETER_PATHS[bl_name] = (
"tests/test_data/i04_beamlineParameters"
)


@pytest.fixture(scope="function")
Expand All @@ -64,12 +90,12 @@ def module_and_devices_for_beamline(request):
bl_mod = importlib.import_module("dodal.beamlines." + beamline)
importlib.reload(bl_mod)
mock_beamline_module_filepaths(beamline, bl_mod)
devices, _ = make_all_devices(
devices, exceptions = make_all_devices(
bl_mod,
include_skipped=True,
fake_with_ophyd_sim=True,
)
yield (bl_mod, devices)
yield (bl_mod, devices, exceptions)
beamline_utils.clear_devices()
del bl_mod

Expand Down
4 changes: 2 additions & 2 deletions tests/devices/i22/test_dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
async def dcm() -> DoubleCrystalMonochromator:
async with DeviceCollector(mock=True):
dcm = DoubleCrystalMonochromator(
motion_prefix="FOO-MO",
prefix="FOO-MO",
temperature_prefix="FOO-DI",
crystal_1_metadata=CrystalMetadata(
usage="Bragg",
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_count_dcm(
async def test_crystal_metadata_not_propagated_when_not_supplied():
async with DeviceCollector(mock=True):
dcm = DoubleCrystalMonochromator(
motion_prefix="FOO-MO",
prefix="FOO-MO",
temperature_prefix="FOO-DI",
crystal_1_metadata=None,
crystal_2_metadata=None,
Expand Down

0 comments on commit b9f0ec8

Please sign in to comment.