]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Modernize asyncio "yield from" test.
authorBen Darnell <ben@bendarnell.com>
Sun, 4 Oct 2015 01:05:01 +0000 (21:05 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 4 Oct 2015 02:28:15 +0000 (22:28 -0400)
tornado/test/asyncio_test.py

index 1be0e54f35529da7a0a6671992f0b279d74cffdb..94a569104117ae11c475241fe134cba777c46f0e 100644 (file)
 
 from __future__ import absolute_import, division, print_function, with_statement
 
-import sys
-import textwrap
-
 from tornado import gen
 from tornado.testing import AsyncTestCase, gen_test
-from tornado.test.util import unittest
+from tornado.test.util import unittest, skipBefore33, exec_test
 
 try:
     from tornado.platform.asyncio import asyncio, AsyncIOLoop
@@ -49,21 +46,18 @@ class AsyncIOLoopTest(AsyncTestCase):
             asyncio.get_event_loop().run_in_executor(None, lambda: 42))
         self.assertEqual(x, 42)
 
-    @unittest.skipIf(sys.version_info < (3, 3),
-                     'PEP 380 not available')
+    @skipBefore33
     @skipIfNoSingleDispatch
     @gen_test
     def test_asyncio_yield_from(self):
         # Test that we can use asyncio coroutines with 'yield from'
         # instead of asyncio.async(). This requires python 3.3 syntax.
-        global_namespace = dict(globals(), **locals())
-        local_namespace = {}
-        exec(textwrap.dedent("""
+        namespace = exec_test(globals(), locals(), """
         @gen.coroutine
         def f():
             event_loop = asyncio.get_event_loop()
             x = yield from event_loop.run_in_executor(None, lambda: 42)
             return x
-        """), global_namespace, local_namespace)
-        result = yield local_namespace['f']()
+        """)
+        result = yield namespace['f']()
         self.assertEqual(result, 42)