From: Ben Darnell Date: Sun, 4 Oct 2015 01:05:01 +0000 (-0400) Subject: Modernize asyncio "yield from" test. X-Git-Tag: v4.3.0b1~8^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53bf664844a78099c0f0eab5f5cfa86f5ed5c38f;p=thirdparty%2Ftornado.git Modernize asyncio "yield from" test. --- 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)