mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
bpo-34728: Fix asyncio tests to run under "-Werror" (GH-9661)
This commit is contained in:
parent
11c4eaa993
commit
9012a0fb4c
14 changed files with 192 additions and 206 deletions
|
|
@ -395,9 +395,9 @@ async def to_list(self, gen):
|
|||
def test_async_gen_asyncio_01(self):
|
||||
async def gen():
|
||||
yield 1
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield 2
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
return
|
||||
yield 3
|
||||
|
||||
|
|
@ -407,7 +407,7 @@ async def gen():
|
|||
def test_async_gen_asyncio_02(self):
|
||||
async def gen():
|
||||
yield 1
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield 2
|
||||
1 / 0
|
||||
yield 3
|
||||
|
|
@ -421,7 +421,7 @@ def test_async_gen_asyncio_03(self):
|
|||
class Gen:
|
||||
async def __aiter__(self):
|
||||
yield 1
|
||||
await asyncio.sleep(0.01, loop=loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield 2
|
||||
|
||||
res = loop.run_until_complete(self.to_list(Gen()))
|
||||
|
|
@ -430,13 +430,13 @@ async def __aiter__(self):
|
|||
def test_async_gen_asyncio_anext_04(self):
|
||||
async def foo():
|
||||
yield 1
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
try:
|
||||
yield 2
|
||||
yield 3
|
||||
except ZeroDivisionError:
|
||||
yield 1000
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield 4
|
||||
|
||||
async def run1():
|
||||
|
|
@ -587,7 +587,7 @@ async def foo():
|
|||
yield 1
|
||||
1 / 0
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield 12
|
||||
|
||||
async def run():
|
||||
|
|
@ -610,8 +610,8 @@ async def foo():
|
|||
yield 1
|
||||
1 / 0
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE += 1
|
||||
DONE += 1000
|
||||
|
||||
|
|
@ -637,8 +637,8 @@ async def foo():
|
|||
DONE += 1000
|
||||
yield 2
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE += 1
|
||||
DONE += 1000
|
||||
|
||||
|
|
@ -647,7 +647,7 @@ async def run():
|
|||
it = gen.__aiter__()
|
||||
self.assertEqual(await it.__anext__(), 1)
|
||||
t = self.loop.create_task(it.__anext__())
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await gen.aclose()
|
||||
return t
|
||||
|
||||
|
|
@ -657,7 +657,7 @@ async def run():
|
|||
# Silence ResourceWarnings
|
||||
fut.cancel()
|
||||
t.cancel()
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
def test_async_gen_asyncio_gc_aclose_09(self):
|
||||
DONE = 0
|
||||
|
|
@ -668,8 +668,8 @@ async def gen():
|
|||
while True:
|
||||
yield 1
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE = 1
|
||||
|
||||
async def run():
|
||||
|
|
@ -678,7 +678,7 @@ async def run():
|
|||
await g.__anext__()
|
||||
del g
|
||||
|
||||
await asyncio.sleep(0.1, loop=self.loop)
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
self.loop.run_until_complete(run())
|
||||
self.assertEqual(DONE, 1)
|
||||
|
|
@ -769,15 +769,15 @@ def sgen():
|
|||
async def gen():
|
||||
nonlocal DONE
|
||||
try:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
v = yield 1
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield v * 2
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
return
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE = 1
|
||||
|
||||
async def run():
|
||||
|
|
@ -799,20 +799,20 @@ def test_async_gen_asyncio_asend_02(self):
|
|||
DONE = 0
|
||||
|
||||
async def sleep_n_crash(delay):
|
||||
await asyncio.sleep(delay, loop=self.loop)
|
||||
await asyncio.sleep(delay)
|
||||
1 / 0
|
||||
|
||||
async def gen():
|
||||
nonlocal DONE
|
||||
try:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
v = yield 1
|
||||
await sleep_n_crash(0.01)
|
||||
DONE += 1000
|
||||
yield v * 2
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE = 1
|
||||
|
||||
async def run():
|
||||
|
|
@ -831,7 +831,7 @@ def test_async_gen_asyncio_asend_03(self):
|
|||
DONE = 0
|
||||
|
||||
async def sleep_n_crash(delay):
|
||||
fut = asyncio.ensure_future(asyncio.sleep(delay, loop=self.loop),
|
||||
fut = asyncio.ensure_future(asyncio.sleep(delay),
|
||||
loop=self.loop)
|
||||
self.loop.call_later(delay / 2, lambda: fut.cancel())
|
||||
return await fut
|
||||
|
|
@ -839,14 +839,14 @@ async def sleep_n_crash(delay):
|
|||
async def gen():
|
||||
nonlocal DONE
|
||||
try:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
v = yield 1
|
||||
await sleep_n_crash(0.01)
|
||||
DONE += 1000
|
||||
yield v * 2
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE = 1
|
||||
|
||||
async def run():
|
||||
|
|
@ -885,18 +885,18 @@ def sgen():
|
|||
async def gen():
|
||||
nonlocal DONE
|
||||
try:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
try:
|
||||
v = yield 1
|
||||
except FooEr:
|
||||
v = 1000
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield v * 2
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
# return
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE = 1
|
||||
|
||||
async def run():
|
||||
|
|
@ -921,7 +921,7 @@ class FooEr(Exception):
|
|||
pass
|
||||
|
||||
async def sleep_n_crash(delay):
|
||||
fut = asyncio.ensure_future(asyncio.sleep(delay, loop=self.loop),
|
||||
fut = asyncio.ensure_future(asyncio.sleep(delay),
|
||||
loop=self.loop)
|
||||
self.loop.call_later(delay / 2, lambda: fut.cancel())
|
||||
return await fut
|
||||
|
|
@ -929,17 +929,17 @@ async def sleep_n_crash(delay):
|
|||
async def gen():
|
||||
nonlocal DONE
|
||||
try:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
try:
|
||||
v = yield 1
|
||||
except FooEr:
|
||||
await sleep_n_crash(0.01)
|
||||
yield v * 2
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
# return
|
||||
finally:
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
DONE = 1
|
||||
|
||||
async def run():
|
||||
|
|
@ -1038,10 +1038,10 @@ def test_async_gen_asyncio_shutdown_01(self):
|
|||
async def waiter(timeout):
|
||||
nonlocal finalized
|
||||
try:
|
||||
await asyncio.sleep(timeout, loop=self.loop)
|
||||
await asyncio.sleep(timeout)
|
||||
yield 1
|
||||
finally:
|
||||
await asyncio.sleep(0, loop=self.loop)
|
||||
await asyncio.sleep(0)
|
||||
finalized += 1
|
||||
|
||||
async def wait():
|
||||
|
|
@ -1051,7 +1051,7 @@ async def wait():
|
|||
t1 = self.loop.create_task(wait())
|
||||
t2 = self.loop.create_task(wait())
|
||||
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1))
|
||||
|
||||
self.loop.run_until_complete(self.loop.shutdown_asyncgens())
|
||||
self.assertEqual(finalized, 2)
|
||||
|
|
@ -1059,7 +1059,7 @@ async def wait():
|
|||
# Silence warnings
|
||||
t1.cancel()
|
||||
t2.cancel()
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1))
|
||||
|
||||
def test_async_gen_asyncio_shutdown_02(self):
|
||||
logged = 0
|
||||
|
|
@ -1073,7 +1073,7 @@ def logger(loop, context):
|
|||
|
||||
async def waiter(timeout):
|
||||
try:
|
||||
await asyncio.sleep(timeout, loop=self.loop)
|
||||
await asyncio.sleep(timeout)
|
||||
yield 1
|
||||
finally:
|
||||
1 / 0
|
||||
|
|
@ -1083,7 +1083,7 @@ async def wait():
|
|||
pass
|
||||
|
||||
t = self.loop.create_task(wait())
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1))
|
||||
|
||||
self.loop.set_exception_handler(logger)
|
||||
self.loop.run_until_complete(self.loop.shutdown_asyncgens())
|
||||
|
|
@ -1092,12 +1092,12 @@ async def wait():
|
|||
|
||||
# Silence warnings
|
||||
t.cancel()
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1))
|
||||
|
||||
def test_async_gen_expression_01(self):
|
||||
async def arange(n):
|
||||
for i in range(n):
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
yield i
|
||||
|
||||
def make_arange(n):
|
||||
|
|
@ -1112,7 +1112,7 @@ async def run():
|
|||
|
||||
def test_async_gen_expression_02(self):
|
||||
async def wrap(n):
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
return n
|
||||
|
||||
def make_arange(n):
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ def new_loop(self):
|
|||
return asyncio.new_event_loop()
|
||||
|
||||
def run_loop_briefly(self, *, delay=0.01):
|
||||
self.loop.run_until_complete(asyncio.sleep(delay, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(delay))
|
||||
|
||||
def loop_exception_handler(self, loop, context):
|
||||
self.__unhandled_exceptions.append(context)
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ class ShowStopper(BaseException):
|
|||
pass
|
||||
|
||||
async def foo(delay):
|
||||
await asyncio.sleep(delay, loop=self.loop)
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
def throw():
|
||||
raise ShowStopper
|
||||
|
|
@ -579,7 +579,7 @@ def test_default_exc_handler_coro(self):
|
|||
|
||||
@asyncio.coroutine
|
||||
def zero_error_coro():
|
||||
yield from asyncio.sleep(0.01, loop=self.loop)
|
||||
yield from asyncio.sleep(0.01)
|
||||
1/0
|
||||
|
||||
# Test Future.__del__
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ async def on_server_client(reader, writer):
|
|||
|
||||
addr = srv.sockets[0].getsockname()
|
||||
self.loop.run_until_complete(
|
||||
asyncio.wait_for(client(addr), 5, loop=self.loop))
|
||||
asyncio.wait_for(client(addr), 5))
|
||||
|
||||
srv.close()
|
||||
self.loop.run_until_complete(srv.wait_closed())
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ def coro2():
|
|||
|
||||
def test_run_until_complete(self):
|
||||
t0 = self.loop.time()
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1))
|
||||
t1 = self.loop.time()
|
||||
self.assertTrue(0.08 <= t1-t0 <= 0.8, t1-t0)
|
||||
|
||||
|
|
@ -279,7 +279,7 @@ def test_run_until_complete_stopped(self):
|
|||
|
||||
async def cb():
|
||||
self.loop.stop()
|
||||
await asyncio.sleep(0.1, loop=self.loop)
|
||||
await asyncio.sleep(0.1)
|
||||
task = cb()
|
||||
self.assertRaises(RuntimeError,
|
||||
self.loop.run_until_complete, task)
|
||||
|
|
@ -1757,11 +1757,11 @@ def _run_once():
|
|||
|
||||
async def wait():
|
||||
loop = self.loop
|
||||
await asyncio.sleep(1e-2, loop=loop)
|
||||
await asyncio.sleep(1e-4, loop=loop)
|
||||
await asyncio.sleep(1e-6, loop=loop)
|
||||
await asyncio.sleep(1e-8, loop=loop)
|
||||
await asyncio.sleep(1e-10, loop=loop)
|
||||
await asyncio.sleep(1e-2)
|
||||
await asyncio.sleep(1e-4)
|
||||
await asyncio.sleep(1e-6)
|
||||
await asyncio.sleep(1e-8)
|
||||
await asyncio.sleep(1e-10)
|
||||
|
||||
self.loop.run_until_complete(wait())
|
||||
# The ideal number of call is 12, but on some platforms, the selector
|
||||
|
|
|
|||
|
|
@ -81,13 +81,13 @@ def test_lock_by_with_statement(self):
|
|||
|
||||
@asyncio.coroutine
|
||||
def test(lock):
|
||||
yield from asyncio.sleep(0.01, loop=loop)
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with (yield from lock) as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
yield from asyncio.sleep(0.01, loop=loop)
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertTrue(lock.locked())
|
||||
self.assertFalse(lock.locked())
|
||||
|
||||
|
|
@ -819,8 +819,7 @@ async def task_timeout():
|
|||
condition = asyncio.Condition(loop=loop)
|
||||
async with condition:
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(condition.wait(), timeout=0.5,
|
||||
loop=loop)
|
||||
await asyncio.wait_for(condition.wait(), timeout=0.5)
|
||||
|
||||
loop.run_until_complete(task_timeout())
|
||||
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ def test_context_manager_async_with(self):
|
|||
]
|
||||
|
||||
async def test(lock):
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
async with lock as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertTrue(lock.locked())
|
||||
self.assertFalse(lock.locked())
|
||||
|
||||
|
|
@ -74,13 +74,13 @@ def test_context_manager_with_await(self):
|
|||
]
|
||||
|
||||
async def test(lock):
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with await lock as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertTrue(lock.locked())
|
||||
self.assertFalse(lock.locked())
|
||||
|
||||
|
|
@ -198,13 +198,13 @@ async def runner():
|
|||
|
||||
def test_double_await(self):
|
||||
async def afunc():
|
||||
await asyncio.sleep(0.1, loop=self.loop)
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
async def runner():
|
||||
coro = afunc()
|
||||
t = asyncio.Task(coro, loop=self.loop)
|
||||
try:
|
||||
await asyncio.sleep(0, loop=self.loop)
|
||||
await asyncio.sleep(0)
|
||||
await coro
|
||||
finally:
|
||||
t.cancel()
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ async def add_getter():
|
|||
# Start a task that waits to get.
|
||||
asyncio.Task(q.get(), loop=loop)
|
||||
# Let it start waiting.
|
||||
await asyncio.sleep(0.1, loop=loop)
|
||||
await asyncio.sleep(0.1)
|
||||
self.assertTrue('_getters[1]' in fn(q))
|
||||
# resume q.get coroutine to finish generator
|
||||
q.put_nowait(0)
|
||||
|
|
@ -58,7 +58,7 @@ async def add_putter():
|
|||
# Start a task that waits to put.
|
||||
asyncio.Task(q.put(2), loop=loop)
|
||||
# Let it start waiting.
|
||||
await asyncio.sleep(0.1, loop=loop)
|
||||
await asyncio.sleep(0.1)
|
||||
self.assertTrue('_putters[1]' in fn(q))
|
||||
# resume q.put coroutine to finish generator
|
||||
q.get_nowait()
|
||||
|
|
@ -135,14 +135,14 @@ async def putter():
|
|||
|
||||
async def test():
|
||||
t = asyncio.Task(putter(), loop=loop)
|
||||
await asyncio.sleep(0.01, loop=loop)
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
# The putter is blocked after putting two items.
|
||||
self.assertEqual([0, 1], have_been_put)
|
||||
self.assertEqual(0, q.get_nowait())
|
||||
|
||||
# Let the putter resume and put last item.
|
||||
await asyncio.sleep(0.01, loop=loop)
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertEqual([0, 1, 2], have_been_put)
|
||||
self.assertEqual(1, q.get_nowait())
|
||||
self.assertEqual(2, q.get_nowait())
|
||||
|
|
@ -234,11 +234,11 @@ def gen():
|
|||
q = asyncio.Queue(loop=loop)
|
||||
|
||||
async def queue_get():
|
||||
return await asyncio.wait_for(q.get(), 0.051, loop=loop)
|
||||
return await asyncio.wait_for(q.get(), 0.051)
|
||||
|
||||
async def test():
|
||||
get_task = asyncio.Task(queue_get(), loop=loop)
|
||||
await asyncio.sleep(0.01, loop=loop) # let the task start
|
||||
await asyncio.sleep(0.01) # let the task start
|
||||
q.put_nowait(1)
|
||||
return await get_task
|
||||
|
||||
|
|
@ -297,7 +297,7 @@ def a_generator():
|
|||
|
||||
async def consumer(queue):
|
||||
try:
|
||||
item = await asyncio.wait_for(queue.get(), 0.1, loop=self.loop)
|
||||
item = await asyncio.wait_for(queue.get(), 0.1)
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
|
||||
|
|
@ -364,7 +364,7 @@ def gen():
|
|||
|
||||
reader = loop.create_task(q.get())
|
||||
|
||||
loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
|
||||
loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
q.put_nowait(1)
|
||||
q.put_nowait(2)
|
||||
|
|
@ -395,7 +395,7 @@ def gen():
|
|||
reader2 = loop.create_task(q.get())
|
||||
reader3 = loop.create_task(q.get())
|
||||
|
||||
loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
|
||||
loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
q.put_nowait(1)
|
||||
q.put_nowait(2)
|
||||
|
|
@ -424,7 +424,7 @@ def gen():
|
|||
|
||||
# putting a second item in the queue has to block (qsize=1)
|
||||
writer = loop.create_task(q.put(2))
|
||||
loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
|
||||
loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
value1 = q.get_nowait()
|
||||
self.assertEqual(value1, 1)
|
||||
|
|
@ -512,7 +512,7 @@ async def putter(item):
|
|||
await queue.put(item)
|
||||
|
||||
async def getter():
|
||||
await asyncio.sleep(0, loop=self.loop)
|
||||
await asyncio.sleep(0)
|
||||
num = queue.qsize()
|
||||
for _ in range(num):
|
||||
item = queue.get_nowait()
|
||||
|
|
@ -537,7 +537,7 @@ def a_generator():
|
|||
|
||||
# Task waiting for space to put an item in the queue.
|
||||
put_task = loop.create_task(queue.put(1))
|
||||
loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
|
||||
loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
# Check that the putter is correctly removed from queue._putters when
|
||||
# the task is canceled.
|
||||
|
|
@ -560,7 +560,7 @@ def gen():
|
|||
|
||||
# Task waiting for space to put a item in the queue.
|
||||
put_task = loop.create_task(queue.put(1))
|
||||
loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
|
||||
loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
# get_nowait() remove the future of put_task from queue._putters.
|
||||
queue.get_nowait()
|
||||
|
|
@ -638,7 +638,7 @@ async def test():
|
|||
running = False
|
||||
for i in range(len(tasks)):
|
||||
q.put_nowait(0)
|
||||
self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.wait(tasks))
|
||||
|
||||
def test_join_empty_queue(self):
|
||||
q = self.q_class(loop=self.loop)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ def test_sock_recv(self):
|
|||
self.loop._sock_recv = mock.Mock()
|
||||
|
||||
f = self.loop.create_task(self.loop.sock_recv(sock, 1024))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
self.assertEqual(self.loop._sock_recv.call_args[0][1:],
|
||||
(None, sock, 1024))
|
||||
|
|
@ -215,7 +215,7 @@ def test_sock_recv_reconnection(self):
|
|||
fut = self.loop.create_task(
|
||||
self.loop.sock_recv(sock, 1024))
|
||||
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
callback = self.loop.add_reader.call_args[0][1]
|
||||
params = self.loop.add_reader.call_args[0][2:]
|
||||
|
|
@ -226,7 +226,7 @@ def test_sock_recv_reconnection(self):
|
|||
sock.recv.side_effect = OSError(9)
|
||||
callback(*params)
|
||||
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
self.assertIsInstance(fut.exception(), OSError)
|
||||
self.assertEqual((10,), self.loop.remove_reader.call_args[0])
|
||||
|
|
@ -278,7 +278,7 @@ def test_sock_sendall(self):
|
|||
f = self.loop.create_task(
|
||||
self.loop.sock_sendall(sock, b'data'))
|
||||
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
self.assertEqual(
|
||||
(None, sock, b'data'),
|
||||
|
|
@ -293,7 +293,7 @@ def test_sock_sendall_nodata(self):
|
|||
self.loop._sock_sendall = mock.Mock()
|
||||
|
||||
f = self.loop.create_task(self.loop.sock_sendall(sock, b''))
|
||||
self.loop.run_until_complete(asyncio.sleep(0, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0))
|
||||
|
||||
self.assertTrue(f.done())
|
||||
self.assertIsNone(f.result())
|
||||
|
|
@ -309,7 +309,7 @@ def test_sock_sendall_reconnection(self):
|
|||
self.loop.remove_writer = mock.Mock()
|
||||
fut = self.loop.create_task(self.loop.sock_sendall(sock, b'data'))
|
||||
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
callback = self.loop.add_writer.call_args[0][1]
|
||||
params = self.loop.add_writer.call_args[0][2:]
|
||||
|
|
@ -320,7 +320,7 @@ def test_sock_sendall_reconnection(self):
|
|||
sock.send.side_effect = OSError(9)
|
||||
callback(*params)
|
||||
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
self.assertIsInstance(fut.exception(), OSError)
|
||||
self.assertEqual((10,), self.loop.remove_writer.call_args[0])
|
||||
|
|
@ -531,7 +531,7 @@ def test_sock_accept(self):
|
|||
self.loop._sock_accept = mock.Mock()
|
||||
|
||||
f = self.loop.create_task(self.loop.sock_accept(sock))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01))
|
||||
|
||||
self.assertFalse(self.loop._sock_accept.call_args[0][1])
|
||||
self.assertIs(self.loop._sock_accept.call_args[0][2], sock)
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ def eof_received(self):
|
|||
self.on_eof.set_result(True)
|
||||
|
||||
async def client(addr):
|
||||
await asyncio.sleep(0.5, loop=self.loop)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
on_data = self.loop.create_future()
|
||||
on_eof = self.loop.create_future()
|
||||
|
|
@ -271,7 +271,7 @@ async def client(addr):
|
|||
|
||||
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
|
||||
self.loop.run_until_complete(
|
||||
asyncio.wait_for(client(srv.addr), loop=self.loop, timeout=10))
|
||||
asyncio.wait_for(client(srv.addr), timeout=10))
|
||||
|
||||
def test_start_tls_client_buf_proto_1(self):
|
||||
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
|
||||
|
|
@ -332,7 +332,7 @@ def eof_received(self):
|
|||
self.on_eof.set_result(True)
|
||||
|
||||
async def client(addr):
|
||||
await asyncio.sleep(0.5, loop=self.loop)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
on_data1 = self.loop.create_future()
|
||||
on_data2 = self.loop.create_future()
|
||||
|
|
@ -362,7 +362,7 @@ async def client(addr):
|
|||
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
|
||||
self.loop.run_until_complete(
|
||||
asyncio.wait_for(client(srv.addr),
|
||||
loop=self.loop, timeout=self.TIMEOUT))
|
||||
timeout=self.TIMEOUT))
|
||||
|
||||
def test_start_tls_slow_client_cancel(self):
|
||||
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
|
||||
|
|
@ -403,7 +403,7 @@ def eof_received(self):
|
|||
self.on_eof.set_result(True)
|
||||
|
||||
async def client(addr):
|
||||
await asyncio.sleep(0.5, loop=self.loop)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
on_data = self.loop.create_future()
|
||||
on_eof = self.loop.create_future()
|
||||
|
|
@ -418,12 +418,11 @@ async def client(addr):
|
|||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(
|
||||
self.loop.start_tls(tr, proto, client_context),
|
||||
0.5,
|
||||
loop=self.loop)
|
||||
0.5)
|
||||
|
||||
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
|
||||
self.loop.run_until_complete(
|
||||
asyncio.wait_for(client(srv.addr), loop=self.loop, timeout=10))
|
||||
asyncio.wait_for(client(srv.addr), timeout=10))
|
||||
|
||||
def test_start_tls_server_1(self):
|
||||
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
|
||||
|
|
@ -496,7 +495,7 @@ async def run_main():
|
|||
timeout=self.TIMEOUT):
|
||||
await asyncio.wait_for(
|
||||
main(proto, on_con, on_eof, on_con_lost),
|
||||
loop=self.loop, timeout=self.TIMEOUT)
|
||||
timeout=self.TIMEOUT)
|
||||
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
|
|
@ -541,8 +540,7 @@ async def client(addr):
|
|||
ssl=client_sslctx,
|
||||
server_hostname='',
|
||||
ssl_handshake_timeout=10.0),
|
||||
0.5,
|
||||
loop=self.loop)
|
||||
0.5)
|
||||
|
||||
with self.tcp_server(server,
|
||||
max_clients=1,
|
||||
|
|
|
|||
|
|
@ -560,7 +560,7 @@ def set_err():
|
|||
t1 = asyncio.Task(stream.readline(), loop=self.loop)
|
||||
t2 = asyncio.Task(set_err(), loop=self.loop)
|
||||
|
||||
self.loop.run_until_complete(asyncio.wait([t1, t2], loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.wait([t1, t2]))
|
||||
|
||||
self.assertRaises(ValueError, t1.result)
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ async def run(data):
|
|||
return (exitcode, data)
|
||||
|
||||
task = run(b'some data')
|
||||
task = asyncio.wait_for(task, 60.0, loop=self.loop)
|
||||
task = asyncio.wait_for(task, 60.0)
|
||||
exitcode, stdout = self.loop.run_until_complete(task)
|
||||
self.assertEqual(exitcode, 0)
|
||||
self.assertEqual(stdout, b'some data')
|
||||
|
|
@ -144,7 +144,7 @@ async def run(data):
|
|||
return proc.returncode, stdout
|
||||
|
||||
task = run(b'some data')
|
||||
task = asyncio.wait_for(task, 60.0, loop=self.loop)
|
||||
task = asyncio.wait_for(task, 60.0)
|
||||
exitcode, stdout = self.loop.run_until_complete(task)
|
||||
self.assertEqual(exitcode, 0)
|
||||
self.assertEqual(stdout, b'some data')
|
||||
|
|
@ -233,7 +233,7 @@ def test_stdin_broken_pipe(self):
|
|||
proc, large_data = self.prepare_broken_pipe_test()
|
||||
|
||||
async def write_stdin(proc, data):
|
||||
await asyncio.sleep(0.5, loop=self.loop)
|
||||
await asyncio.sleep(0.5)
|
||||
proc.stdin.write(data)
|
||||
await proc.stdin.drain()
|
||||
|
||||
|
|
@ -504,7 +504,7 @@ async def execute():
|
|||
while True:
|
||||
data = await process.stdout.read(65536)
|
||||
if data:
|
||||
await asyncio.sleep(0.3, loop=self.loop)
|
||||
await asyncio.sleep(0.3)
|
||||
else:
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ def set_coroutine_debug(enabled):
|
|||
coroutines._DEBUG = old_debug
|
||||
|
||||
|
||||
|
||||
def format_coroutine(qualname, state, src, source_traceback, generator=False):
|
||||
if generator:
|
||||
state = '%s' % state
|
||||
|
|
@ -472,7 +471,7 @@ def gen():
|
|||
loop = self.new_test_loop(gen)
|
||||
|
||||
async def task():
|
||||
await asyncio.sleep(10.0, loop=loop)
|
||||
await asyncio.sleep(10.0)
|
||||
return 12
|
||||
|
||||
t = self.new_task(loop, task())
|
||||
|
|
@ -595,7 +594,7 @@ async def task():
|
|||
t.cancel()
|
||||
self.assertTrue(t._must_cancel) # White-box test.
|
||||
# The sleep should be cancelled immediately.
|
||||
await asyncio.sleep(100, loop=loop)
|
||||
await asyncio.sleep(100)
|
||||
return 12
|
||||
|
||||
t = self.new_task(loop, task())
|
||||
|
|
@ -641,7 +640,7 @@ def gen():
|
|||
async def task():
|
||||
nonlocal x
|
||||
while x < 10:
|
||||
await asyncio.sleep(0.1, loop=loop)
|
||||
await asyncio.sleep(0.1)
|
||||
x += 1
|
||||
if x == 2:
|
||||
loop.stop()
|
||||
|
|
@ -677,7 +676,7 @@ def gen():
|
|||
fut = self.new_future(loop)
|
||||
fut.set_result('done')
|
||||
|
||||
ret = loop.run_until_complete(asyncio.wait_for(fut, 0, loop=loop))
|
||||
ret = loop.run_until_complete(asyncio.wait_for(fut, 0))
|
||||
|
||||
self.assertEqual(ret, 'done')
|
||||
self.assertTrue(fut.done())
|
||||
|
|
@ -698,7 +697,7 @@ def foo():
|
|||
foo_started = True
|
||||
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
loop.run_until_complete(asyncio.wait_for(foo(), 0, loop=loop))
|
||||
loop.run_until_complete(asyncio.wait_for(foo(), 0))
|
||||
|
||||
self.assertAlmostEqual(0, loop.time())
|
||||
self.assertEqual(foo_started, False)
|
||||
|
|
@ -720,7 +719,7 @@ async def foo():
|
|||
nonlocal foo_running
|
||||
foo_running = True
|
||||
try:
|
||||
await asyncio.sleep(0.2, loop=loop)
|
||||
await asyncio.sleep(0.2)
|
||||
finally:
|
||||
foo_running = False
|
||||
return 'done'
|
||||
|
|
@ -728,8 +727,7 @@ async def foo():
|
|||
fut = self.new_task(loop, foo())
|
||||
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
loop.run_until_complete(asyncio.wait_for(
|
||||
fut, timeout, loop=loop))
|
||||
loop.run_until_complete(asyncio.wait_for(fut, timeout))
|
||||
self.assertTrue(fut.done())
|
||||
# it should have been cancelled due to the timeout
|
||||
self.assertTrue(fut.cancelled())
|
||||
|
|
@ -753,7 +751,7 @@ async def foo():
|
|||
nonlocal foo_running
|
||||
foo_running = True
|
||||
try:
|
||||
await asyncio.sleep(0.2, loop=loop)
|
||||
await asyncio.sleep(0.2)
|
||||
finally:
|
||||
foo_running = False
|
||||
return 'done'
|
||||
|
|
@ -761,7 +759,7 @@ async def foo():
|
|||
fut = self.new_task(loop, foo())
|
||||
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
loop.run_until_complete(asyncio.wait_for(fut, 0.1, loop=loop))
|
||||
loop.run_until_complete(asyncio.wait_for(fut, 0.1))
|
||||
self.assertTrue(fut.done())
|
||||
# it should have been cancelled due to the timeout
|
||||
self.assertTrue(fut.cancelled())
|
||||
|
|
@ -775,9 +773,7 @@ def test_wait_for_blocking(self):
|
|||
def coro():
|
||||
return 'done'
|
||||
|
||||
res = loop.run_until_complete(asyncio.wait_for(coro(),
|
||||
timeout=None,
|
||||
loop=loop))
|
||||
res = loop.run_until_complete(asyncio.wait_for(coro(), timeout=None))
|
||||
self.assertEqual(res, 'done')
|
||||
|
||||
def test_wait_for_with_global_loop(self):
|
||||
|
|
@ -792,7 +788,7 @@ def gen():
|
|||
loop = self.new_test_loop(gen)
|
||||
|
||||
async def foo():
|
||||
await asyncio.sleep(0.2, loop=loop)
|
||||
await asyncio.sleep(0.2)
|
||||
return 'done'
|
||||
|
||||
asyncio.set_event_loop(loop)
|
||||
|
|
@ -817,7 +813,7 @@ def gen():
|
|||
loop = self.new_test_loop(gen)
|
||||
|
||||
fut = self.new_future(loop)
|
||||
task = asyncio.wait_for(fut, timeout=0.2, loop=loop)
|
||||
task = asyncio.wait_for(fut, timeout=0.2)
|
||||
loop.call_later(0.1, fut.set_result, "ok")
|
||||
res = loop.run_until_complete(task)
|
||||
self.assertEqual(res, "ok")
|
||||
|
|
@ -832,14 +828,14 @@ async def foo():
|
|||
async def inner():
|
||||
nonlocal task_done
|
||||
try:
|
||||
await asyncio.sleep(0.2, loop=loop)
|
||||
await asyncio.sleep(0.2)
|
||||
finally:
|
||||
task_done = True
|
||||
|
||||
inner_task = self.new_task(loop, inner())
|
||||
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(inner_task, timeout=0.1, loop=loop)
|
||||
await asyncio.wait_for(inner_task, timeout=0.1)
|
||||
|
||||
self.assertTrue(task_done)
|
||||
|
||||
|
|
@ -852,23 +848,23 @@ def test_wait_for_self_cancellation(self):
|
|||
async def foo():
|
||||
async def inner():
|
||||
try:
|
||||
await asyncio.sleep(0.3, loop=loop)
|
||||
await asyncio.sleep(0.3)
|
||||
except asyncio.CancelledError:
|
||||
try:
|
||||
await asyncio.sleep(0.3, loop=loop)
|
||||
await asyncio.sleep(0.3)
|
||||
except asyncio.CancelledError:
|
||||
await asyncio.sleep(0.3, loop=loop)
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
return 42
|
||||
|
||||
inner_task = self.new_task(loop, inner())
|
||||
|
||||
wait = asyncio.wait_for(inner_task, timeout=0.1, loop=loop)
|
||||
wait = asyncio.wait_for(inner_task, timeout=0.1)
|
||||
|
||||
# Test that wait_for itself is properly cancellable
|
||||
# even when the initial task holds up the initial cancellation.
|
||||
task = self.new_task(loop, wait)
|
||||
await asyncio.sleep(0.2, loop=loop)
|
||||
await asyncio.sleep(0.2)
|
||||
task.cancel()
|
||||
|
||||
with self.assertRaises(asyncio.CancelledError):
|
||||
|
|
@ -889,11 +885,11 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop))
|
||||
b = self.new_task(loop, asyncio.sleep(0.15, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(0.1))
|
||||
b = self.new_task(loop, asyncio.sleep(0.15))
|
||||
|
||||
async def foo():
|
||||
done, pending = await asyncio.wait([b, a], loop=loop)
|
||||
done, pending = await asyncio.wait([b, a])
|
||||
self.assertEqual(done, set([a, b]))
|
||||
self.assertEqual(pending, set())
|
||||
return 42
|
||||
|
|
@ -918,8 +914,8 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = self.new_task(loop, asyncio.sleep(0.01, loop=loop))
|
||||
b = self.new_task(loop, asyncio.sleep(0.015, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(0.01))
|
||||
b = self.new_task(loop, asyncio.sleep(0.015))
|
||||
|
||||
async def foo():
|
||||
done, pending = await asyncio.wait([b, a])
|
||||
|
|
@ -942,7 +938,7 @@ def coro(s):
|
|||
|
||||
task =self.new_task(
|
||||
self.loop,
|
||||
asyncio.wait([c, c, coro('spam')], loop=self.loop))
|
||||
asyncio.wait([c, c, coro('spam')]))
|
||||
|
||||
done, pending = self.loop.run_until_complete(task)
|
||||
|
||||
|
|
@ -952,11 +948,11 @@ def coro(s):
|
|||
def test_wait_errors(self):
|
||||
self.assertRaises(
|
||||
ValueError, self.loop.run_until_complete,
|
||||
asyncio.wait(set(), loop=self.loop))
|
||||
asyncio.wait(set()))
|
||||
|
||||
# -1 is an invalid return_when value
|
||||
sleep_coro = asyncio.sleep(10.0, loop=self.loop)
|
||||
wait_coro = asyncio.wait([sleep_coro], return_when=-1, loop=self.loop)
|
||||
sleep_coro = asyncio.sleep(10.0)
|
||||
wait_coro = asyncio.wait([sleep_coro], return_when=-1)
|
||||
self.assertRaises(ValueError,
|
||||
self.loop.run_until_complete, wait_coro)
|
||||
|
||||
|
|
@ -973,12 +969,11 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = self.new_task(loop, asyncio.sleep(10.0, loop=loop))
|
||||
b = self.new_task(loop, asyncio.sleep(0.1, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(10.0))
|
||||
b = self.new_task(loop, asyncio.sleep(0.1))
|
||||
task = self.new_task(
|
||||
loop,
|
||||
asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED,
|
||||
loop=loop))
|
||||
asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
|
||||
|
||||
done, pending = loop.run_until_complete(task)
|
||||
self.assertEqual({b}, done)
|
||||
|
|
@ -990,7 +985,7 @@ def gen():
|
|||
|
||||
# move forward to close generator
|
||||
loop.advance_time(10)
|
||||
loop.run_until_complete(asyncio.wait([a, b], loop=loop))
|
||||
loop.run_until_complete(asyncio.wait([a, b]))
|
||||
|
||||
def test_wait_really_done(self):
|
||||
# there is possibility that some tasks in the pending list
|
||||
|
|
@ -1009,8 +1004,7 @@ def coro2():
|
|||
b = self.new_task(self.loop, coro2())
|
||||
task = self.new_task(
|
||||
self.loop,
|
||||
asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED,
|
||||
loop=self.loop))
|
||||
asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
|
||||
|
||||
done, pending = self.loop.run_until_complete(task)
|
||||
self.assertEqual({a, b}, done)
|
||||
|
|
@ -1029,7 +1023,7 @@ def gen():
|
|||
loop = self.new_test_loop(gen)
|
||||
|
||||
# first_exception, task already has exception
|
||||
a = self.new_task(loop, asyncio.sleep(10.0, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(10.0))
|
||||
|
||||
@asyncio.coroutine
|
||||
def exc():
|
||||
|
|
@ -1038,8 +1032,7 @@ def exc():
|
|||
b = self.new_task(loop, exc())
|
||||
task = self.new_task(
|
||||
loop,
|
||||
asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION,
|
||||
loop=loop))
|
||||
asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION))
|
||||
|
||||
done, pending = loop.run_until_complete(task)
|
||||
self.assertEqual({b}, done)
|
||||
|
|
@ -1048,7 +1041,7 @@ def exc():
|
|||
|
||||
# move forward to close generator
|
||||
loop.advance_time(10)
|
||||
loop.run_until_complete(asyncio.wait([a, b], loop=loop))
|
||||
loop.run_until_complete(asyncio.wait([a, b]))
|
||||
|
||||
def test_wait_first_exception_in_wait(self):
|
||||
|
||||
|
|
@ -1062,15 +1055,14 @@ def gen():
|
|||
loop = self.new_test_loop(gen)
|
||||
|
||||
# first_exception, exception during waiting
|
||||
a = self.new_task(loop, asyncio.sleep(10.0, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(10.0))
|
||||
|
||||
async def exc():
|
||||
await asyncio.sleep(0.01, loop=loop)
|
||||
await asyncio.sleep(0.01)
|
||||
raise ZeroDivisionError('err')
|
||||
|
||||
b = self.new_task(loop, exc())
|
||||
task = asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION,
|
||||
loop=loop)
|
||||
task = asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION)
|
||||
|
||||
done, pending = loop.run_until_complete(task)
|
||||
self.assertEqual({b}, done)
|
||||
|
|
@ -1079,7 +1071,7 @@ async def exc():
|
|||
|
||||
# move forward to close generator
|
||||
loop.advance_time(10)
|
||||
loop.run_until_complete(asyncio.wait([a, b], loop=loop))
|
||||
loop.run_until_complete(asyncio.wait([a, b]))
|
||||
|
||||
def test_wait_with_exception(self):
|
||||
|
||||
|
|
@ -1092,17 +1084,17 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(0.1))
|
||||
|
||||
@asyncio.coroutine
|
||||
def sleeper():
|
||||
yield from asyncio.sleep(0.15, loop=loop)
|
||||
yield from asyncio.sleep(0.15)
|
||||
raise ZeroDivisionError('really')
|
||||
|
||||
b = self.new_task(loop, sleeper())
|
||||
|
||||
async def foo():
|
||||
done, pending = await asyncio.wait([b, a], loop=loop)
|
||||
done, pending = await asyncio.wait([b, a])
|
||||
self.assertEqual(len(done), 2)
|
||||
self.assertEqual(pending, set())
|
||||
errors = set(f for f in done if f.exception() is not None)
|
||||
|
|
@ -1127,12 +1119,11 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop))
|
||||
b = self.new_task(loop, asyncio.sleep(0.15, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(0.1))
|
||||
b = self.new_task(loop, asyncio.sleep(0.15))
|
||||
|
||||
async def foo():
|
||||
done, pending = await asyncio.wait([b, a], timeout=0.11,
|
||||
loop=loop)
|
||||
done, pending = await asyncio.wait([b, a], timeout=0.11)
|
||||
self.assertEqual(done, set([a]))
|
||||
self.assertEqual(pending, set([b]))
|
||||
|
||||
|
|
@ -1141,7 +1132,7 @@ async def foo():
|
|||
|
||||
# move forward to close generator
|
||||
loop.advance_time(10)
|
||||
loop.run_until_complete(asyncio.wait([a, b], loop=loop))
|
||||
loop.run_until_complete(asyncio.wait([a, b]))
|
||||
|
||||
def test_wait_concurrent_complete(self):
|
||||
|
||||
|
|
@ -1156,11 +1147,11 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop))
|
||||
b = self.new_task(loop, asyncio.sleep(0.15, loop=loop))
|
||||
a = self.new_task(loop, asyncio.sleep(0.1))
|
||||
b = self.new_task(loop, asyncio.sleep(0.15))
|
||||
|
||||
done, pending = loop.run_until_complete(
|
||||
asyncio.wait([b, a], timeout=0.1, loop=loop))
|
||||
asyncio.wait([b, a], timeout=0.1))
|
||||
|
||||
self.assertEqual(done, set([a]))
|
||||
self.assertEqual(pending, set([b]))
|
||||
|
|
@ -1168,7 +1159,7 @@ def gen():
|
|||
|
||||
# move forward to close generator
|
||||
loop.advance_time(10)
|
||||
loop.run_until_complete(asyncio.wait([a, b], loop=loop))
|
||||
loop.run_until_complete(asyncio.wait([a, b]))
|
||||
|
||||
def test_as_completed(self):
|
||||
|
||||
|
|
@ -1187,7 +1178,7 @@ def gen():
|
|||
@asyncio.coroutine
|
||||
def sleeper(dt, x):
|
||||
nonlocal time_shifted
|
||||
yield from asyncio.sleep(dt, loop=loop)
|
||||
yield from asyncio.sleep(dt)
|
||||
completed.add(x)
|
||||
if not time_shifted and 'a' in completed and 'b' in completed:
|
||||
time_shifted = True
|
||||
|
|
@ -1225,8 +1216,8 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = loop.create_task(asyncio.sleep(0.1, 'a', loop=loop))
|
||||
b = loop.create_task(asyncio.sleep(0.15, 'b', loop=loop))
|
||||
a = loop.create_task(asyncio.sleep(0.1, 'a'))
|
||||
b = loop.create_task(asyncio.sleep(0.15, 'b'))
|
||||
|
||||
async def foo():
|
||||
values = []
|
||||
|
|
@ -1249,7 +1240,7 @@ async def foo():
|
|||
|
||||
# move forward to close generator
|
||||
loop.advance_time(10)
|
||||
loop.run_until_complete(asyncio.wait([a, b], loop=loop))
|
||||
loop.run_until_complete(asyncio.wait([a, b]))
|
||||
|
||||
def test_as_completed_with_unused_timeout(self):
|
||||
|
||||
|
|
@ -1260,7 +1251,7 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = asyncio.sleep(0.01, 'a', loop=loop)
|
||||
a = asyncio.sleep(0.01, 'a')
|
||||
|
||||
async def foo():
|
||||
for f in asyncio.as_completed([a], timeout=1, loop=loop):
|
||||
|
|
@ -1278,8 +1269,8 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = asyncio.sleep(0.05, 'a', loop=loop)
|
||||
b = asyncio.sleep(0.10, 'b', loop=loop)
|
||||
a = asyncio.sleep(0.05, 'a')
|
||||
b = asyncio.sleep(0.10, 'b')
|
||||
fs = {a, b}
|
||||
futs = list(asyncio.as_completed(fs, loop=loop))
|
||||
self.assertEqual(len(futs), 2)
|
||||
|
|
@ -1303,12 +1294,12 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
a = asyncio.sleep(0.05, 'a', loop=loop)
|
||||
b = asyncio.sleep(0.05, 'b', loop=loop)
|
||||
a = asyncio.sleep(0.05, 'a')
|
||||
b = asyncio.sleep(0.05, 'b')
|
||||
fs = {a, b}
|
||||
futs = list(asyncio.as_completed(fs, loop=loop))
|
||||
self.assertEqual(len(futs), 2)
|
||||
waiter = asyncio.wait(futs, loop=loop)
|
||||
waiter = asyncio.wait(futs)
|
||||
done, pending = loop.run_until_complete(waiter)
|
||||
self.assertEqual(set(f.result() for f in done), {'a', 'b'})
|
||||
|
||||
|
|
@ -1346,8 +1337,8 @@ def gen():
|
|||
|
||||
@asyncio.coroutine
|
||||
def sleeper(dt, arg):
|
||||
yield from asyncio.sleep(dt/2, loop=loop)
|
||||
res = yield from asyncio.sleep(dt/2, arg, loop=loop)
|
||||
yield from asyncio.sleep(dt/2)
|
||||
res = yield from asyncio.sleep(dt/2, arg)
|
||||
return res
|
||||
|
||||
t = self.new_task(loop, sleeper(0.1, 'yeah'))
|
||||
|
|
@ -1365,7 +1356,7 @@ def gen():
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
t = self.new_task(loop, asyncio.sleep(10.0, 'yeah', loop=loop))
|
||||
t = self.new_task(loop, asyncio.sleep(10.0, 'yeah'))
|
||||
|
||||
handle = None
|
||||
orig_call_later = loop.call_later
|
||||
|
|
@ -1397,7 +1388,7 @@ def gen():
|
|||
|
||||
@asyncio.coroutine
|
||||
def sleep(dt):
|
||||
yield from asyncio.sleep(dt, loop=loop)
|
||||
yield from asyncio.sleep(dt)
|
||||
|
||||
@asyncio.coroutine
|
||||
def doit():
|
||||
|
|
@ -1502,7 +1493,7 @@ def gen():
|
|||
|
||||
@asyncio.coroutine
|
||||
def sleeper():
|
||||
yield from asyncio.sleep(10, loop=loop)
|
||||
yield from asyncio.sleep(10)
|
||||
|
||||
base_exc = BaseException()
|
||||
|
||||
|
|
@ -1663,8 +1654,7 @@ async def coro2(loop):
|
|||
task1 = self.new_task(self.loop, coro1(self.loop))
|
||||
task2 = self.new_task(self.loop, coro2(self.loop))
|
||||
|
||||
self.loop.run_until_complete(asyncio.wait((task1, task2),
|
||||
loop=self.loop))
|
||||
self.loop.run_until_complete(asyncio.wait((task1, task2)))
|
||||
self.assertIsNone(asyncio.current_task(loop=self.loop))
|
||||
|
||||
# Some thorough tests for cancellation propagation through
|
||||
|
|
@ -1714,7 +1704,7 @@ async def inner():
|
|||
|
||||
async def outer():
|
||||
nonlocal proof
|
||||
d, p = await asyncio.wait([inner()], loop=self.loop)
|
||||
d, p = await asyncio.wait([inner()])
|
||||
proof += 100
|
||||
|
||||
f = asyncio.ensure_future(outer(), loop=self.loop)
|
||||
|
|
@ -1827,15 +1817,15 @@ def test_wait_invalid_args(self):
|
|||
|
||||
# wait() expects a list of futures, not a future instance
|
||||
self.assertRaises(TypeError, self.loop.run_until_complete,
|
||||
asyncio.wait(fut, loop=self.loop))
|
||||
asyncio.wait(fut))
|
||||
coro = coroutine_function()
|
||||
self.assertRaises(TypeError, self.loop.run_until_complete,
|
||||
asyncio.wait(coro, loop=self.loop))
|
||||
asyncio.wait(coro))
|
||||
coro.close()
|
||||
|
||||
# wait() expects at least a future
|
||||
self.assertRaises(ValueError, self.loop.run_until_complete,
|
||||
asyncio.wait([], loop=self.loop))
|
||||
asyncio.wait([]))
|
||||
|
||||
def test_corowrapper_mocks_generator(self):
|
||||
|
||||
|
|
@ -2027,7 +2017,7 @@ def coro():
|
|||
@asyncio.coroutine
|
||||
def runner():
|
||||
task = self.new_task(loop, coro())
|
||||
yield from asyncio.sleep(0.05, loop=loop)
|
||||
yield from asyncio.sleep(0.05)
|
||||
task.cancel()
|
||||
task = None
|
||||
|
||||
|
|
@ -2111,7 +2101,7 @@ def blocking_coroutine():
|
|||
|
||||
task = loop.create_task(blocking_coroutine())
|
||||
|
||||
wait = loop.create_task(asyncio.wait_for(task, timeout, loop=loop))
|
||||
wait = loop.create_task(asyncio.wait_for(task, timeout))
|
||||
loop.call_soon(wait.cancel)
|
||||
|
||||
self.assertRaises(asyncio.CancelledError,
|
||||
|
|
@ -2164,7 +2154,7 @@ async def test():
|
|||
time = 0
|
||||
while True:
|
||||
time += 0.05
|
||||
await asyncio.gather(asyncio.sleep(0.05, loop=loop),
|
||||
await asyncio.gather(asyncio.sleep(0.05),
|
||||
return_exceptions=True,
|
||||
loop=loop)
|
||||
if time > 1:
|
||||
|
|
@ -2172,7 +2162,7 @@ async def test():
|
|||
|
||||
async def main():
|
||||
qwe = self.new_task(loop, test())
|
||||
await asyncio.sleep(0.2, loop=loop)
|
||||
await asyncio.sleep(0.2)
|
||||
qwe.cancel()
|
||||
try:
|
||||
await qwe
|
||||
|
|
@ -2305,7 +2295,7 @@ def test_context_1(self):
|
|||
cvar = contextvars.ContextVar('cvar', default='nope')
|
||||
|
||||
async def sub():
|
||||
await asyncio.sleep(0.01, loop=loop)
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertEqual(cvar.get(), 'nope')
|
||||
cvar.set('something else')
|
||||
|
||||
|
|
@ -2346,7 +2336,7 @@ def fut_on_done(fut):
|
|||
for i in range(3):
|
||||
# Test that task passed its context to add_done_callback:
|
||||
cvar.set(f'yes{i}-{j}')
|
||||
await asyncio.sleep(0.001, loop=loop)
|
||||
await asyncio.sleep(0.001)
|
||||
self.assertEqual(cvar.get(), f'yes{i}-{j}')
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
|
|
@ -2366,8 +2356,7 @@ def test_context_3(self):
|
|||
async def sub(num):
|
||||
for i in range(10):
|
||||
cvar.set(num + i)
|
||||
await asyncio.sleep(
|
||||
random.uniform(0.001, 0.05), loop=loop)
|
||||
await asyncio.sleep(random.uniform(0.001, 0.05))
|
||||
self.assertEqual(cvar.get(), num + i)
|
||||
|
||||
async def main():
|
||||
|
|
@ -2452,7 +2441,7 @@ def test_set_result_causes_invalid_state(self):
|
|||
self.loop.call_exception_handler = exc_handler = mock.Mock()
|
||||
|
||||
async def foo():
|
||||
await asyncio.sleep(0.1, loop=self.loop)
|
||||
await asyncio.sleep(0.1)
|
||||
return 10
|
||||
|
||||
coro = foo()
|
||||
|
|
@ -2479,7 +2468,7 @@ class MyExc(Exception):
|
|||
self.loop.call_exception_handler = exc_handler = mock.Mock()
|
||||
|
||||
async def foo():
|
||||
await asyncio.sleep(0.1, loop=self.loop)
|
||||
await asyncio.sleep(0.1)
|
||||
return 10
|
||||
|
||||
coro = foo()
|
||||
|
|
@ -3103,7 +3092,7 @@ def setUp(self):
|
|||
@asyncio.coroutine
|
||||
def add(self, a, b, fail=False, cancel=False):
|
||||
"""Wait 0.05 second and return a + b."""
|
||||
yield from asyncio.sleep(0.05, loop=self.loop)
|
||||
yield from asyncio.sleep(0.05)
|
||||
if fail:
|
||||
raise RuntimeError("Fail!")
|
||||
if cancel:
|
||||
|
|
@ -3213,7 +3202,7 @@ def inc_result(num):
|
|||
def coro():
|
||||
self.loop.call_soon(inc_result, 1)
|
||||
self.assertEqual(result, 0)
|
||||
num = yield from asyncio.sleep(0, loop=self.loop, result=10)
|
||||
num = yield from asyncio.sleep(0, result=10)
|
||||
self.assertEqual(result, 1) # inc'ed by call_soon
|
||||
inc_result(num) # num should be 11
|
||||
|
||||
|
|
@ -3221,7 +3210,7 @@ def coro():
|
|||
self.assertEqual(result, 11)
|
||||
|
||||
def test_loop_argument_is_deprecated(self):
|
||||
# Remove test when loop argument is removed in Python 4.0
|
||||
# Remove test when loop argument is removed in Python 3.10
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
|
||||
|
||||
|
|
@ -3238,13 +3227,13 @@ def tearDown(self):
|
|||
super().tearDown()
|
||||
|
||||
def test_loop_argument_is_deprecated_in_wait(self):
|
||||
# Remove test when loop argument is removed in Python 4.0
|
||||
# Remove test when loop argument is removed in Python 3.10
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.loop.run_until_complete(
|
||||
asyncio.wait([coroutine_function()], loop=self.loop))
|
||||
|
||||
def test_loop_argument_is_deprecated_in_wait_for(self):
|
||||
# Remove test when loop argument is removed in Python 4.0
|
||||
# Remove test when loop argument is removed in Python 3.10
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.loop.run_until_complete(
|
||||
asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop))
|
||||
|
|
@ -3268,7 +3257,7 @@ def test_yield_from_awaitable(self):
|
|||
|
||||
@asyncio.coroutine
|
||||
def coro():
|
||||
yield from asyncio.sleep(0, loop=self.loop)
|
||||
yield from asyncio.sleep(0)
|
||||
return 'ok'
|
||||
|
||||
result = self.loop.run_until_complete(coro())
|
||||
|
|
@ -3282,7 +3271,7 @@ def coro1():
|
|||
|
||||
@asyncio.coroutine
|
||||
def coro2():
|
||||
yield from asyncio.sleep(0, loop=self.loop)
|
||||
yield from asyncio.sleep(0)
|
||||
return 'ok2'
|
||||
|
||||
async def inner():
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ def run_until(loop, pred, timeout=30):
|
|||
timeout = deadline - time.time()
|
||||
if timeout <= 0:
|
||||
raise futures.TimeoutError()
|
||||
loop.run_until_complete(tasks.sleep(0.001, loop=loop))
|
||||
loop.run_until_complete(tasks.sleep(0.001))
|
||||
|
||||
|
||||
def run_once(loop):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue