runtests.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from __future__ import absolute_import, division, print_function, with_statement
00004 import gc
00005 import locale  # system locale module, not tornado.locale
00006 import logging
00007 import operator
00008 import textwrap
00009 import sys
00010 from tornado.httpclient import AsyncHTTPClient
00011 from tornado.ioloop import IOLoop
00012 from tornado.netutil import Resolver
00013 from tornado.options import define, options, add_parse_callback
00014 from tornado.test.util import unittest
00015 
00016 try:
00017     reduce  # py2
00018 except NameError:
00019     from functools import reduce  # py3
00020 
00021 TEST_MODULES = [
00022     'tornado.httputil.doctests',
00023     'tornado.iostream.doctests',
00024     'tornado.util.doctests',
00025     'tornado.test.auth_test',
00026     'tornado.test.concurrent_test',
00027     'tornado.test.curl_httpclient_test',
00028     'tornado.test.escape_test',
00029     'tornado.test.gen_test',
00030     'tornado.test.httpclient_test',
00031     'tornado.test.httpserver_test',
00032     'tornado.test.httputil_test',
00033     'tornado.test.import_test',
00034     'tornado.test.ioloop_test',
00035     'tornado.test.iostream_test',
00036     'tornado.test.locale_test',
00037     'tornado.test.netutil_test',
00038     'tornado.test.log_test',
00039     'tornado.test.options_test',
00040     'tornado.test.process_test',
00041     'tornado.test.simple_httpclient_test',
00042     'tornado.test.stack_context_test',
00043     'tornado.test.tcpclient_test',
00044     'tornado.test.template_test',
00045     'tornado.test.testing_test',
00046     'tornado.test.twisted_test',
00047     'tornado.test.util_test',
00048     'tornado.test.web_test',
00049     'tornado.test.websocket_test',
00050     'tornado.test.wsgi_test',
00051 ]
00052 
00053 
00054 def all():
00055     return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES)
00056 
00057 
00058 class TornadoTextTestRunner(unittest.TextTestRunner):
00059     def run(self, test):
00060         result = super(TornadoTextTestRunner, self).run(test)
00061         if result.skipped:
00062             skip_reasons = set(reason for (test, reason) in result.skipped)
00063             self.stream.write(textwrap.fill(
00064                 "Some tests were skipped because: %s" %
00065                 ", ".join(sorted(skip_reasons))))
00066             self.stream.write("\n")
00067         return result
00068 
00069 
00070 def main():
00071     # The -W command-line option does not work in a virtualenv with
00072     # python 3 (as of virtualenv 1.7), so configure warnings
00073     # programmatically instead.
00074     import warnings
00075     # Be strict about most warnings.  This also turns on warnings that are
00076     # ignored by default, including DeprecationWarnings and
00077     # python 3.2's ResourceWarnings.
00078     warnings.filterwarnings("error")
00079     # setuptools sometimes gives ImportWarnings about things that are on
00080     # sys.path even if they're not being used.
00081     warnings.filterwarnings("ignore", category=ImportWarning)
00082     # Tornado generally shouldn't use anything deprecated, but some of
00083     # our dependencies do (last match wins).
00084     warnings.filterwarnings("ignore", category=DeprecationWarning)
00085     warnings.filterwarnings("error", category=DeprecationWarning,
00086                             module=r"tornado\..*")
00087     warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
00088     warnings.filterwarnings("error", category=PendingDeprecationWarning,
00089                             module=r"tornado\..*")
00090     # The unittest module is aggressive about deprecating redundant methods,
00091     # leaving some without non-deprecated spellings that work on both
00092     # 2.7 and 3.2
00093     warnings.filterwarnings("ignore", category=DeprecationWarning,
00094                             message="Please use assert.* instead")
00095 
00096     logging.getLogger("tornado.access").setLevel(logging.CRITICAL)
00097 
00098     define('httpclient', type=str, default=None,
00099            callback=lambda s: AsyncHTTPClient.configure(
00100                s, defaults=dict(allow_ipv6=False)))
00101     define('ioloop', type=str, default=None)
00102     define('ioloop_time_monotonic', default=False)
00103     define('resolver', type=str, default=None,
00104            callback=Resolver.configure)
00105     define('debug_gc', type=str, multiple=True,
00106            help="A comma-separated list of gc module debug constants, "
00107            "e.g. DEBUG_STATS or DEBUG_COLLECTABLE,DEBUG_OBJECTS",
00108            callback=lambda values: gc.set_debug(
00109                reduce(operator.or_, (getattr(gc, v) for v in values))))
00110     define('locale', type=str, default=None,
00111            callback=lambda x: locale.setlocale(locale.LC_ALL, x))
00112 
00113     def configure_ioloop():
00114         kwargs = {}
00115         if options.ioloop_time_monotonic:
00116             from tornado.platform.auto import monotonic_time
00117             if monotonic_time is None:
00118                 raise RuntimeError("monotonic clock not found")
00119             kwargs['time_func'] = monotonic_time
00120         if options.ioloop or kwargs:
00121             IOLoop.configure(options.ioloop, **kwargs)
00122     add_parse_callback(configure_ioloop)
00123 
00124     import tornado.testing
00125     kwargs = {}
00126     if sys.version_info >= (3, 2):
00127         # HACK:  unittest.main will make its own changes to the warning
00128         # configuration, which may conflict with the settings above
00129         # or command-line flags like -bb.  Passing warnings=False
00130         # suppresses this behavior, although this looks like an implementation
00131         # detail.  http://bugs.python.org/issue15626
00132         kwargs['warnings'] = False
00133     kwargs['testRunner'] = TornadoTextTestRunner
00134     tornado.testing.main(**kwargs)
00135 
00136 if __name__ == '__main__':
00137     main()


rosbridge_tools
Author(s): Jonathan Mace
autogenerated on Sat Dec 27 2014 11:25:59