]> granicus.if.org Git - python/commitdiff
Issue #24400: Add one more unittest for CoroutineType.__await__
authorYury Selivanov <yselivanov@sprymix.com>
Wed, 1 Jul 2015 16:29:55 +0000 (12:29 -0400)
committerYury Selivanov <yselivanov@sprymix.com>
Wed, 1 Jul 2015 16:29:55 +0000 (12:29 -0400)
Lib/test/test_coroutines.py

index a84e27a0d5036f2af71d8f50c1d3e8f6e945a263..3413a12d6f00d795184c27a31686f594c9fe4231 100644 (file)
@@ -519,6 +519,40 @@ class CoroutineTest(unittest.TestCase):
 
             run_async(foo())
 
+    def test_await_14(self):
+        class Wrapper:
+            # Forces the interpreter to use CoroutineType.__await__
+            def __init__(self, coro):
+                assert coro.__class__ is types.CoroutineType
+                self.coro = coro
+            def __await__(self):
+                return self.coro.__await__()
+
+        class FutureLike:
+            def __await__(self):
+                return (yield)
+
+        class Marker(Exception):
+            pass
+
+        async def coro1():
+            try:
+                return await FutureLike()
+            except ZeroDivisionError:
+                raise Marker
+        async def coro2():
+            return await Wrapper(coro1())
+
+        c = coro2()
+        c.send(None)
+        with self.assertRaisesRegex(StopIteration, 'spam'):
+            c.send('spam')
+
+        c = coro2()
+        c.send(None)
+        with self.assertRaises(Marker):
+            c.throw(ZeroDivisionError)
+
     def test_with_1(self):
         class Manager:
             def __init__(self, name):