Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ dependencies = [
# as by default pip-install will not upgrade to a pre-release.
#
"daq-config-server>=v1.0.0-rc.2",
"blueapi >= 1.6.3",
"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@main",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@i03-device-manager",
]


Expand Down
4 changes: 2 additions & 2 deletions src/mx_bluesky/hyperion/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def clear_all_device_caches(context: BlueskyContext):


def setup_devices(context: BlueskyContext, dev_mode: bool):
_, exceptions = context.with_dodal_module(
get_beamline_based_on_environment_variable(),
_, exceptions = context.with_device_manager(
get_beamline_based_on_environment_variable().devices,
mock=dev_mode,
)
if exceptions:
Expand Down
83 changes: 41 additions & 42 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def done_status():

@pytest.fixture
def eiger(done_status):
eiger = i03.eiger(connect_immediately=True, mock=True)
eiger = i03.eiger.build(mock=True)
eiger.stage = MagicMock(return_value=done_status)
eiger.do_arm.set = MagicMock(return_value=done_status)
eiger.unstage = MagicMock(return_value=done_status)
Expand All @@ -412,7 +412,7 @@ def eiger(done_status):

@pytest.fixture
def smargon() -> Generator[Smargon, None, None]:
smargon = i03.smargon(connect_immediately=True, mock=True)
smargon = i03.smargon.build(connect_immediately=True, mock=True)
# Initial positions, needed for stub_offsets
set_mock_value(smargon.stub_offsets.center_at_current_position.disp, 0)
yield smargon
Expand All @@ -427,7 +427,7 @@ def aithre_gonio():

@pytest.fixture
def zebra():
zebra = i03.zebra(connect_immediately=True, mock=True)
zebra = i03.zebra.build(connect_immediately=True, mock=True)

def mock_side(demand: ArmDemand):
set_mock_value(zebra.pc.arm.armed, demand.value)
Expand All @@ -439,7 +439,7 @@ def mock_side(demand: ArmDemand):

@pytest.fixture
def zebra_shutter():
shutter = i03.sample_shutter(connect_immediately=True, mock=True)
shutter = i03.sample_shutter.build(connect_immediately=True, mock=True)

def put_sample_shutter(value, **kwargs):
set_mock_value(shutter.position_readback, value)
Expand All @@ -450,14 +450,14 @@ def put_sample_shutter(value, **kwargs):

@pytest.fixture
def backlight():
backlight = i03.backlight(connect_immediately=True, mock=True)
backlight = i03.backlight.build(connect_immediately=True, mock=True)
backlight.TIME_TO_MOVE_S = 0.001
return backlight


@pytest.fixture
def baton():
baton = i03.baton(connect_immediately=True, mock=True)
baton = i03.baton.build(connect_immediately=True, mock=True)
set_mock_value(baton.requested_user, HYPERION_USER)
set_mock_value(baton.current_user, HYPERION_USER)
return baton
Expand All @@ -473,31 +473,31 @@ def baton_in_commissioning_mode(baton: Baton):

@pytest.fixture
def fast_grid_scan():
scan = i03.zebra_fast_grid_scan(connect_immediately=True, mock=True)
scan = i03.zebra_fast_grid_scan.build(mock=True, connect_immediately=True)
for signal in [scan.x_scan_valid, scan.y_scan_valid, scan.z_scan_valid]:
set_mock_value(signal, 1)
return scan


@pytest.fixture
def detector_motion():
return i03.detector_motion(connect_immediately=True, mock=True)
return i03.detector_motion.build(mock=True, connect_immediately=True)


@pytest.fixture
def undulator(baton):
undulator = i03.undulator(connect_immediately=True, mock=True)
def undulator():
undulator = i03.undulator.build(mock=True, connect_immediately=True)
return undulator


@pytest.fixture
def s4_slit_gaps():
return i03.s4_slit_gaps(connect_immediately=True, mock=True)
return i03.s4_slit_gaps.build(mock=True, connect_immediately=True)


@pytest.fixture
def synchrotron():
synchrotron = i03.synchrotron(connect_immediately=True, mock=True)
synchrotron = i03.synchrotron.build(mock=True, connect_immediately=True)
set_mock_value(synchrotron.synchrotron_mode, SynchrotronMode.USER)
set_mock_value(synchrotron.top_up_start_countdown, 10)
return synchrotron
Expand All @@ -508,7 +508,7 @@ def oav(test_config_files):
parameters = OAVConfigBeamCentre(
test_config_files["zoom_params_file"], test_config_files["display_config"]
)
oav = i03.oav(connect_immediately=True, mock=True, params=parameters)
oav = i03.oav.build(mock=True, connect_immediately=True, params=parameters)

zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x", "15.0x"]
oav.zoom_controller._get_allowed_zoom_levels = AsyncMock(
Expand All @@ -527,17 +527,17 @@ def oav(test_config_files):

@pytest.fixture
def flux():
return i03.flux(connect_immediately=True, mock=True)
return i03.flux.build(connect_immediately=True, mock=True)


@pytest.fixture
def pin_tip():
return i03.pin_tip_detection(connect_immediately=True, mock=True)
return i03.pin_tip_detection.build(connect_immediately=True, mock=True)


@pytest.fixture
def ophyd_pin_tip_detection():
return i03.pin_tip_detection(connect_immediately=True, mock=True)
return i03.pin_tip_detection.build(connect_immediately=True, mock=True)


@pytest.fixture()
Expand All @@ -549,8 +549,8 @@ def transfocator():


@pytest.fixture
def robot(done_status):
robot = i03.robot(connect_immediately=True, mock=True)
def robot():
robot = i03.robot.build(connect_immediately=True, mock=True)
set_mock_value(robot.barcode, "BARCODE")

@AsyncStatus.wrap
Expand Down Expand Up @@ -578,7 +578,7 @@ def scintillator(aperture_scatterguard):

@pytest.fixture
def attenuator():
attenuator = i03.attenuator(connect_immediately=True, mock=True)
attenuator = i03.attenuator.build(connect_immediately=True, mock=True)
set_mock_value(attenuator.actual_transmission, 0.49118047952)

@AsyncStatus.wrap
Expand All @@ -599,7 +599,7 @@ def beamstop_phase1(
"dodal.beamlines.i03.get_beamline_parameters",
return_value=beamline_parameters,
):
beamstop = i03.beamstop(connect_immediately=True, mock=True)
beamstop = i03.beamstop.build(connect_immediately=True, mock=True)

set_mock_value(beamstop.x_mm.user_readback, 1.52)
set_mock_value(beamstop.y_mm.user_readback, 44.78)
Expand All @@ -625,7 +625,7 @@ def xbpm_feedback(
done_status,
baton: Baton, # Ensure baton is cached with mock configuration
):
xbpm = i03.xbpm_feedback(connect_immediately=True, mock=True)
xbpm = i03.xbpm_feedback.build(connect_immediately=True, mock=True)
xbpm.trigger = MagicMock(return_value=done_status)
yield xbpm
beamline_utils.clear_devices()
Expand All @@ -641,14 +641,14 @@ def set_up_dcm(dcm: DCM, sim_run_engine: RunEngineSimulator):

@pytest.fixture
def dcm(sim_run_engine):
dcm = i03.dcm(connect_immediately=True, mock=True)
dcm = i03.dcm.build(connect_immediately=True, mock=True)
set_up_dcm(dcm, sim_run_engine)
yield dcm


@pytest.fixture
def vfm():
vfm = i03.vfm(connect_immediately=True, mock=True)
vfm = i03.vfm.build(connect_immediately=True, mock=True)
vfm.bragg_to_lat_lookup_table_path = (
"tests/test_data/test_beamline_vfm_lat_converter.txt"
)
Expand All @@ -659,7 +659,7 @@ def vfm():
def lower_gonio(
sim_run_engine: RunEngineSimulator,
):
lower_gonio = i03.lower_gonio(connect_immediately=True, mock=True)
lower_gonio = i03.lower_gonio.build(connect_immediately=True, mock=True)

# Replace when https://github.com/bluesky/bluesky/issues/1906 is fixed
def locate_gonio(_):
Expand All @@ -673,7 +673,7 @@ def locate_gonio(_):

@pytest.fixture
def mirror_voltages():
voltages = i03.mirror_voltages(connect_immediately=True, mock=True)
voltages = i03.mirror_voltages.build(connect_immediately=True, mock=True)
voltages.voltage_lookup_table_path = "tests/test_data/test_mirror_focus.json"
for vc in voltages.vertical_voltages.values():
vc.set = MagicMock(return_value=NullStatus())
Expand All @@ -684,33 +684,32 @@ def mirror_voltages():


@pytest.fixture
def undulator_dcm(sim_run_engine, undulator, dcm):
# This depends on the undulator and dcm as they must be connected as mocks first
undulator_dcm = i03.undulator_dcm(
def undulator_dcm(sim_run_engine):
undulator_dcm = i03.undulator_dcm.build(
connect_immediately=True,
mock=True,
daq_configuration_path="tests/test_data/test_daq_configuration",
)
set_up_dcm(undulator_dcm.dcm_ref(), sim_run_engine)
yield undulator_dcm
beamline_utils.clear_devices()
# beamline_utils.clear_devices()


@pytest.fixture
def webcam() -> Generator[Webcam, Any, Any]:
webcam = i03.webcam(connect_immediately=True, mock=True)
webcam = i03.webcam.build(connect_immediately=True, mock=True)
with patch.object(webcam, "_get_and_write_image"):
yield webcam


@pytest.fixture
def thawer() -> Generator[Thawer, Any, Any]:
yield i03.thawer(connect_immediately=True, mock=True)
yield i03.thawer.build(connect_immediately=True, mock=True)


@pytest.fixture
def sample_shutter() -> Generator[ZebraShutter, Any, Any]:
yield i03.sample_shutter(connect_immediately=True, mock=True)
yield i03.sample_shutter.build(connect_immediately=True, mock=True)


@pytest.fixture
Expand Down Expand Up @@ -773,7 +772,7 @@ async def aperture_scatterguard():
),
),
):
ap_sg = i03.aperture_scatterguard(connect_immediately=True, mock=True)
ap_sg = i03.aperture_scatterguard.build(connect_immediately=True, mock=True)

