summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_types.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
commit7544508f0245173bff5866aa1598c8f6cce1fc5f (patch)
treebf80850d9cd46fc811f04b8c2484fb50775c697d /Lib/test/test_types.py
parent4e6bf4b3da03b132b0698f30ee931a350585b117 (diff)
downloadcpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.zip
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.gz
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.bz2
PEP 0492 -- Coroutines with async and await syntax. Issue #24017.
Diffstat (limited to 'Lib/test/test_types.py')
-rw-r--r--Lib/test/test_types.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 8cdecb0..c5a35f9 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -1,7 +1,8 @@
# Python test set -- part 6, built-in types
from test.support import run_with_locale
-import collections
+import collections.abc
+import inspect
import pickle
import locale
import sys
@@ -1172,5 +1173,37 @@ class SimpleNamespaceTests(unittest.TestCase):
self.assertEqual(ns, ns_roundtrip, pname)
+class CoroutineTests(unittest.TestCase):
+ def test_wrong_args(self):
+ class Foo:
+ def __call__(self):
+ pass
+ def bar(): pass
+
+ samples = [Foo, Foo(), bar, None, int, 1]
+ for sample in samples:
+ with self.assertRaisesRegex(TypeError, 'expects a generator'):
+ types.coroutine(sample)
+
+ def test_genfunc(self):
+ def gen():
+ yield
+
+ self.assertFalse(isinstance(gen(), collections.abc.Coroutine))
+ self.assertFalse(isinstance(gen(), collections.abc.Awaitable))
+
+ self.assertIs(types.coroutine(gen), gen)
+
+ self.assertTrue(gen.__code__.co_flags & inspect.CO_ITERABLE_COROUTINE)
+ self.assertFalse(gen.__code__.co_flags & inspect.CO_COROUTINE)
+
+ g = gen()
+ self.assertTrue(g.gi_code.co_flags & inspect.CO_ITERABLE_COROUTINE)
+ self.assertFalse(g.gi_code.co_flags & inspect.CO_COROUTINE)
+ self.assertTrue(isinstance(g, collections.abc.Coroutine))
+ self.assertTrue(isinstance(g, collections.abc.Awaitable))
+ g.close() # silence warning
+
+
if __name__ == '__main__':
unittest.main()