Skip to content

Commit

Permalink
Make mock_puts_blocked a sync contextmanager as it doesn't do any asy…
Browse files Browse the repository at this point in the history
…nc things (#672)

# Changes
```python
# old
async with mock_puts_blocked(sig):
    ...
# old
with mock_puts_blocked(sig):
    ...
```
  • Loading branch information
coretl authored and evalott100 committed Nov 27, 2024
1 parent f79c3c4 commit 48ec45f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/ophyd_async/core/_mock_signal_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Awaitable, Callable, Iterable
from contextlib import asynccontextmanager, contextmanager
from contextlib import contextmanager
from unittest.mock import AsyncMock, Mock

from ._device import Device
Expand Down Expand Up @@ -40,8 +40,8 @@ def set_mock_put_proceeds(signal: Signal, proceeds: bool):
backend.put_proceeds.clear()


@asynccontextmanager
async def mock_puts_blocked(*signals: Signal):
@contextmanager
def mock_puts_blocked(*signals: Signal):
for signal in signals:
set_mock_put_proceeds(signal, False)
yield
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_mock_signal_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def test_mock_utils_throw_error_if_backend_isnt_mock_signal_backend():
get_mock_put(signal).assert_called_once_with(10)
exc_msgs.append(str(exc.value))
with pytest.raises(AssertionError) as exc:
async with mock_puts_blocked(signal):
with mock_puts_blocked(signal):
...
exc_msgs.append(str(exc.value))
with pytest.raises(AssertionError) as exc:
Expand Down Expand Up @@ -182,7 +182,7 @@ async def mock_signals():
async def test_blocks_during_put(mock_signals):
signal1, signal2 = mock_signals

async with mock_puts_blocked(signal1, signal2):
with mock_puts_blocked(signal1, signal2):
status1 = signal1.set("second_value", wait=True, timeout=None)
status2 = signal2.set("second_value", wait=True, timeout=None)
assert await signal1.get_value() == "second_value"
Expand Down
2 changes: 1 addition & 1 deletion tests/epics/test_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async def test_locatable(sim_motor: motor.Motor) -> None:
lambda x, *_, **__: set_mock_value(sim_motor.user_readback, x),
)
assert (await sim_motor.locate())["readback"] == 0
async with mock_puts_blocked(sim_motor.user_setpoint):
with mock_puts_blocked(sim_motor.user_setpoint):
move_status = sim_motor.set(10)
assert (await sim_motor.locate())["readback"] == 0
await move_status
Expand Down

0 comments on commit 48ec45f

Please sign in to comment.