diff --git a/src/ophyd_async/core/signal.py b/src/ophyd_async/core/signal.py index 1f29cf7928..5bb73cb42d 100644 --- a/src/ophyd_async/core/signal.py +++ b/src/ophyd_async/core/signal.py @@ -24,6 +24,7 @@ Stageable, Subscribable, ) +from event_model.documents import DocumentType from .async_status import AsyncStatus from .device import Device @@ -58,7 +59,6 @@ def __init__( self, backend: SignalBackend[T], timeout: Optional[float] = DEFAULT_TIMEOUT ) -> None: self._name = "" - self._long_name = None self._timeout = timeout self._init_backend = self._backend = backend @@ -257,7 +257,7 @@ def set_sim_callback(signal: Signal[T], callback: ReadingValueCallback[T]) -> No return _sim_backends[signal].set_callback(callback) -async def verify_readable( +async def _verify_readings( func: Callable[[], dict[str, Any] | Awaitable[dict[str, Any]]], expectation: Dict[str, Any], ) -> None: @@ -269,23 +269,33 @@ async def verify_readable( result = func() for signal in expectation: - for field in expectation[signal]: - if field == "timestamp": - assert isinstance(result[signal]["timestamp"], float) - else: - assert result[signal][field] == expectation[signal][field] + assert result[signal] == expectation[signal] async def assert_value(signal: SignalR[T], value: T) -> None: - """Assert a signal value""" + """Assert a signal value + Parameters + ---------- + signal: + Call get_valueand and compare it with expected value. + value: + the expected value from the signal. + + Notes + ----- + Example usage:: + await assert_reading(signal, value) + + + """ assert await signal.get_value() == value async def assert_reading( readable: Readable, reading: Dict[str, Reading] | dict[str, dict[str, Any]] ) -> None: - """Assert readable by calling verify_readable""" - await verify_readable(readable.read, reading) + """Assert readable by calling_verify_readings""" + await _verify_readings(readable.read, reading) async def assert_configuration( @@ -293,11 +303,11 @@ async def assert_configuration( configuration: Dict[str, Reading] | dict[str, dict[str, Any]], ) -> None: """Assert readable generated by configurable.read_configuration - using verify_readable""" - await verify_readable(configurable.read_configuration, configuration) + using _verify_readings""" + await _verify_readings(configurable.read_configuration, configuration) -def assert_emitted(docs: Dict[str, list], **numbers: int): +def assert_emitted(docs: Dict[str, list[DocumentType]], **numbers: int): """Assert emitted""" assert list(docs) == list(numbers) assert {name: len(d) for name, d in docs.items()} == numbers diff --git a/tests/core/test_signal.py b/tests/core/test_signal.py index fbc60c531a..f0d5559553 100644 --- a/tests/core/test_signal.py +++ b/tests/core/test_signal.py @@ -1,6 +1,7 @@ import asyncio import re import time +from unittest.mock import ANY import pytest @@ -143,7 +144,7 @@ async def test_assert_value(sim_signal: SignalRW): async def test_assert_reaading(sim_signal: SignalRW): set_sim_value(sim_signal, 888) dummy_reading = { - "sim_signal": {"alarm_severity": 0, "timestamp": 46709394.28, "value": 888} + "sim_signal": {"alarm_severity": 0, "timestamp": ANY, "value": 888} } await assert_reading(sim_signal, dummy_reading) @@ -180,12 +181,12 @@ async def test_assert_configuration(sim_readable: DummyReadable): dummy_config_reading = { "sim_readable-mode": { "alarm_severity": 0, - "timestamp": 123.2, + "timestamp": ANY, "value": "super mode", }, "sim_readable-mode2": { "alarm_severity": 0, - "timestamp": 123.2, + "timestamp": ANY, "value": "slow mode", }, } @@ -195,8 +196,8 @@ async def test_assert_configuration(sim_readable: DummyReadable): something = DetWithConf(name="det") dummy_config_reading1 = { - "det_c": {"value": 3, "timestamp": 171}, - "det_d": {"value": 4, "timestamp": 1753}, + "det_c": {"value": 3, "timestamp": ANY}, + "det_d": {"value": 4, "timestamp": ANY}, } await assert_configuration(something, dummy_config_reading1)