Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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()))
Expand All @@ -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():
Expand Down Expand Up @@ -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():
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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():
Expand All @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand All @@ -831,22 +831,22 @@ 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

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():
Expand Down Expand Up @@ -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():
Expand All @@ -921,25 +921,25 @@ 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

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():
Expand Down Expand Up @@ -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():
Expand All @@ -1051,15 +1051,15 @@ 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)

# 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
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_buffered_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ 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)

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)
Expand Down Expand Up @@ -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
Expand Down
Loading