summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-07-23 12:58:37 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-07-23 12:58:37 (GMT)
commit4887523c038bc3449fe87a10828355e624de6565 (patch)
treed58274f9412fc308913deaf19ec2ca0e7ba0dca7
parent96ec934e755355cfc5af036db8641646b7ddb45e (diff)
downloadcpython-4887523c038bc3449fe87a10828355e624de6565.zip
cpython-4887523c038bc3449fe87a10828355e624de6565.tar.gz
cpython-4887523c038bc3449fe87a10828355e624de6565.tar.bz2
Issue #24692: Add more tests for types.coroutine
-rw-r--r--Lib/test/test_types.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 738588e..5e74115 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -1213,6 +1213,10 @@ class CoroutineTests(unittest.TestCase):
return aw
self.assertIs(aw, foo())
+ # decorate foo second time
+ foo = types.coroutine(foo)
+ self.assertIs(aw, foo())
+
def test_async_def(self):
# Test that types.coroutine passes 'async def' coroutines
# without modification
@@ -1226,12 +1230,13 @@ class CoroutineTests(unittest.TestCase):
self.assertIs(decorated_foo.__code__, foo_code)
foo_coro = foo()
- @types.coroutine
def bar(): return foo_coro
- coro = bar()
- self.assertIs(foo_coro, coro)
- self.assertEqual(coro.cr_code.co_flags, foo_flags)
- coro.close()
+ for _ in range(2):
+ bar = types.coroutine(bar)
+ coro = bar()
+ self.assertIs(foo_coro, coro)
+ self.assertEqual(coro.cr_code.co_flags, foo_flags)
+ coro.close()
def test_duck_coro(self):
class CoroLike:
@@ -1447,6 +1452,10 @@ class CoroutineTests(unittest.TestCase):
with self.assertRaisesRegex(Exception, 'ham'):
wrapper.throw(Exception, Exception('ham'))
+ # decorate foo second time
+ foo = types.coroutine(foo)
+ self.assertIs(foo().__await__(), gen)
+
def test_returning_itercoro(self):
@types.coroutine
def gen():
@@ -1460,9 +1469,14 @@ class CoroutineTests(unittest.TestCase):
self.assertIs(foo(), gencoro)
+ # decorate foo second time
+ foo = types.coroutine(foo)
+ self.assertIs(foo(), gencoro)
+
def test_genfunc(self):
def gen(): yield
self.assertIs(types.coroutine(gen), gen)
+ self.assertIs(types.coroutine(types.coroutine(gen)), gen)
self.assertTrue(gen.__code__.co_flags & inspect.CO_ITERABLE_COROUTINE)
self.assertFalse(gen.__code__.co_flags & inspect.CO_COROUTINE)