From 53bf664844a78099c0f0eab5f5cfa86f5ed5c38f Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 3 Oct 2015 21:05:01 -0400 Subject: [PATCH] Modernize asyncio "yield from" test. --- tornado/test/asyncio_test.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tornado/test/asyncio_test.py b/tornado/test/asyncio_test.py index 1be0e54f3..94a569104 100644 --- a/tornado/test/asyncio_test.py +++ b/tornado/test/asyncio_test.py @@ -12,12 +12,9 @@ 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) -- 2.47.3