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

Commit

Permalink
Fix unit tests after aperture change (#1424)
Browse files Browse the repository at this point in the history
* Fix aperture test

* Pin blueapi to working commit

* Give mock motors a non=0 velocity

---------

Co-authored-by: Dominic Oram <[email protected]>
  • Loading branch information
olliesilvester and DominicOram authored Jun 3, 2024
1 parent 0dd461b commit 4bed47e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ install_requires =
ophyd == 1.9.0
ophyd-async >= 0.3a5
bluesky >= 1.13.0a3
blueapi >= 0.4.3-a1
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@4b53c861ac2babb4c96fcad55405083eb549e531
blueapi >= 0.4.3-rc1
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git


[options.entry_points]
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def patch_async_motor(
set_mock_value(motor.user_readback, initial_position)
set_mock_value(motor.deadband, 0.001)
set_mock_value(motor.motor_done_move, 1)
set_mock_value(motor.velocity, 1)
return callback_on_mock_put(motor.user_setpoint, pass_on_mock(motor, call_log))


Expand Down Expand Up @@ -486,7 +487,9 @@ def aperture_scatterguard(RE):
patch_async_motor(ap_sg.scatterguard.x),
patch_async_motor(ap_sg.scatterguard.y),
):
RE(bps.abs_set(ap_sg, ap_sg.aperture_positions.SMALL)) # type:
assert ap_sg.aperture_positions
RE(bps.abs_set(ap_sg, ap_sg.aperture_positions.SMALL))

set_mock_value(ap_sg.aperture.small, 1)
yield ap_sg

Expand Down
33 changes: 14 additions & 19 deletions tests/unit_tests/device_setup_plans/test_manipulate_sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import MagicMock, patch
from unittest.mock import patch

from bluesky.run_engine import RunEngine
from dodal.devices.aperturescatterguard import (
Expand All @@ -9,30 +9,25 @@
from hyperion.device_setup_plans.manipulate_sample import move_aperture_if_required


@patch("bluesky.plan_stubs.abs_set")
async def test_move_aperture_goes_to_correct_position(
mock_set: MagicMock, aperture_scatterguard: ApertureScatterguard, RE: RunEngine
aperture_scatterguard: ApertureScatterguard, RE: RunEngine
):
assert aperture_scatterguard.aperture_positions

RE(
move_aperture_if_required(
aperture_scatterguard, AperturePositionGDANames.LARGE_APERTURE
with patch.object(aperture_scatterguard, "set") as mock_set:
RE(
move_aperture_if_required(
aperture_scatterguard, AperturePositionGDANames.LARGE_APERTURE
)
)
mock_set.assert_called_once_with(
aperture_scatterguard.aperture_positions.LARGE,
)
)
mock_set.assert_called_once_with(
aperture_scatterguard,
aperture_scatterguard.aperture_positions.LARGE,
group="move_aperture",
)


@patch("bluesky.plan_stubs.abs_set")
async def test_move_aperture_does_nothing_when_none_selected(
mock_set: MagicMock, aperture_scatterguard: ApertureScatterguard, RE: RunEngine
aperture_scatterguard: ApertureScatterguard, RE: RunEngine
):
assert aperture_scatterguard.aperture_positions
await aperture_scatterguard.set(aperture_scatterguard.aperture_positions.ROBOT_LOAD)

RE(move_aperture_if_required(aperture_scatterguard, None))
mock_set.assert_not_called()
with patch.object(aperture_scatterguard, "set") as mock_set:
RE(move_aperture_if_required(aperture_scatterguard, None))
mock_set.assert_not_called()

0 comments on commit 4bed47e

Please sign in to comment.