Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b3ed6a7
Remove get-xyz-limits
teoching0705 Sep 15, 2025
e974bf7
Change test exception to MotorLimitsException
teoching0705 Sep 15, 2025
69b8f9e
Remove SampleException
teoching0705 Sep 15, 2025
2ef83ad
Change pytest.raises
teoching0705 Sep 15, 2025
a954272
Change pytest.raises
teoching0705 Sep 15, 2025
bf035c8
Revert "Change pytest.raises"
teoching0705 Sep 16, 2025
668d1e8
Revert "Change pytest.raises"
teoching0705 Sep 16, 2025
5ca5310
Revert "Remove SampleException"
teoching0705 Sep 16, 2025
5b92590
Revert "Change test exception to MotorLimitsException"
teoching0705 Sep 16, 2025
437f522
Revert "Remove get-xyz-limits"
teoching0705 Sep 16, 2025
b1f4deb
Try to catch the MotorLimitsException and re-raise a SampleException
teoching0705 Sep 16, 2025
2cafc20
Change try/catch exception behaviour
teoching0705 Sep 17, 2025
cc3a1d0
Add testing for moving smargon raising error that is not motorlimitse…
teoching0705 Sep 17, 2025
beb28aa
Fix test
teoching0705 Sep 18, 2025
6036c0f
Add checking failed status
teoching0705 Sep 18, 2025
37aae24
Fix test
teoching0705 Sep 18, 2025
bbfa7d0
Fix codedev
teoching0705 Sep 18, 2025
6d64a97
Merge branch 'main' into remove-get-xyz-limits
teoching0705 Sep 18, 2025
dfd6f59
Re raise failed status
teoching0705 Sep 22, 2025
7660790
Change test for re raised failed status
teoching0705 Sep 22, 2025
23b5a90
Fix test
teoching0705 Sep 22, 2025
1785bc4
Fix test
teoching0705 Sep 22, 2025
8210501
test FailedStatus structure
teoching0705 Sep 22, 2025
63a3446
test FailedStatus structure
teoching0705 Sep 22, 2025
6be3815
test FailedStatus structure
teoching0705 Sep 22, 2025
3b426b4
Fix test
teoching0705 Sep 22, 2025
86e0d2f
Fix test
teoching0705 Sep 22, 2025
d2c1c6e
Fix test
teoching0705 Sep 22, 2025
4def26c
Fix test
teoching0705 Sep 22, 2025
6a4ed02
Fix test
teoching0705 Sep 22, 2025
53d780f
Fix test
teoching0705 Sep 22, 2025
52d5246
Fix test
teoching0705 Sep 22, 2025
721d148
Fix test
teoching0705 Sep 22, 2025
4270029
Fix patching issues
teoching0705 Sep 22, 2025
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
21 changes: 13 additions & 8 deletions src/mx_bluesky/hyperion/device_setup_plans/smargon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
from bluesky import plan_stubs as bps
from bluesky.utils import FailedStatus
from dodal.devices.smargon import CombinedMove, Smargon
from ophyd_async.epics.motor import MotorLimitsException

from mx_bluesky.common.utils.exceptions import SampleException

Expand All @@ -9,12 +11,15 @@ def move_smargon_warn_on_out_of_range(
smargon: Smargon, position: np.ndarray | list[float] | tuple[float, float, float]
):
"""Throws a SampleException if the specified position is out of range for the
smargon. Otherwise moves to that position."""
limits = yield from smargon.get_xyz_limits()
if not limits.position_valid(position):
raise SampleException(
"Pin tip centring failed - pin too long/short/bent and out of range"
smargon. Otherwise moves to that position. The check is from ophyd-async"""
try:
yield from bps.mv(
smargon, CombinedMove(x=position[0], y=position[1], z=position[2])
)
yield from bps.mv(
smargon, CombinedMove(x=position[0], y=position[1], z=position[2])
)
except FailedStatus as fs:
Comment thread
teoching0705 marked this conversation as resolved.
if isinstance(fs.__cause__, MotorLimitsException):
raise SampleException(
"Pin tip centring failed - pin too long/short/bent and out of range"
) from fs.__cause__
else:
raise fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from bluesky import plan_stubs as bps
from bluesky.plan_stubs import null
from bluesky.run_engine import RunEngine, RunEngineResult
from bluesky.utils import FailedStatus
from dodal.devices.backlight import Backlight
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.oav.pin_image_recognition import PinTipDetection
from dodal.devices.oav.pin_image_recognition.utils import SampleLocation
from dodal.devices.oav.utils import PinNotFoundException
from dodal.devices.smargon import Smargon
from ophyd.sim import NullStatus
from ophyd_async.epics.motor import MotorLimitsException
from ophyd_async.testing import get_mock_put, set_mock_value

from mx_bluesky.common.utils.exceptions import SampleException, WarningException
Expand Down Expand Up @@ -286,6 +288,32 @@ def test_given_moving_out_of_range_when_move_with_warn_called_then_warning_excep
RE(move_smargon_warn_on_out_of_range(smargon, (100, 0, 0)))


@patch(
"mx_bluesky.hyperion.device_setup_plans.smargon.bps.mv",
new=MagicMock(side_effect=FailedStatus(RuntimeError("RuntimeError"))),
)
def test_re_raise_failed_status_that_is_not_MotorLimitsException(
RE: RunEngine, smargon: Smargon
):
with pytest.raises(FailedStatus) as fs:
RE(move_smargon_warn_on_out_of_range(smargon, (0, 0, 0)))

assert fs.type is FailedStatus
assert not isinstance(fs.value.args[0], MotorLimitsException)
assert isinstance(fs.value.args[0], RuntimeError)


@patch(
"mx_bluesky.hyperion.device_setup_plans.smargon.bps.mv",
new=MagicMock(side_effect=RuntimeError("RuntimeError")),
)
def test_does_not_catch_exception_that_is_not_MotorLimitsException(
RE: RunEngine, smargon: Smargon
):
with pytest.raises(RuntimeError, match="RuntimeError"):
RE(move_smargon_warn_on_out_of_range(smargon, (0, 0, 0)))


def return_pixel(pixel, *args):
yield from null()
return pixel
Expand Down
Loading