Author: Raffael Tfirst <raffael.tfi...@gmail.com>
Branch: py3.5
Changeset: r86205:90eef5573de8
Date: 2016-08-15 22:11 +0200
http://bitbucket.org/pypy/pypy/changeset/90eef5573de8/

Log:    Add asyncio test for asynchronous context managers

diff --git a/pypy/module/_asyncio/test/test_asyncio.py 
b/pypy/module/_asyncio/test/test_asyncio.py
--- a/pypy/module/_asyncio/test/test_asyncio.py
+++ b/pypy/module/_asyncio/test/test_asyncio.py
@@ -18,3 +18,31 @@
         loop.run_until_complete(f())
         print("done with async loop")
         """
+    
+    def test_asynchronous_context_managers(self):
+        """
+import encodings.idna
+import asyncio
+
+class Corotest(object):
+    def __init__(self):
+        self.res = "-"
+    
+    async def coro(self, name, lock):
+        self.res += ' coro {}: waiting for lock -'.format(name)
+        async with lock:
+            self.res += ' coro {}: holding the lock -'.format(name)
+            await asyncio.sleep(1)
+            self.res += ' coro {}: releasing the lock -'.format(name)
+
+cor = Corotest()
+loop = asyncio.get_event_loop()
+lock = asyncio.Lock()
+coros = asyncio.gather(cor.coro(1, lock), cor.coro(2, lock))
+try:
+    loop.run_until_complete(coros)
+finally:
+    loop.close()
+
+assert cor.res == "- coro 1: waiting for lock - coro 1: holding the lock - 
coro 2: waiting for lock - coro 1: releasing the lock - coro 2: holding the 
lock - coro 2: releasing the lock -"
+        """
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to