Add a test runner that makes the output for skipped tests more informative.
from __future__ import absolute_import, division, with_statement
-from tornado.test.httpclient_test import HTTPClientCommonTestCase
+from tornado.test import httpclient_test
+from tornado.test.util import unittest
try:
import pycurl
from tornado.curl_httpclient import CurlAsyncHTTPClient
-class CurlHTTPClientCommonTestCase(HTTPClientCommonTestCase):
+class CurlHTTPClientCommonTestCase(httpclient_test.HTTPClientCommonTestCase):
def get_http_client(self):
client = CurlAsyncHTTPClient(io_loop=self.io_loop)
# make sure AsyncHTTPClient magic doesn't give us the wrong class
self.assertTrue(isinstance(client, CurlAsyncHTTPClient))
return client
-
-# Remove the base class from our namespace so the unittest module doesn't
-# try to run it again.
-del HTTPClientCommonTestCase
-
-if pycurl is None:
- del CurlHTTPClientCommonTestCase
+CurlHTTPClientCommonTestCase = unittest.skipIf(pycurl is None,
+ "pycurl module not present")(
+ CurlHTTPClientCommonTestCase)
self.finish("Got %d bytes in POST" % len(self.request.body))
+skipIfNoSSL = unittest.skipIf(ssl is None, "ssl module not present")
+# In pre-1.0 versions of openssl, SSLv23 clients always send SSLv2
+# ClientHello messages, which are rejected by SSLv3 and TLSv1
+# servers. Note that while the OPENSSL_VERSION_INFO was formally
+# introduced in python3.2, it was present but undocumented in
+# python 2.7
+skipIfOldSSL = unittest.skipIf(
+ getattr(ssl, 'OPENSSL_VERSION_INFO', (0, 0)) < (1, 0),
+ "old version of ssl module and/or openssl")
+
+
class BaseSSLTest(AsyncHTTPSTestCase, LogTrapTestCase):
def get_app(self):
return Application([('/', HelloWorldRequestHandler,
class SSLv23Test(BaseSSLTest, SSLTestMixin):
def get_ssl_version(self):
return ssl.PROTOCOL_SSLv23
+SSLv23Test = skipIfNoSSL(SSLv23Test)
class SSLv3Test(BaseSSLTest, SSLTestMixin):
def get_ssl_version(self):
return ssl.PROTOCOL_SSLv3
-
+SSLv3Test = skipIfNoSSL(skipIfOldSSL(SSLv3Test))
class TLSv1Test(BaseSSLTest, SSLTestMixin):
def get_ssl_version(self):
return ssl.PROTOCOL_TLSv1
+TLSv1Test = skipIfNoSSL(skipIfOldSSL(TLSv1Test))
class BadSSLOptionsTest(unittest.TestCase):
})
-if ssl is None:
- del BaseSSLTest
- del SSLv23Test
-if getattr(ssl, 'OPENSSL_VERSION_INFO', (0, 0)) < (1, 0):
- # In pre-1.0 versions of openssl, SSLv23 clients always send SSLv2
- # ClientHello messages, which are rejected by SSLv3 and TLSv1
- # servers. Note that while the OPENSSL_VERSION_INFO was formally
- # introduced in python3.2, it was present but undocumented in
- # python 2.7
- del SSLv3Test
- del TLSv1Test
-
-
class MultipartTestHandler(RequestHandler):
def post(self):
self.finish({"header": self.request.headers["X-Header-Encoding-Test"],
self.assertEqual(body, b("Hello world"))
stream.close()
server.stop()
-
-if not hasattr(socket, 'AF_UNIX') or sys.platform == 'cygwin':
- del UnixSocketTest
+UnixSocketTest = unittest.skipIf(
+ not hasattr(socket, 'AF_UNIX') or sys.platform == 'cygwin',
+ "unix sockets not supported on this platform")
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream, SSLIOStream
from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, LogTrapTestCase, get_unused_port
+from tornado.test.util import unittest
from tornado.util import b
from tornado.web import RequestHandler, Application
import errno
except ImportError:
ssl = None
+skipIfNoSSL = unittest.skipIf(ssl is None, "ssl module not present")
class HelloHandler(RequestHandler):
def get(self):
# "frozen write buffer" assumption.
if (isinstance(server, SSLIOStream) and
platform.python_implementation() == 'PyPy'):
- return
+ raise unittest.SkipTest(
+ "pypy gc causes problems with openssl")
except AttributeError:
# python 2.5 didn't have platform.python_implementation,
# but there was no pypy for 2.5
LogTrapTestCase):
def _make_client_iostream(self):
return SSLIOStream(socket.socket(), io_loop=self.io_loop)
+TestIOStreamWebHTTPS = skipIfNoSSL(TestIOStreamWebHTTPS)
class TestIOStream(TestIOStreamMixin, AsyncTestCase, LogTrapTestCase):
def _make_client_iostream(self, connection, **kwargs):
return SSLIOStream(connection, io_loop=self.io_loop, **kwargs)
-
-if ssl is None:
- del TestIOStreamWebHTTPS
- del TestIOStreamSSL
+TestIOStreamSSL = skipIfNoSSL(TestIOStreamSSL)
from tornado.process import fork_processes, task_id
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.testing import LogTrapTestCase, get_unused_port
+from tornado.test.util import unittest
from tornado.web import RequestHandler, Application
# Not using AsyncHTTPTestCase because we need control over the IOLoop.
except Exception:
logging.error("exception in child process %d", id, exc_info=True)
raise
-
-
-if os.name != 'posix' or sys.platform == 'cygwin':
- # All sorts of unixisms here
- del ProcessTest
+ProcessTest = unittest.skipIf(os.name != 'posix' or sys.platform == 'cygwin',
+ "non-unix platform")(ProcessTest)
#!/usr/bin/env python
from __future__ import absolute_import, division, with_statement
+import textwrap
import sys
from tornado.test.util import unittest
def all():
return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES)
+class TornadoTextTestRunner(unittest.TextTestRunner):
+ def run(self, test):
+ result = super(TornadoTextTestRunner, self).run(test)
+ if result.skipped:
+ skip_reasons = set(reason for (test, reason) in result.skipped)
+ self.stream.write(textwrap.fill(
+ "Some tests were skipped because: %s" %
+ ", ".join(sorted(skip_reasons))))
+ self.stream.write("\n")
+ return result
+
if __name__ == '__main__':
# The -W command-line option does not work in a virtualenv with
# python 3 (as of virtualenv 1.7), so configure warnings
# suppresses this behavior, although this looks like an implementation
# detail. http://bugs.python.org/issue15626
kwargs['warnings'] = False
+ kwargs['testRunner'] = TornadoTextTestRunner
tornado.testing.main(**kwargs)
from tornado.httputil import HTTPHeaders
from tornado.ioloop import IOLoop
from tornado.simple_httpclient import SimpleAsyncHTTPClient, _DEFAULT_CA_CERTS
-from tornado.test.httpclient_test import HTTPClientCommonTestCase, ChunkHandler, CountdownHandler, HelloWorldHandler
+from tornado.test.httpclient_test import ChunkHandler, CountdownHandler, HelloWorldHandler
+from tornado.test import httpclient_test
from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, LogTrapTestCase, get_unused_port
+from tornado.test.util import unittest
from tornado.util import b
from tornado.web import RequestHandler, Application, asynchronous, url
-class SimpleHTTPClientCommonTestCase(HTTPClientCommonTestCase):
+class SimpleHTTPClientCommonTestCase(httpclient_test.HTTPClientCommonTestCase):
def get_http_client(self):
client = SimpleAsyncHTTPClient(io_loop=self.io_loop,
force_instance=True)
self.assertTrue(isinstance(client, SimpleAsyncHTTPClient))
return client
-# Remove the base class from our namespace so the unittest module doesn't
-# try to run it again.
-del HTTPClientCommonTestCase
-
class TriggerHandler(RequestHandler):
def initialize(self, queue, wake_callback):
# trigger the hanging request to let it clean up after itself
self.triggers.popleft()()
+ @unittest.skipIf(not socket.has_ipv6, 'ipv6 support not present')
def test_ipv6(self):
- if not socket.has_ipv6:
- # python compiled without ipv6 support, so skip this test
- return
try:
self.http_server.listen(self.get_http_port(), address='::1')
except socket.gaierror, e:
from tornado.util import import_object
from tornado.web import RequestHandler, Application
+skipIfNoTwisted = unittest.skipUnless(have_twisted,
+ "twisted module not present")
def save_signal_handlers():
saved = {}
def anotherWhenRunningCallback(self):
self._anotherWhenRunningCalled = True
-
+ReactorWhenRunningTest = skipIfNoTwisted(ReactorWhenRunningTest)
class ReactorCallLaterTest(ReactorTestCase):
def test_callLater(self):
self._laterCalled = True
self._called = self._reactor.seconds()
self._reactor.stop()
+ReactorCallLaterTest = skipIfNoTwisted(ReactorCallLaterTest)
class ReactorTwoCallLaterTest(ReactorTestCase):
self._later2Called = True
self._called2 = self._reactor.seconds()
self._reactor.stop()
+ReactorTwoCallLaterTest = skipIfNoTwisted(ReactorTwoCallLaterTest)
class ReactorCallFromThreadTest(ReactorTestCase):
def testCallFromThread(self):
self._reactor.callWhenRunning(self._whenRunningCallback)
self._reactor.run()
+ReactorCallFromThreadTest = skipIfNoTwisted(ReactorCallFromThreadTest)
class ReactorCallInThread(ReactorTestCase):
def testCallInThread(self):
self._reactor.callWhenRunning(self._whenRunningCallback)
self._reactor.run()
+ReactorCallInThread = skipIfNoTwisted(ReactorCallInThread)
class Reader(object):
def testNoWriter(self):
self._reactor.callWhenRunning(self._testNoWriter)
self._reactor.run()
+ReactorReaderWriterTest = skipIfNoTwisted(ReactorReaderWriterTest)
# Test various combinations of twisted and tornado http servers,
# http clients, and event loop interfaces.
response = self.twisted_fetch(
'http://localhost:%d' % self.tornado_port, self.run_reactor)
self.assertEqual(response, 'Hello from tornado!')
+CompatibilityTests = skipIfNoTwisted(CompatibilityTests)
-if not have_twisted:
- del ReactorWhenRunningTest
- del ReactorCallLaterTest
- del ReactorTwoCallLaterTest
- del ReactorCallFromThreadTest
- del ReactorCallInThread
- del ReactorReaderWriterTest
- del CompatibilityTests
-else:
+if have_twisted:
# Import and run as much of twisted's test suite as possible.
# This is unfortunately rather dependent on implementation details,
# but there doesn't appear to be a clean all-in-one conformance test
# This is kind of hacky, but run some of the HTTPServer tests through
# WSGIContainer and WSGIApplication to make sure everything survives
# repeated disassembly and reassembly.
-from tornado.test.httpserver_test import HTTPConnectionTest
-from tornado.test.web_test import WSGISafeWebTest
+from tornado.test import httpserver_test
+from tornado.test import web_test
-class WSGIConnectionTest(HTTPConnectionTest):
+class WSGIConnectionTest(httpserver_test.HTTPConnectionTest):
def get_app(self):
return WSGIContainer(validator(WSGIApplication(self.get_handlers())))
-class WSGIWebTest(WSGISafeWebTest):
+class WSGIWebTest(web_test.WSGISafeWebTest):
def get_app(self):
self.app = WSGIApplication(self.get_handlers(), **self.get_app_kwargs())
return WSGIContainer(validator(self.app))
-
-del HTTPConnectionTest
-del WSGISafeWebTest