Skip to content

Commit caea4e0

Browse files
committed
Add None-value tests for broadcast and anycast channels
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 1fcc0a4 commit caea4e0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/test_anycast.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
"""Tests for the Channel implementation."""
55

6+
from __future__ import annotations
7+
68
import asyncio
79

810
import pytest
@@ -147,6 +149,23 @@ async def test_anycast_full() -> None:
147149
assert False
148150

149151

152+
async def test_anycast_none_values() -> None:
153+
"""Ensure None values can be sent and received."""
154+
acast: Anycast[int | None] = Anycast()
155+
156+
sender = acast.new_sender()
157+
receiver = acast.new_receiver()
158+
159+
await sender.send(5)
160+
assert await receiver.receive() == 5
161+
162+
await sender.send(None)
163+
assert await receiver.receive() is None
164+
165+
await sender.send(10)
166+
assert await receiver.receive() == 10
167+
168+
150169
async def test_anycast_async_iterator() -> None:
151170
"""Check that the anycast receiver works as an async iterator."""
152171
acast: Anycast[str] = Anycast()

tests/test_broadcast.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
"""Tests for the Broadcast implementation."""
55

6+
from __future__ import annotations
7+
68
import asyncio
79
from typing import Tuple
810

@@ -69,6 +71,23 @@ async def update_tracker_on_receive(receiver_id: int, recv: Receiver[int]) -> No
6971
assert actual_sum == expected_sum
7072

7173

74+
async def test_broadcast_none_values() -> None:
75+
"""Ensure None values can be sent and received."""
76+
bcast: Broadcast[int | None] = Broadcast("any_channel")
77+
78+
sender = bcast.new_sender()
79+
receiver = bcast.new_receiver()
80+
81+
await sender.send(5)
82+
assert await receiver.receive() == 5
83+
84+
await sender.send(None)
85+
assert await receiver.receive() is None
86+
87+
await sender.send(10)
88+
assert await receiver.receive() == 10
89+
90+
7291
async def test_broadcast_after_close() -> None:
7392
"""Ensure closed channels can't get new messages."""
7493
bcast: Broadcast[int] = Broadcast("meter_5")

0 commit comments

Comments
 (0)