Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1356 from DiamondLightSource/1354_update_ap_sg
Browse files Browse the repository at this point in the history
(#1354) update Hyperion to use the new ApertureScatterguard
  • Loading branch information
d-perl authored May 7, 2024
2 parents cf2873b + 48e31c0 commit b70731e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install_requires =
xarray
doct
databroker
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@6864607ad8cf5415fa63cafa0a8a7ff955471eeb
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@daaf2de4e98dc0e12e88a70b85a1268c1861b48f
pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774
scipy
pyzmq<25 # See https://github.com/DiamondLightSource/hyperion/issues/1103
Expand Down
50 changes: 31 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import asyncio
import json
import logging
import sys
import threading
from functools import partial
from typing import Any, Callable, Generator, Optional, Sequence
from unittest.mock import MagicMock, patch
from unittest.mock import AsyncMock, MagicMock, patch

import bluesky.plan_stubs as bps
import pytest
from bluesky.run_engine import RunEngine
from bluesky.utils import Msg
Expand Down Expand Up @@ -41,6 +43,7 @@
from ophyd.status import DeviceStatus, Status
from ophyd_async.core import set_sim_value
from ophyd_async.core.async_status import AsyncStatus
from ophyd_async.epics.motion.motor import Motor
from scanspec.core import Path as ScanPath
from scanspec.specs import Line

Expand Down Expand Up @@ -181,6 +184,26 @@ def patch_motor(motor: EpicsMotor):
return patch.object(motor, "set", MagicMock(side_effect=partial(mock_set, motor)))


async def mock_good_coroutine():
return asyncio.sleep(0)


def mock_async_motor_move(motor: Motor, val, *args, **kwargs):
set_sim_value(motor.user_setpoint, val)
set_sim_value(motor.user_readback, val)
return mock_good_coroutine() # type: ignore


def patch_async_motor(motor: Motor, initial_position=0):
set_sim_value(motor.user_setpoint, initial_position)
set_sim_value(motor.user_readback, initial_position)
set_sim_value(motor.deadband, 0.001)
set_sim_value(motor.motor_done_move, 1)
return patch.object(
motor, "_move", AsyncMock(side_effect=partial(mock_async_motor_move, motor))
)


@pytest.fixture
def beamline_parameters():
return GDABeamlineParameters.from_file(
Expand Down Expand Up @@ -433,7 +456,7 @@ def webcam(RE) -> Generator[Webcam, Any, Any]:


@pytest.fixture
def aperture_scatterguard(done_status):
def aperture_scatterguard(done_status, RE):
AperturePositions.LARGE = SingleAperturePosition(
location=ApertureFiveDimensionalLocation(0, 1, 2, 3, 4),
name="Large",
Expand Down Expand Up @@ -467,16 +490,14 @@ def aperture_scatterguard(done_status):
AperturePositions.ROBOT_LOAD,
),
)
ap_sg.aperture.z.user_setpoint.sim_put(2) # type: ignore
ap_sg.aperture.z.motor_done_move.sim_put(1) # type: ignore
with (
patch_motor(ap_sg.aperture.x),
patch_motor(ap_sg.aperture.y),
patch_motor(ap_sg.aperture.z),
patch_motor(ap_sg.scatterguard.x),
patch_motor(ap_sg.scatterguard.y),
patch_async_motor(ap_sg.aperture.x),
patch_async_motor(ap_sg.aperture.y),
patch_async_motor(ap_sg.aperture.z, 2),
patch_async_motor(ap_sg.scatterguard.x),
patch_async_motor(ap_sg.scatterguard.y),
):
ap_sg.set(ap_sg.aperture_positions.SMALL) # type: ignore
RE(bps.abs_set(ap_sg, ap_sg.aperture_positions.SMALL)) # type: ignore
yield ap_sg


Expand Down Expand Up @@ -622,15 +643,6 @@ def fake_fgs_composite(
fake_composite.eiger.ALL_FRAMES_TIMEOUT = 2 # type: ignore
fake_composite.eiger.stop_odin_when_all_frames_collected = MagicMock()
fake_composite.eiger.odin.check_odin_state = lambda: True
fake_composite.aperture_scatterguard.aperture.x.user_setpoint._use_limits = False
fake_composite.aperture_scatterguard.aperture.y.user_setpoint._use_limits = False
fake_composite.aperture_scatterguard.aperture.z.user_setpoint._use_limits = False
fake_composite.aperture_scatterguard.scatterguard.x.user_setpoint._use_limits = (
False
)
fake_composite.aperture_scatterguard.scatterguard.y.user_setpoint._use_limits = (
False
)

mock_gridscan_kickoff_complete(fake_composite.fast_grid_scan)
mock_gridscan_kickoff_complete(fake_composite.panda_fast_grid_scan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Tuple
from unittest.mock import DEFAULT, MagicMock, call, patch

import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
import numpy as np
import pytest
Expand Down Expand Up @@ -212,8 +213,11 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices(
flux_test_value = 10.0
fake_fgs_composite.flux.flux_reading.sim_put(flux_test_value) # type: ignore

fake_fgs_composite.aperture_scatterguard.set(
fake_fgs_composite.aperture_scatterguard.aperture_positions.LARGE # type: ignore
RE(
bps.abs_set(
fake_fgs_composite.aperture_scatterguard,
fake_fgs_composite.aperture_scatterguard.aperture_positions.LARGE, # type: ignore
)
)

test_ispyb_callback = PlanReactiveCallback(ISPYB_LOGGER)
Expand Down

0 comments on commit b70731e

Please sign in to comment.