await ap_sg.aperture.z.set(2)
await ap_sg.selected_aperture.set(ApertureValue.SMALL)
Expand Down Expand Up @@ -872,7 +871,7 @@ def fake_create_rotation_devices(

@pytest.fixture
def zocalo(done_status):
zoc = i03.zocalo(connect_immediately=True, mock=True)
zoc = i03.zocalo.build(connect_immediately=True, mock=True)
zoc.stage = MagicMock(return_value=done_status)
zoc.unstage = MagicMock(return_value=done_status)
return zoc
Expand Down Expand Up @@ -912,7 +911,7 @@ async def create_mock_signals(devices_and_signals: dict[Device, dict[str, Any]])
await sig.connect(mock=True)
setattr(device, name, sig)

panda = i03.panda(connect_immediately=True, mock=True)
panda = i03.panda.build(connect_immediately=True, mock=True)
await set_mock_blocks(
panda,
{
Expand Down Expand Up @@ -952,7 +951,7 @@ def mock_gridscan_kickoff_complete(gridscan: FastGridScanCommon):

@pytest.fixture
def panda_fast_grid_scan():
scan = i03.panda_fast_grid_scan(connect_immediately=True, mock=True)
scan = i03.panda_fast_grid_scan.build(connect_immediately=True, mock=True)
for signal in [scan.x_scan_valid, scan.y_scan_valid, scan.z_scan_valid]:
set_mock_value(signal, 1)
return scan
Expand Down Expand Up @@ -982,20 +981,20 @@ async def hyperion_flyscan_xrc_composite(
backlight=backlight,
dcm=dcm,
# We don't use the eiger fixture here because .unstage() is used in some tests
eiger=i03.eiger(connect_immediately=True, mock=True),
eiger=i03.eiger.build(mock=True),
zebra_fast_grid_scan=fast_grid_scan,
flux=i03.flux(connect_immediately=True, mock=True),
flux=i03.flux.build(connect_immediately=True, mock=True),
s4_slit_gaps=s4_slit_gaps,
smargon=smargon,
undulator=i03.undulator(connect_immediately=True, mock=True),
undulator=i03.undulator.build(connect_immediately=True, mock=True),
synchrotron=synchrotron,
xbpm_feedback=xbpm_feedback,
zebra=i03.zebra(connect_immediately=True, mock=True),
zebra=i03.zebra.build(connect_immediately=True, mock=True),
zocalo=zocalo,
panda=panda,
panda_fast_grid_scan=panda_fast_grid_scan,
robot=i03.robot(connect_immediately=True, mock=True),
sample_shutter=i03.sample_shutter(connect_immediately=True, mock=True),
robot=i03.robot.build(connect_immediately=True, mock=True),
sample_shutter=i03.sample_shutter.build(connect_immediately=True, mock=True),
beamsize=beamsize,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/system_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def oav_for_system_test(test_config_files, next_oav_system_test_image):
parameters = OAVConfigBeamCentre(
test_config_files["zoom_params_file"], test_config_files["display_config"]
)
oav = i03.oav(connect_immediately=True, mock=True, params=parameters)
oav = i03.oav.build(connect_immediately=True, mock=True, params=parameters)
set_mock_value(oav.cam.array_size_x, 1024)
set_mock_value(oav.cam.array_size_y, 768)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async def zocalo_for_fake_zocalo(zocalo_env) -> ZocaloResults:

@pytest.fixture
def zocalo_for_system_test() -> Generator[ZocaloResults, None, None]:
zocalo = i03.zocalo(connect_immediately=True, mock=True)
zocalo = i03.zocalo.build(connect_immediately=True, mock=True)
zocalo.timeout_s = 10
old_zocalo_trigger = zocalo.trigger
zocalo.my_zocalo_result = deepcopy(TEST_RESULT_MEDIUM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ async def fake_composite(
aperture_scatterguard=aperture_scatterguard,
attenuator=attenuator,
dcm=dcm,
flux=i03.flux(connect_immediately=True, mock=True),
s4_slit_gaps=i03.s4_slit_gaps(connect_immediately=True, mock=True),
undulator=i03.undulator(connect_immediately=True, mock=True),
flux=i03.flux.build(connect_immediately=True, mock=True),
s4_slit_gaps=i03.s4_slit_gaps.build(connect_immediately=True, mock=True),
undulator=i03.undulator.build(connect_immediately=True, mock=True),
synchrotron=synchrotron,
robot=robot,
smargon=smargon,
eiger=eiger(connect_immediately=True, mock=True),
eiger=eiger.build(mock=True),
)
return fake_composite

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_waits_for_motion_program(
done_status: Status,
):
fake_fgs_composite.eiger.unstage = MagicMock(return_value=done_status)
fgs = i03.zebra_fast_grid_scan(connect_immediately=True, mock=True)
fgs = i03.zebra_fast_grid_scan.build(connect_immediately=True, mock=True)
fgs.KICKOFF_TIMEOUT = 0.1
fgs.complete = MagicMock(return_value=done_status)
set_mock_value(fgs.motion_program.running, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def fake_devices(
params = OAVConfigBeamCentre(
test_config_files["zoom_params_file"], test_config_files["display_config"]
)
oav = i03.oav(connect_immediately=True, mock=True, params=params)
oav = i03.oav.build(connect_immediately=True, mock=True, params=params)
zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x", "15.0x"]
oav.zoom_controller._get_allowed_zoom_levels = AsyncMock(
return_value=zoom_levels_list
Expand All @@ -68,7 +68,7 @@ def fake_devices(
set_mock_value(oav.grid_snapshot.x_size, 1024)
set_mock_value(oav.grid_snapshot.y_size, 768)

pin_tip_detection = i03.pin_tip_detection(connect_immediately=True, mock=True)
pin_tip_detection = i03.pin_tip_detection.build(connect_immediately=True, mock=True)
pin_tip_detection._get_tip_and_edge_data = AsyncMock(
side_effect=[X_Y_EDGE_DATA, X_Z_EDGE_DATA]
)
Expand Down
Loading