|
1 | 1 | # pyright: reportMissingParameterType=false |
2 | | -import asyncio |
3 | | -import sys |
4 | 2 | from contextlib import nullcontext |
5 | 3 | from unittest.mock import ANY, MagicMock, call, patch |
6 | 4 |
|
|
25 | 23 | ) |
26 | 24 | from tests.conftest import MOCK_PREFIX |
27 | 25 |
|
28 | | -if sys.version_info < (3, 11): |
29 | | - aio_timeout_error = asyncio.exceptions.TimeoutError |
30 | | -else: |
31 | | - aio_timeout_error = TimeoutError |
32 | | - |
33 | 26 |
|
34 | 27 | async def _make_block(clazz): |
35 | 28 | block = clazz(float, MOCK_PREFIX, "float_block") |
@@ -192,7 +185,7 @@ async def test_block_set_with_timeout(): |
192 | 185 |
|
193 | 186 | set_mock_value(block.readback, 10) |
194 | 187 |
|
195 | | - with pytest.raises(aio_timeout_error): |
| 188 | + with pytest.raises(TimeoutError): |
196 | 189 | await block.set(20) |
197 | 190 |
|
198 | 191 | func.assert_called_once_with(20, 10) |
@@ -234,7 +227,7 @@ async def test_block_set_waiting_for_global_moving_flag_timeout(): |
234 | 227 |
|
235 | 228 | set_mock_value(block.global_moving, True) |
236 | 229 | with patch("ibex_bluesky_core.devices.block.asyncio.sleep") as mock_aio_sleep: |
237 | | - with pytest.raises(aio_timeout_error): |
| 230 | + with pytest.raises(TimeoutError): |
238 | 231 | await block.set(10) |
239 | 232 | # Only check first call, as wait_for_value from ophyd_async gives us a few more... |
240 | 233 | assert mock_aio_sleep.mock_calls[0] == call(GLOBAL_MOVING_FLAG_PRE_WAIT) |
@@ -359,33 +352,36 @@ async def test_block_mot_set_within_limits(mot_block): |
359 | 352 | get_mock_put(mot_block.user_setpoint).assert_called_once_with(20, wait=True) |
360 | 353 |
|
361 | 354 |
|
362 | | -@pytest.mark.skipif( |
363 | | - ophyd_async._version.version_tuple < (0, 13, 2), |
364 | | - reason="Exception only raised in ophyd_async >= 0.13.2", |
365 | | -) |
366 | 355 | async def test_block_mot_set_outside_limits(mot_block): |
367 | 356 | # Local import as API not available in older ophyd_async versions |
368 | | - from ophyd_async.epics.motor import MotorLimitsException # noqa PLC0415 |
| 357 | + if ophyd_async._version.version_tuple >= (0, 13, 5): |
| 358 | + from ophyd_async.epics.motor import MotorLimitsError # pyright: ignore # noqa PLC0415 |
| 359 | + |
| 360 | + err = MotorLimitsError |
| 361 | + else: |
| 362 | + from ophyd_async.epics.motor import MotorLimitsException # pyright: ignore # noqa PLC0415 |
| 363 | + |
| 364 | + err = MotorLimitsException |
369 | 365 |
|
370 | 366 | set_mock_value(mot_block.user_setpoint, 10) |
371 | 367 | set_mock_value(mot_block.velocity, 10) |
372 | 368 | set_mock_value(mot_block.high_limit_travel, 15) |
373 | 369 | set_mock_value(mot_block.low_limit_travel, 5) |
374 | | - with pytest.raises(MotorLimitsException): |
| 370 | + with pytest.raises(err): |
375 | 371 | await mot_block.set(20) |
376 | 372 |
|
377 | 373 |
|
378 | 374 | @pytest.mark.parametrize("timeout_is_error", [True, False]) |
379 | 375 | async def test_block_failing_write(timeout_is_error): |
380 | 376 | block = await _block_with_write_config(BlockWriteConfig(timeout_is_error=timeout_is_error)) |
381 | 377 |
|
382 | | - get_mock_put(block.setpoint).side_effect = aio_timeout_error |
| 378 | + get_mock_put(block.setpoint).side_effect = TimeoutError |
383 | 379 |
|
384 | | - with pytest.raises(aio_timeout_error) if timeout_is_error else nullcontext(): |
| 380 | + with pytest.raises(TimeoutError) if timeout_is_error else nullcontext(): |
385 | 381 | await block.set(1) |
386 | 382 |
|
387 | 383 |
|
388 | 384 | async def test_block_failing_write_with_default_write_config(writable_block): |
389 | | - get_mock_put(writable_block.setpoint).side_effect = aio_timeout_error |
390 | | - with pytest.raises(aio_timeout_error): |
| 385 | + get_mock_put(writable_block.setpoint).side_effect = TimeoutError |
| 386 | + with pytest.raises(TimeoutError): |
391 | 387 | await writable_block.set(1) |
0 commit comments