Skip to content

Commit

Permalink
Removed testing against the async generator wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jan 24, 2022
1 parent 5e13eb9 commit 00f6662
Showing 1 changed file with 4 additions and 53 deletions.
57 changes: 4 additions & 53 deletions trio/_core/tests/test_ki.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,79 +138,30 @@ def protected_manager():


async def test_agen_protection():
@_core.enable_ki_protection
async def agen_protected1():
assert _core.currently_ki_protected()
try:
yield
finally:
assert _core.currently_ki_protected()

@_core.disable_ki_protection
async def agen_unprotected1():
assert not _core.currently_ki_protected()
try:
yield
finally:
assert not _core.currently_ki_protected()

# Swap the order of the decorators:
@_core.enable_ki_protection
async def agen_protected2():
assert _core.currently_ki_protected()
try:
yield
finally:
assert _core.currently_ki_protected()

@_core.disable_ki_protection
async def agen_unprotected2():
assert not _core.currently_ki_protected()
try:
yield
finally:
assert not _core.currently_ki_protected()

# Native async generators
@_core.enable_ki_protection
async def agen_protected3():
async def agen_protected():
assert _core.currently_ki_protected()
try:
yield
finally:
assert _core.currently_ki_protected()

@_core.disable_ki_protection
async def agen_unprotected3():
async def agen_unprotected():
assert not _core.currently_ki_protected()
try:
yield
finally:
assert not _core.currently_ki_protected()

for agen_fn in [
agen_protected1,
agen_protected2,
agen_protected3,
agen_unprotected1,
agen_unprotected2,
agen_unprotected3,
agen_protected,
agen_unprotected,
]:
async for _ in agen_fn(): # noqa
assert not _core.currently_ki_protected()

# asynccontextmanager insists that the function passed must itself be an
# async gen function, not a wrapper around one
if isasyncgenfunction(agen_fn):
async with contextlib.asynccontextmanager(agen_fn)():
assert not _core.currently_ki_protected()

# Another case that's tricky due to:
# https://bugs.python.org/issue29590
with pytest.raises(KeyError):
async with contextlib.asynccontextmanager(agen_fn)():
raise KeyError


# Test the case where there's no magic local anywhere in the call stack
def test_ki_disabled_out_of_context():
Expand Down

0 comments on commit 00f6662

Please sign in to comment.