PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tornado/test/runtests.py

https://github.com/rgaidot/tornado
Python | 137 lines | 104 code | 14 blank | 19 comment | 11 complexity | eedc4f682c13982a952b67b7e3a3f088 MD5 | raw file
Possible License(s): Apache-2.0
  1. #!/usr/bin/env python
  2. from __future__ import absolute_import, division, print_function, with_statement
  3. import gc
  4. import locale # system locale module, not tornado.locale
  5. import logging
  6. import operator
  7. import textwrap
  8. import sys
  9. from tornado.httpclient import AsyncHTTPClient
  10. from tornado.ioloop import IOLoop
  11. from tornado.netutil import Resolver
  12. from tornado.options import define, options, add_parse_callback
  13. from tornado.test.util import unittest
  14. try:
  15. reduce # py2
  16. except NameError:
  17. from functools import reduce # py3
  18. TEST_MODULES = [
  19. 'tornado.httputil.doctests',
  20. 'tornado.iostream.doctests',
  21. 'tornado.util.doctests',
  22. 'tornado.test.auth_test',
  23. 'tornado.test.concurrent_test',
  24. 'tornado.test.curl_httpclient_test',
  25. 'tornado.test.escape_test',
  26. 'tornado.test.gen_test',
  27. 'tornado.test.httpclient_test',
  28. 'tornado.test.httpserver_test',
  29. 'tornado.test.httputil_test',
  30. 'tornado.test.import_test',
  31. 'tornado.test.ioloop_test',
  32. 'tornado.test.iostream_test',
  33. 'tornado.test.locale_test',
  34. 'tornado.test.netutil_test',
  35. 'tornado.test.log_test',
  36. 'tornado.test.options_test',
  37. 'tornado.test.process_test',
  38. 'tornado.test.simple_httpclient_test',
  39. 'tornado.test.stack_context_test',
  40. 'tornado.test.tcpclient_test',
  41. 'tornado.test.template_test',
  42. 'tornado.test.testing_test',
  43. 'tornado.test.twisted_test',
  44. 'tornado.test.util_test',
  45. 'tornado.test.web_test',
  46. 'tornado.test.websocket_test',
  47. 'tornado.test.wsgi_test',
  48. ]
  49. def all():
  50. return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES)
  51. class TornadoTextTestRunner(unittest.TextTestRunner):
  52. def run(self, test):
  53. result = super(TornadoTextTestRunner, self).run(test)
  54. if result.skipped:
  55. skip_reasons = set(reason for (test, reason) in result.skipped)
  56. self.stream.write(textwrap.fill(
  57. "Some tests were skipped because: %s" %
  58. ", ".join(sorted(skip_reasons))))
  59. self.stream.write("\n")
  60. return result
  61. def main():
  62. # The -W command-line option does not work in a virtualenv with
  63. # python 3 (as of virtualenv 1.7), so configure warnings
  64. # programmatically instead.
  65. import warnings
  66. # Be strict about most warnings. This also turns on warnings that are
  67. # ignored by default, including DeprecationWarnings and
  68. # python 3.2's ResourceWarnings.
  69. warnings.filterwarnings("error")
  70. # setuptools sometimes gives ImportWarnings about things that are on
  71. # sys.path even if they're not being used.
  72. warnings.filterwarnings("ignore", category=ImportWarning)
  73. # Tornado generally shouldn't use anything deprecated, but some of
  74. # our dependencies do (last match wins).
  75. warnings.filterwarnings("ignore", category=DeprecationWarning)
  76. warnings.filterwarnings("error", category=DeprecationWarning,
  77. module=r"tornado\..*")
  78. warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
  79. warnings.filterwarnings("error", category=PendingDeprecationWarning,
  80. module=r"tornado\..*")
  81. # The unittest module is aggressive about deprecating redundant methods,
  82. # leaving some without non-deprecated spellings that work on both
  83. # 2.7 and 3.2
  84. warnings.filterwarnings("ignore", category=DeprecationWarning,
  85. message="Please use assert.* instead")
  86. logging.getLogger("tornado.access").setLevel(logging.CRITICAL)
  87. define('httpclient', type=str, default=None,
  88. callback=lambda s: AsyncHTTPClient.configure(
  89. s, defaults=dict(allow_ipv6=False)))
  90. define('ioloop', type=str, default=None)
  91. define('ioloop_time_monotonic', default=False)
  92. define('resolver', type=str, default=None,
  93. callback=Resolver.configure)
  94. define('debug_gc', type=str, multiple=True,
  95. help="A comma-separated list of gc module debug constants, "
  96. "e.g. DEBUG_STATS or DEBUG_COLLECTABLE,DEBUG_OBJECTS",
  97. callback=lambda values: gc.set_debug(
  98. reduce(operator.or_, (getattr(gc, v) for v in values))))
  99. define('locale', type=str, default=None,
  100. callback=lambda x: locale.setlocale(locale.LC_ALL, x))
  101. def configure_ioloop():
  102. kwargs = {}
  103. if options.ioloop_time_monotonic:
  104. from tornado.platform.auto import monotonic_time
  105. if monotonic_time is None:
  106. raise RuntimeError("monotonic clock not found")
  107. kwargs['time_func'] = monotonic_time
  108. if options.ioloop or kwargs:
  109. IOLoop.configure(options.ioloop, **kwargs)
  110. add_parse_callback(configure_ioloop)
  111. import tornado.testing
  112. kwargs = {}
  113. if sys.version_info >= (3, 2):
  114. # HACK: unittest.main will make its own changes to the warning
  115. # configuration, which may conflict with the settings above
  116. # or command-line flags like -bb. Passing warnings=False
  117. # suppresses this behavior, although this looks like an implementation
  118. # detail. http://bugs.python.org/issue15626
  119. kwargs['warnings'] = False
  120. kwargs['testRunner'] = TornadoTextTestRunner
  121. tornado.testing.main(**kwargs)
  122. if __name__ == '__main__':
  123. main()