Skip to content

Commit

Permalink
added test for observe_signals_value
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Nov 15, 2024
1 parent b951b84 commit 5e7e80b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/ophyd_async/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
assert_emitted,
assert_reading,
assert_value,
observe_signals_value,
observe_value,
set_and_wait_for_other_value,
set_and_wait_for_value,
Expand Down Expand Up @@ -158,6 +159,7 @@
"assert_reading",
"assert_value",
"observe_value",
"observe_signals_value",
"set_and_wait_for_value",
"set_and_wait_for_other_value",
"soft_signal_r_and_setter",
Expand Down
4 changes: 2 additions & 2 deletions src/ophyd_async/core/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,13 @@ async def observe_value(
do_something_with(value)
"""

async for _, value in observe_signals_values(
async for _, value in observe_signals_value(
signal, timeout=timeout, done_status=done_status
):
yield value


async def observe_signals_values(
async def observe_signals_value(
*signals: SignalR[SignalDatatypeT],
timeout: float | None = None,
done_status: Status | None = None,
Expand Down
29 changes: 28 additions & 1 deletion tests/core/test_observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import pytest

from ophyd_async.core import AsyncStatus, observe_value, soft_signal_r_and_setter
from ophyd_async.core import (
AsyncStatus,
observe_signals_value,
observe_value,
soft_signal_r_and_setter,
)


async def test_observe_value_working_correctly():
Expand All @@ -22,6 +27,28 @@ async def tick():
await status


async def test_observes_signals_values_working_correctly():
sig1, setter1 = soft_signal_r_and_setter(float)
sig2, setter2 = soft_signal_r_and_setter(float)

async def tick():
for i in range(2):
await asyncio.sleep(0.01)
setter1(i + 1)
setter2(i + 10)

recv1 = []
recv2 = []
status = AsyncStatus(tick())
async for signal, value in observe_signals_value(sig1, sig2, done_status=status):
if signal is sig1:
recv1.append(value)
elif signal is sig2:
recv2.append(value)
assert recv1 == [0, 1, 2] and recv2 == [0, 10, 11]
await status


async def test_observe_value_times_out():
sig, setter = soft_signal_r_and_setter(float)

Expand Down

0 comments on commit 5e7e80b

Please sign in to comment.