Skip to content

Commit

Permalink
(#325) Give spec to Mock so it throws when typo in assert
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed May 23, 2024
1 parent 1a9a919 commit 4b2dee3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ophyd_async/core/mock_signal_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from functools import cached_property
from typing import Optional, Type
from typing import Callable, Optional, Type
from unittest.mock import Mock

from bluesky.protocols import Descriptor, Reading
Expand Down Expand Up @@ -47,7 +47,7 @@ async def connect(self, timeout: float = DEFAULT_TIMEOUT) -> None:

@cached_property
def put_mock(self) -> Mock:
return Mock(name="put")
return Mock(name="put", spec=Callable)

@cached_property
def put_proceeds(self) -> asyncio.Event:
Expand Down
10 changes: 10 additions & 0 deletions tests/core/test_mock_signal_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,13 @@ async def set(self):
assert await signal.get_value() == 0
backend_put(100)
assert await signal.get_value() == 100


async def test_when_put_mock_called_with_typo_then_fails_but_calling_directly_passes():
mock_signal = SignalRW(SoftSignalBackend(int))
await mock_signal.connect(mock=True)
assert isinstance(mock_signal._backend, MockSignalBackend)
mock = mock_signal._backend.put_mock
with pytest.raises(AttributeError):
mock.asssert_called_once() # Note typo here is deliberate!
mock()

0 comments on commit 4b2dee3

Please sign in to comment.