Skip to content

Commit

Permalink
'return; yield' isn't considered covered
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 25, 2024
1 parent 9bbaef0 commit 1e10e62
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/trio/_core/_tests/test_ki.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ def __eq__(self, other: object) -> bool:

@_core.enable_ki_protection
async def _protected_async_gen_fn() -> AsyncGenerator[None, None]:
return
yield


Expand All @@ -652,13 +651,11 @@ async def _protected_async_fn() -> None:

@_core.enable_ki_protection
def _protected_gen_fn() -> Generator[None, None, None]:
return
yield


@_core.disable_ki_protection
async def _unprotected_async_gen_fn() -> AsyncGenerator[None, None]:
return
yield


Expand All @@ -669,20 +666,27 @@ async def _unprotected_async_fn() -> None:

@_core.disable_ki_protection
def _unprotected_gen_fn() -> Generator[None, None, None]:
return
yield


async def _consume_async_generator(agen: AsyncGenerator[None, None]) -> None:
try:
with pytest.raises(StopAsyncIteration):
while True:
await agen.asend(None)
finally:
await agen.aclose()


def _consume_function_for_coverage(fn: Callable[..., object]) -> None:
result = fn()
if inspect.isasyncgen(result):
with pytest.raises(StopAsyncIteration):
result.asend(None).send(None)
return
result = _consume_async_generator(result)

assert inspect.isgenerator(result) or inspect.iscoroutine(result)
with pytest.raises(StopIteration):
result.send(None)
while True:
result.send(None)


def test_enable_disable_ki_protection_passes_on_inspect_flags() -> None:
Expand Down

0 comments on commit 1e10e62

Please sign in to comment.