1# flake8: noqa 2import subprocess 3import sys 4import unittest 5 6_import_everything = b""" 7# The event loop is not fork-safe, and it's easy to initialize an asyncio.Future 8# at startup, which in turn creates the default event loop and prevents forking. 9# Explicitly disallow the default event loop so that an error will be raised 10# if something tries to touch it. 11import asyncio 12asyncio.set_event_loop(None) 13 14import tornado.auth 15import tornado.autoreload 16import tornado.concurrent 17import tornado.escape 18import tornado.gen 19import tornado.http1connection 20import tornado.httpclient 21import tornado.httpserver 22import tornado.httputil 23import tornado.ioloop 24import tornado.iostream 25import tornado.locale 26import tornado.log 27import tornado.netutil 28import tornado.options 29import tornado.process 30import tornado.simple_httpclient 31import tornado.tcpserver 32import tornado.tcpclient 33import tornado.template 34import tornado.testing 35import tornado.util 36import tornado.web 37import tornado.websocket 38import tornado.wsgi 39 40try: 41 import pycurl 42except ImportError: 43 pass 44else: 45 import tornado.curl_httpclient 46""" 47 48 49class ImportTest(unittest.TestCase): 50 def test_import_everything(self): 51 # Test that all Tornado modules can be imported without side effects, 52 # specifically without initializing the default asyncio event loop. 53 # Since we can't tell which modules may have already beein imported 54 # in our process, do it in a subprocess for a clean slate. 55 proc = subprocess.Popen([sys.executable], stdin=subprocess.PIPE) 56 proc.communicate(_import_everything) 57 self.assertEqual(proc.returncode, 0) 58 59 def test_import_aliases(self): 60 # Ensure we don't delete formerly-documented aliases accidentally. 61 import tornado.ioloop 62 import tornado.gen 63 import tornado.util 64 65 self.assertIs(tornado.ioloop.TimeoutError, tornado.util.TimeoutError) 66 self.assertIs(tornado.gen.TimeoutError, tornado.util.TimeoutError) 67