Repository URL to install this package:
import contextlib
import copy
import inspect
import pickle
import sys
import types
import unittest
import warnings
from test import support
from test.support.script_helper import assert_python_ok
class AsyncYieldFrom:
def __init__(self, obj):
self.obj = obj
def __await__(self):
yield from self.obj
class AsyncYield:
def __init__(self, value):
self.value = value
def __await__(self):
yield self.value
def run_async(coro):
assert coro.__class__ in {types.GeneratorType, types.CoroutineType}
buffer = []
result = None
while True:
try:
buffer.append(coro.send(None))
except StopIteration as ex:
result = ex.args[0] if ex.args else None
break
return buffer, result
def run_async__await__(coro):
assert coro.__class__ is types.CoroutineType
aw = coro.__await__()
buffer = []
result = None
i = 0
while True:
try:
if i % 2:
buffer.append(next(aw))
else:
buffer.append(aw.send(None))
i += 1
except StopIteration as ex:
result = ex.args[0] if ex.args else None
break
return buffer, result
@contextlib.contextmanager
def silence_coro_gc():
with warnings.catch_warnings():
warnings.simplefilter("ignore")
yield
support.gc_collect()
class AsyncBadSyntaxTest(unittest.TestCase):
def test_badsyntax_1(self):
samples = [
"""def foo():
await something()
""",
"""await something()""",
"""async def foo():
yield from []
""",
"""async def foo():
await await fut
""",
"""async def foo(a=await something()):
pass
""",
"""async def foo(a:await something()):
pass
""",
"""async def foo():
def bar():
[i async for i in els]
""",
"""async def foo():
def bar():
[await i for i in els]
""",
"""async def foo():
def bar():
[i for i in els
async for b in els]
""",
"""async def foo():
def bar():
[i for i in els
for c in b
async for b in els]
""",
"""async def foo():
def bar():
[i for i in els
async for b in els
for c in b]
""",
"""async def foo():
def bar():
[i for i in els
for b in await els]
""",
"""async def foo():
def bar():
[i for i in els
for b in els
if await b]
""",
"""async def foo():
def bar():
[i for i in await els]
""",
"""async def foo():
def bar():
[i for i in els if await i]
""",
"""def bar():
[i async for i in els]
""",
"""def bar():
{i: i async for i in els}
""",
"""def bar():
{i async for i in els}
""",
"""def bar():
[await i for i in els]
""",
"""def bar():
[i for i in els
async for b in els]
""",
"""def bar():
[i for i in els
for c in b
async for b in els]
""",
"""def bar():
[i for i in els
async for b in els
for c in b]
""",
"""def bar():
[i for i in els
for b in await els]
""",
"""def bar():
[i for i in els
for b in els
if await b]
""",
"""def bar():
[i for i in await els]
""",
"""def bar():
[i for i in els if await i]
""",
"""async def foo():
await
""",
"""async def foo():
def bar(): pass
await = 1
""",
"""async def foo():
def bar(): pass
await = 1
""",
"""async def foo():
def bar(): pass
if 1:
await = 1
""",
"""def foo():
async def bar(): pass
if 1:
await a
""",
"""def foo():
async def bar(): pass
await a
""",
"""def foo():
def baz(): pass
async def bar(): pass
await a
""",
"""def foo():
def baz(): pass
# 456
async def bar(): pass
# 123
await a
""",
"""async def foo():
def baz(): pass
# 456
async def bar(): pass
# 123
await = 2
""",
"""def foo():
def baz(): pass
async def bar(): pass
await a
""",
"""async def foo():
def baz(): pass
async def bar(): pass
await = 2
""",
"""async def foo():
def async(): pass
""",
"""async def foo():
def await(): pass
""",
"""async def foo():
def bar():
await
""",
"""async def foo():
return lambda async: await
""",
"""async def foo():
return lambda a: await
""",
"""await a()""",
"""async def foo(a=await b):
pass
""",
"""async def foo(a:await b):
pass
""",
"""def baz():
async def foo(a=await b):
pass
""",
"""async def foo(async):
pass
""",
"""async def foo():
def bar():
def baz():
async = 1
""",
"""async def foo():
def bar():
def baz():
pass
async = 1
""",
"""def foo():
async def bar():
async def baz():
pass
def baz():
42
async = 1
""",
"""async def foo():
def bar():
def baz():
pass\nawait foo()
""",
"""def foo():
def bar():
Loading ...