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

Commit

Permalink
(#794) Fix unit tests around new smargon
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Nov 1, 2023
1 parent 32f2859 commit c963c82
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/hyperion/device_setup_plans/unit_tests/test_setup_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from dodal.devices.smargon import Smargon
from ophyd.signal import Signal
from ophyd.status import Status
from ophyd_async.core import (
set_sim_value,
)

from hyperion.device_setup_plans.setup_oav import (
get_move_required_so_that_beam_is_at_pixel,
Expand Down Expand Up @@ -116,7 +119,7 @@ def test_values_for_move_so_that_beam_is_at_pixel(
mock_parameters.beam_centre_i = beam_centre[0]
mock_parameters.beam_centre_j = beam_centre[1]

smargon.omega.user_readback.sim_put(angle)
set_sim_value(smargon.omega.readback, angle)

RE = RunEngine(call_returns_result=True)
pos = RE(
Expand Down
5 changes: 3 additions & 2 deletions src/hyperion/experiment_plans/rotation_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from dodal.devices.undulator import Undulator
from dodal.devices.zebra import RotationDirection, Zebra
from ophyd.epics_motor import EpicsMotor
from ophyd_async.epics.motion.motor import Motor

from hyperion.device_setup_plans.manipulate_sample import (
cleanup_sample_environment,
Expand Down Expand Up @@ -75,7 +76,7 @@ def create_devices(context: BlueskyContext) -> RotationScanComposite:


def move_to_start_w_buffer(
axis: EpicsMotor,
axis: EpicsMotor | Motor,
start_angle: float,
offset: float,
wait_for_velocity_set: bool = True,
Expand All @@ -99,7 +100,7 @@ def move_to_start_w_buffer(


def move_to_end_w_buffer(
axis: EpicsMotor,
axis: EpicsMotor | Motor,
scan_width: float,
offset: float,
shutter_opening_degrees: float,
Expand Down
9 changes: 2 additions & 7 deletions src/hyperion/experiment_plans/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,8 @@ def eiger():


@pytest.fixture
def smargon() -> Smargon:
smargon = i03.smargon(fake_with_ophyd_sim=True)

with patch_motor(smargon.omega), patch_motor(smargon.x), patch_motor(
smargon.y
), patch_motor(smargon.z):
yield smargon
def smargon(RE) -> Smargon:
return i03.smargon(fake_with_ophyd_sim=True)


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run(
move_xyz.assert_called_once()


@pytest.mark.asyncio
@patch("hyperion.experiment_plans.flyscan_xray_centre_plan.run_gridscan", autospec=True)
@patch("hyperion.experiment_plans.flyscan_xray_centre_plan.move_x_y_z", autospec=True)
def test_when_gridscan_finished_then_smargon_stub_offsets_are_set(
async def test_when_gridscan_finished_then_smargon_stub_offsets_are_set(
move_xyz: MagicMock,
run_gridscan: MagicMock,
fake_fgs_composite: FlyScanXRayCentreComposite,
Expand All @@ -309,12 +310,14 @@ def test_when_gridscan_finished_then_smargon_stub_offsets_are_set(
mock_subscriptions,
)
)
assert fake_fgs_composite.smargon.stub_offsets.center_at_current_position.get() == 1
stub_offsets = fake_fgs_composite.smargon.stub_offsets
assert await stub_offsets.center_at_current_position.proc.get_value() == 1


@pytest.mark.asyncio
@patch("hyperion.experiment_plans.flyscan_xray_centre_plan.run_gridscan", autospec=True)
@patch("hyperion.experiment_plans.flyscan_xray_centre_plan.move_x_y_z", autospec=True)
def test_given_gridscan_fails_to_centre_then_stub_offsets_not_set(
async def test_given_gridscan_fails_to_centre_then_stub_offsets_not_set(
move_xyz: MagicMock,
run_gridscan: MagicMock,
fake_fgs_composite: FlyScanXRayCentreComposite,
Expand All @@ -333,7 +336,8 @@ def test_given_gridscan_fails_to_centre_then_stub_offsets_not_set(
mock_subscriptions,
)
)
assert fake_fgs_composite.smargon.stub_offsets.center_at_current_position.get() == 0
stub_offsets = fake_fgs_composite.smargon.stub_offsets
assert await stub_offsets.center_at_current_position.proc.get_value() == 0


@patch("hyperion.experiment_plans.flyscan_xray_centre_plan.bps.sleep", autospec=True)
Expand Down
13 changes: 8 additions & 5 deletions src/hyperion/experiment_plans/tests/test_pin_tip_centring.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,28 @@ def test_pin_tip_starting_near_positive_edge_doesnt_exceed_limit(
assert smargon.x.user_readback.get() == 2


def test_given_no_tip_found_ever_when_get_tip_into_view_then_smargon_moved_positive_and_exception_thrown(
@pytest.mark.asyncio
async def test_given_no_tip_found_ever_when_get_tip_into_view_then_smargon_moved_positive_and_exception_thrown(
smargon: Smargon, oav: OAV, RE: RunEngine
):
smargon.x.user_setpoint.sim_set_limits([-2, 2])
set_sim_value(smargon.x_low_lim, -2)
set_sim_value(smargon.x_high_lim, 2)

oav.mxsc.pin_tip.triggered_tip.put(oav.mxsc.pin_tip.INVALID_POSITION)
oav.mxsc.pin_tip.validity_timeout.put(0.01)

smargon.x.user_readback.sim_put(0)
set_sim_value(smargon.x.readback, 0)

with pytest.raises(WarningException):
RE(move_pin_into_view(oav, smargon))

assert smargon.x.user_readback.get() == 1
assert await smargon.x.setpoint.get_value() == 1


def test_given_moving_out_of_range_when_move_with_warn_called_then_warning_exception(
RE: RunEngine, smargon: Smargon
):
smargon.x.high_limit_travel.sim_put(10)
set_sim_value(smargon.x_high_lim, 10)

with pytest.raises(WarningException):
RE(move_smargon_warn_on_out_of_range(smargon, (100, 0, 0)))
Expand Down

0 comments on commit c963c82

Please sign in to comment.