Skip to content

Commit 0e34b85

Browse files
committed
codecov, fix tests after functionality change
1 parent 54800e2 commit 0e34b85

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/trio/_tests/test_channel.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ async def do_send(s: trio.MemorySendChannel[int], v: int) -> None:
417417

418418

419419
async def test_background_with_channel() -> None:
420-
@background_with_channel()
420+
@background_with_channel(1)
421421
async def agen() -> AsyncGenerator[int]:
422422
yield 1
423423
await trio.sleep_forever() # simulate deadlock
@@ -461,11 +461,11 @@ async def test_background_with_channel_cancelled() -> None:
461461
with trio.CancelScope() as cs:
462462

463463
@background_with_channel()
464-
async def agen() -> AsyncGenerator[int]:
465-
yield 1
466-
raise AssertionError( # pragma: no cover
467-
"cancel before consumption means generator should not be iteratod"
464+
async def agen() -> AsyncGenerator[None]: # pragma: no cover
465+
raise AssertionError(
466+
"cancel before consumption means generator should not be iterated"
468467
)
468+
yield # indicate that we're an iterator
469469

470470
async with agen():
471471
cs.cancel()
@@ -491,7 +491,6 @@ async def test_background_with_channel_buffer_size_too_small(
491491
@background_with_channel(0)
492492
async def agen() -> AsyncGenerator[int]:
493493
yield 1
494-
yield 2
495494
raise AssertionError(
496495
"buffer size 0 means we shouldn't be asked for another value"
497496
) # pragma: no cover
@@ -526,7 +525,7 @@ async def test_background_with_channel_no_interleave() -> None:
526525
@background_with_channel()
527526
async def agen() -> AsyncGenerator[int]:
528527
yield 1
529-
raise AssertionError
528+
raise AssertionError # pragma: no cover
530529

531530
async with agen() as recv_chan:
532531
assert await recv_chan.__anext__() == 1
@@ -547,7 +546,7 @@ async def agen() -> AsyncGenerator[int]:
547546
Matcher(TypeError, match="^iterator$"),
548547
):
549548
async with agen() as recv_chan:
550-
async for i in recv_chan:
549+
async for i in recv_chan: # pragma: no branch
551550
assert i == 1
552551
await event.wait()
553552
raise TypeError("iterator")
@@ -572,7 +571,7 @@ async def agen(stuff: list[str]) -> AsyncGenerator[int]:
572571
Matcher(TypeError, match="^iterator$"),
573572
):
574573
async with agen(events) as recv_chan:
575-
async for i in recv_chan:
574+
async for i in recv_chan: # pragma: no branch
576575
assert i == 1
577576
raise TypeError("iterator")
578577

@@ -602,3 +601,18 @@ async def test_background_with_channel_no_parens() -> None:
602601
@background_with_channel # type: ignore[arg-type]
603602
async def agen() -> AsyncGenerator[None]:
604603
yield # pragma: no cover
604+
605+
606+
async def test_background_with_channel_inf_buffer() -> None:
607+
event = trio.Event()
608+
609+
# agen immediately starts yielding numbers
610+
# into the buffer upon entering the cm
611+
@background_with_channel(None)
612+
async def agen() -> AsyncGenerator[int]:
613+
for i in range(10):
614+
yield i
615+
event.set()
616+
617+
async with agen() as _:
618+
await event.wait()

0 commit comments

Comments
 (0)