summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_locks.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio/test_locks.py')
-rw-r--r--Lib/test/test_asyncio/test_locks.py47
1 files changed, 40 insertions, 7 deletions
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index c1f8d6e..f365a45 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -42,7 +42,8 @@ class LockTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_lock():
- yield from lock
+ with self.assertWarns(DeprecationWarning):
+ yield from lock
self.loop.run_until_complete(acquire_lock())
self.assertTrue(repr(lock).endswith('[locked]>'))
@@ -53,7 +54,8 @@ class LockTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_lock():
- return (yield from lock)
+ with self.assertWarns(DeprecationWarning):
+ return (yield from lock)
res = self.loop.run_until_complete(acquire_lock())
@@ -63,6 +65,32 @@ class LockTests(test_utils.TestCase):
lock.release()
self.assertFalse(lock.locked())
+ def test_lock_by_with_statement(self):
+ loop = asyncio.new_event_loop() # don't use TestLoop quirks
+ self.set_event_loop(loop)
+ primitives = [
+ asyncio.Lock(loop=loop),
+ asyncio.Condition(loop=loop),
+ asyncio.Semaphore(loop=loop),
+ asyncio.BoundedSemaphore(loop=loop),
+ ]
+
+ @asyncio.coroutine
+ def test(lock):
+ yield from asyncio.sleep(0.01, loop=loop)
+ 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)
+ self.assertTrue(lock.locked())
+ self.assertFalse(lock.locked())
+
+ for primitive in primitives:
+ loop.run_until_complete(test(primitive))
+ self.assertFalse(primitive.locked())
+
def test_acquire(self):
lock = asyncio.Lock(loop=self.loop)
result = []
@@ -212,7 +240,8 @@ class LockTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_lock():
- return (yield from lock)
+ with self.assertWarns(DeprecationWarning):
+ return (yield from lock)
with self.loop.run_until_complete(acquire_lock()):
self.assertTrue(lock.locked())
@@ -224,7 +253,8 @@ class LockTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_lock():
- return (yield from lock)
+ with self.assertWarns(DeprecationWarning):
+ return (yield from lock)
# This spells "yield from lock" outside a generator.
cm = self.loop.run_until_complete(acquire_lock())
@@ -668,7 +698,8 @@ class ConditionTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_cond():
- return (yield from cond)
+ with self.assertWarns(DeprecationWarning):
+ return (yield from cond)
with self.loop.run_until_complete(acquire_cond()):
self.assertTrue(cond.locked())
@@ -751,7 +782,8 @@ class SemaphoreTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_lock():
- return (yield from sem)
+ with self.assertWarns(DeprecationWarning):
+ return (yield from sem)
res = self.loop.run_until_complete(acquire_lock())
@@ -893,7 +925,8 @@ class SemaphoreTests(test_utils.TestCase):
@asyncio.coroutine
def acquire_lock():
- return (yield from sem)
+ with self.assertWarns(DeprecationWarning):
+ return (yield from sem)
with self.loop.run_until_complete(acquire_lock()):
self.assertFalse(sem.locked())