summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_locks.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-08 22:23:48 (GMT)
committerGitHub <noreply@github.com>2017-12-08 22:23:48 (GMT)
commit5f841b553814969220b096a2b4f959b7f6fcbaf6 (patch)
treeb48ea916d9585efa9bf7ff370b50c4e2dfb30247 /Lib/test/test_asyncio/test_locks.py
parentede157331b4f9e550334900b3b4de1c8590688de (diff)
downloadcpython-5f841b553814969220b096a2b4f959b7f6fcbaf6.zip
cpython-5f841b553814969220b096a2b4f959b7f6fcbaf6.tar.gz
cpython-5f841b553814969220b096a2b4f959b7f6fcbaf6.tar.bz2
bpo-32193: Convert asyncio to async/await usage (#4753)
* Convert asyncio/tasks.py to async/await * Convert asyncio/queues.py to async/await * Convert asyncio/test_utils.py to async/await * Convert asyncio/base_subprocess.py to async/await * Convert asyncio/subprocess.py to async/await * Convert asyncio/streams.py to async/await * Fix comments * Convert asyncio/locks.py to async/await * Convert asyncio.sleep to async def * Add a comment * Add missing news * Convert stubs from AbstrctEventLoop to async functions * Convert subprocess_shell/subprocess_exec * Convert connect_read_pipe/connect_write_pip to async/await syntax * Convert create_datagram_endpoint * Convert create_unix_server/create_unix_connection * Get rid of old style coroutines in unix_events.py * Convert selector_events.py to async/await * Convert wait_closed and create_connection * Drop redundant line * Convert base_events.py * Code cleanup * Drop redundant comments * Fix indentation * Add explicit tests for compatibility between old and new coroutines * Convert windows event loop to use async/await * Fix double awaiting of async function * Convert asyncio/locks.py * Improve docstring * Convert tests to async/await * Convert more tests * Convert more tests * Convert more tests * Convert tests * Improve test
Diffstat (limited to 'Lib/test/test_asyncio/test_locks.py')
-rw-r--r--Lib/test/test_asyncio/test_locks.py125
1 files changed, 52 insertions, 73 deletions
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index c85e8b1..c1f8d6e 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -69,21 +69,18 @@ class LockTests(test_utils.TestCase):
self.assertTrue(self.loop.run_until_complete(lock.acquire()))
- @asyncio.coroutine
- def c1(result):
- if (yield from lock.acquire()):
+ async def c1(result):
+ if await lock.acquire():
result.append(1)
return True
- @asyncio.coroutine
- def c2(result):
- if (yield from lock.acquire()):
+ async def c2(result):
+ if await lock.acquire():
result.append(2)
return True
- @asyncio.coroutine
- def c3(result):
- if (yield from lock.acquire()):
+ async def c3(result):
+ if await lock.acquire():
result.append(3)
return True
@@ -145,12 +142,11 @@ class LockTests(test_utils.TestCase):
# Setup: A has the lock, b and c are waiting.
lock = asyncio.Lock(loop=self.loop)
- @asyncio.coroutine
- def lockit(name, blocker):
- yield from lock.acquire()
+ async def lockit(name, blocker):
+ await lock.acquire()
try:
if blocker is not None:
- yield from blocker
+ await blocker
finally:
lock.release()
@@ -294,19 +290,16 @@ class EventTests(test_utils.TestCase):
result = []
- @asyncio.coroutine
- def c1(result):
- if (yield from ev.wait()):
+ async def c1(result):
+ if await ev.wait():
result.append(1)
- @asyncio.coroutine
- def c2(result):
- if (yield from ev.wait()):
+ async def c2(result):
+ if await ev.wait():
result.append(2)
- @asyncio.coroutine
- def c3(result):
- if (yield from ev.wait()):
+ async def c3(result):
+ if await ev.wait():
result.append(3)
t1 = asyncio.Task(c1(result), loop=self.loop)
@@ -359,9 +352,8 @@ class EventTests(test_utils.TestCase):
ev = asyncio.Event(loop=self.loop)
result = []
- @asyncio.coroutine
- def c1(result):
- if (yield from ev.wait()):
+ async def c1(result):
+ if await ev.wait():
result.append(1)
return True
@@ -408,24 +400,21 @@ class ConditionTests(test_utils.TestCase):
cond = asyncio.Condition(loop=self.loop)
result = []
- @asyncio.coroutine
- def c1(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c1(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(1)
return True
- @asyncio.coroutine
- def c2(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c2(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(2)
return True
- @asyncio.coroutine
- def c3(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c3(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(3)
return True
@@ -522,10 +511,9 @@ class ConditionTests(test_utils.TestCase):
result = []
- @asyncio.coroutine
- def c1(result):
- yield from cond.acquire()
- if (yield from cond.wait_for(predicate)):
+ async def c1(result):
+ await cond.acquire()
+ if await cond.wait_for(predicate):
result.append(1)
cond.release()
return True
@@ -567,26 +555,23 @@ class ConditionTests(test_utils.TestCase):
cond = asyncio.Condition(loop=self.loop)
result = []
- @asyncio.coroutine
- def c1(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c1(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(1)
cond.release()
return True
- @asyncio.coroutine
- def c2(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c2(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(2)
cond.release()
return True
- @asyncio.coroutine
- def c3(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c3(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(3)
cond.release()
return True
@@ -623,18 +608,16 @@ class ConditionTests(test_utils.TestCase):
result = []
- @asyncio.coroutine
- def c1(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c1(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(1)
cond.release()
return True
- @asyncio.coroutine
- def c2(result):
- yield from cond.acquire()
- if (yield from cond.wait()):
+ async def c2(result):
+ await cond.acquire()
+ if await cond.wait():
result.append(2)
cond.release()
return True
@@ -791,27 +774,23 @@ class SemaphoreTests(test_utils.TestCase):
self.assertTrue(self.loop.run_until_complete(sem.acquire()))
self.assertFalse(sem.locked())
- @asyncio.coroutine
- def c1(result):
- yield from sem.acquire()
+ async def c1(result):
+ await sem.acquire()
result.append(1)
return True
- @asyncio.coroutine
- def c2(result):
- yield from sem.acquire()
+ async def c2(result):
+ await sem.acquire()
result.append(2)
return True
- @asyncio.coroutine
- def c3(result):
- yield from sem.acquire()
+ async def c3(result):
+ await sem.acquire()
result.append(3)
return True
- @asyncio.coroutine
- def c4(result):
- yield from sem.acquire()
+ async def c4(result):
+ await sem.acquire()
result.append(4)
return True