Skip to content

Commit

Permalink
Convert all tests to async/await syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jul 28, 2018
1 parent 0da84c9 commit 8dfcd30
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions tests/test_mixed.py
Expand Up @@ -64,16 +64,15 @@ def threaded():
for i in range(5):
q.sync_q.put(i)

@asyncio.coroutine
def go():
async def go():
f = self.loop.run_in_executor(None, threaded)
for i in range(5):
val = yield from q.async_q.get()
val = await q.async_q.get()
self.assertEqual(val, i)

self.assertTrue(q.async_q.empty())

yield from f
await f

for i in range(3):
self.loop.run_until_complete(go())
Expand All @@ -84,18 +83,16 @@ def test_sync_put_async_join(self):
for i in range(5):
q.sync_q.put(i)

@asyncio.coroutine
def do_work():
yield from asyncio.sleep(1, loop=self.loop)
async def do_work():
await asyncio.sleep(1)
while True:
yield from q.async_q.get()
await q.async_q.get()
q.async_q.task_done()

task = self.loop.create_task(do_work())

@asyncio.coroutine
def wait_for_empty_queue():
yield from q.async_q.join()
async def wait_for_empty_queue():
await q.async_q.join()
task.cancel()

self.loop.run_until_complete(wait_for_empty_queue())
Expand All @@ -108,13 +105,12 @@ def threaded():
val = q.sync_q.get()
self.assertEqual(val, i)

@asyncio.coroutine
def go():
async def go():
f = self.loop.run_in_executor(None, threaded)
for i in range(5):
yield from q.async_q.put(i)
await q.async_q.put(i)

yield from f
await f
self.assertTrue(q.async_q.empty())

for i in range(3):
Expand All @@ -128,17 +124,16 @@ def threaded():
q.sync_q.put(i)
q.sync_q.join()

@asyncio.coroutine
def go():
async def go():
f = self.loop.run_in_executor(None, threaded)
for i in range(5):
val = yield from q.async_q.get()
val = await q.async_q.get()
self.assertEqual(val, i)
q.async_q.task_done()

self.assertTrue(q.async_q.empty())

yield from f
await f

for i in range(3):
self.loop.run_until_complete(go())
Expand All @@ -152,15 +147,14 @@ def threaded():
self.assertEqual(val, i)
q.sync_q.task_done()

@asyncio.coroutine
def go():
async def go():
f = self.loop.run_in_executor(None, threaded)
for i in range(5):
yield from q.async_q.put(i)
await q.async_q.put(i)

yield from q.async_q.join()
await q.async_q.join()

yield from f
await f
self.assertTrue(q.async_q.empty())

for i in range(3):
Expand Down

0 comments on commit 8dfcd30

Please sign in to comment.