diff --git a/src/ophyd_async/core/signal.py b/src/ophyd_async/core/signal.py index 72c884127a..fc114a8df4 100644 --- a/src/ophyd_async/core/signal.py +++ b/src/ophyd_async/core/signal.py @@ -3,6 +3,7 @@ import asyncio import functools from typing import ( + Any, AsyncGenerator, Awaitable, Callable, @@ -293,7 +294,7 @@ async def _verify_readings( assert result[signal] == expectation[signal] -async def assert_value(signal: SignalR[T], value: T) -> None: +async def assert_value(signal: SignalR[T], value: Any) -> None: """Assert a signal's value and compare it an expected signal. Parameters @@ -312,7 +313,7 @@ async def assert_value(signal: SignalR[T], value: T) -> None: assert await signal.get_value() == value -async def assert_reading(readable: Readable, reading: Dict[str, Reading]) -> None: +async def assert_reading(readable: Readable, reading: Mapping[str, Reading]) -> None: """Assert readings from readable. Parameters diff --git a/tests/epics/demo/test_demo.py b/tests/epics/demo/test_demo.py index 832143de99..afb5c62675 100644 --- a/tests/epics/demo/test_demo.py +++ b/tests/epics/demo/test_demo.py @@ -9,6 +9,8 @@ from ophyd_async.core import ( DeviceCollector, NotConnected, + assert_reading, + assert_value, set_sim_callback, set_sim_value, ) @@ -84,7 +86,8 @@ async def test_mover_moving_well(sim_mover: demo.Mover) -> None: precision=3, time_elapsed=pytest.approx(0.0, abs=0.05), ) - assert 0.55 == await sim_mover.setpoint.get_value() + + await assert_value(sim_mover.setpoint, 0.55) assert not s.done done.assert_not_called() await asyncio.sleep(0.1) @@ -110,24 +113,30 @@ async def test_mover_moving_well(sim_mover: demo.Mover) -> None: async def test_sensor_reading_shows_value(sim_sensor: demo.Sensor): # Check default value + await assert_value(sim_sensor.value, pytest.approx(0.0)) assert (await sim_sensor.value.get_value()) == pytest.approx(0.0) - assert (await sim_sensor.read()) == { - "sim_sensor-value": { - "alarm_severity": 0, - "timestamp": ANY, - "value": 0.0, - } - } - + await assert_reading( + sim_sensor, + { + "sim_sensor-value": { + "value": 0.0, + "alarm_severity": 0, + "timestamp": ANY, + } + }, + ) # Check different value set_sim_value(sim_sensor.value, 5.0) - assert (await sim_sensor.read()) == { - "sim_sensor-value": { - "alarm_severity": 0, - "timestamp": ANY, - "value": 5.0, - } - } + await assert_reading( + sim_sensor, + { + "sim_sensor-value": { + "value": 5.0, + "timestamp": ANY, + "alarm_severity": 0, + } + }, + ) async def test_mover_stopped(sim_mover: demo.Mover): @@ -254,9 +263,28 @@ async def test_dynamic_sensor_group_read_and_describe( await sim_sensor_group.stage() description = await sim_sensor_group.describe() - reading = await sim_sensor_group.read() - await sim_sensor_group.unstage() + await sim_sensor_group.unstage() + await assert_reading( + sim_sensor_group, + { + "sim_sensor_group-sensors-1-value": { + "value": 0.0, + "timestamp": ANY, + "alarm_severity": 0, + }, + "sim_sensor_group-sensors-2-value": { + "value": 0.5, + "timestamp": ANY, + "alarm_severity": 0, + }, + "sim_sensor_group-sensors-3-value": { + "value": 1.0, + "timestamp": ANY, + "alarm_severity": 0, + }, + }, + ) assert description == { "sim_sensor_group-sensors-1-value": { "dtype": "number", @@ -274,23 +302,6 @@ async def test_dynamic_sensor_group_read_and_describe( "source": "sim://SIM:SENSOR:3:Value", }, } - assert reading == { - "sim_sensor_group-sensors-1-value": { - "alarm_severity": 0, - "timestamp": ANY, - "value": 0.0, - }, - "sim_sensor_group-sensors-2-value": { - "alarm_severity": 0, - "timestamp": ANY, - "value": 0.5, - }, - "sim_sensor_group-sensors-3-value": { - "alarm_severity": 0, - "timestamp": ANY, - "value": 1.0, - }, - } @patch("ophyd_async.epics.demo.subprocess.Popen")