]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Start using new unittest features from py27/unittest2.
authorBen Darnell <ben@bendarnell.com>
Thu, 30 Aug 2012 21:43:54 +0000 (17:43 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 30 Aug 2012 22:24:49 +0000 (18:24 -0400)
Tornado's test suite now requires unittest2 on py25 and py26.
tornado.testing will use unittest2 if available but does not require
it.

This means we can no longer run the test suite under app engine 2.5,
although it still works for app engine 2.7.

16 files changed:
maint/test/appengine/tox.ini
tornado/test/escape_test.py
tornado/test/httpserver_test.py
tornado/test/httputil_test.py
tornado/test/import_test.py
tornado/test/ioloop_test.py
tornado/test/locale_test.py
tornado/test/options_test.py
tornado/test/runtests.py
tornado/test/stack_context_test.py
tornado/test/testing_test.py
tornado/test/twisted_test.py
tornado/test/util.py [new file with mode: 0644]
tornado/test/util_test.py
tornado/testing.py
tox.ini

index 0970bf8840d30145bd45d29603fe697ae000966e..dcc7ac2f8e64ac7772d4db863ace6455546dd939 100644 (file)
@@ -5,14 +5,18 @@
 # These are currently excluded from the main tox.ini because their
 # logs are spammy and they're a little flaky.
 [tox]
-envlist = py25-appengine, py27-appengine
+envlist = py27-appengine
 
 [testenv]
 changedir = {toxworkdir}
 
+# py25-appengine was broken by the addition of unittest2.  Need to figure
+# out a way to smuggle unittest2 into the appengine environment if we don't
+# drop py25 support.
 [testenv:py25-appengine]
 basepython = python2.5
 commands = python {toxinidir}/py25/runtests.py {posargs:}
+deps = unittest2
 
 [testenv:py27-appengine]
 basepython = python2.7
index defca1ba292712a47df7fe4deddf1b613995f4ef..793e3c8ebe6c0e41c731ecb4a3dd33124a0c39cf 100644 (file)
@@ -3,10 +3,10 @@
 
 from __future__ import absolute_import, division, with_statement
 import tornado.escape
-import unittest
 
 from tornado.escape import utf8, xhtml_escape, xhtml_unescape, url_escape, url_unescape, to_unicode, json_decode, json_encode
 from tornado.util import b
+from tornado.test.util import unittest
 
 linkify_tests = [
     # (input, linkify_kwargs, expected_output)
index 190f1abc3bbd5a777eb16f10fb9aa2396514f423..415727150c0246276a66d80a98c8f37df4be3206 100644 (file)
@@ -10,6 +10,7 @@ from tornado.ioloop import IOLoop
 from tornado.iostream import IOStream
 from tornado.simple_httpclient import SimpleAsyncHTTPClient
 from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, LogTrapTestCase
+from tornado.test.util import unittest
 from tornado.util import b, bytes_type
 from tornado.web import Application, RequestHandler
 import os
@@ -17,7 +18,6 @@ import shutil
 import socket
 import sys
 import tempfile
-import unittest
 
 try:
     import ssl
index 736ed6d67a4dd154ac4cbf178b307c955ac1394a..f1319cded8466de20a8865487f1d87b6ed777583 100644 (file)
@@ -5,9 +5,9 @@ from __future__ import absolute_import, division, with_statement
 from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders
 from tornado.escape import utf8
 from tornado.testing import LogTrapTestCase
+from tornado.test.util import unittest
 from tornado.util import b
 import logging
-import unittest
 
 
 class TestUrlConcat(unittest.TestCase):
index 584f070d2f1c95182c429e287bca4937207ec466..97c2277b9f1b49b2414007b11196227c4016b3b4 100644 (file)
@@ -1,5 +1,5 @@
 from __future__ import absolute_import, division, with_statement
-import unittest
+from tornado.test.util import unittest
 
 
 class ImportTest(unittest.TestCase):
index 2ebdbcea82ad229825a02bed68f2f5ff9dc4eebe..4e5e123c9ac2b2a8c9672f1c89d6117efa9d7eb8 100644 (file)
@@ -5,11 +5,11 @@ from __future__ import absolute_import, division, with_statement
 import datetime
 import socket
 import time
-import unittest
 
 from tornado.ioloop import IOLoop
 from tornado.netutil import bind_sockets
 from tornado.testing import AsyncTestCase, LogTrapTestCase, get_unused_port
+from tornado.test.util import unittest
 
 
 class TestIOLoop(AsyncTestCase, LogTrapTestCase):
index 586080b1e31dceba396bb0239c4d3e6ba347827d..4131dd0fe7f98c16883106643a51f164112f40b3 100644 (file)
@@ -2,7 +2,7 @@ from __future__ import absolute_import, division, with_statement
 
 import os
 import tornado.locale
-import unittest
+from tornado.test.util import unittest
 
 
 class TranslationLoaderTest(unittest.TestCase):
index 72be4459c1a5902c8365495ac9c078533604d14c..c815935c99140298811a9bf426285c17c3b57f25 100644 (file)
@@ -4,11 +4,11 @@ import logging
 import os
 import re
 import tempfile
-import unittest
 import warnings
 
 from tornado.escape import utf8
 from tornado.options import _Options, _LogFormatter
+from tornado.test.util import unittest
 from tornado.util import b, bytes_type
 
 
index eea052ea1cb9d4687ecb063408fc519c8622c5e3..29c82d4db7411a412c02d589247da60d4c59d6f7 100644 (file)
@@ -2,7 +2,7 @@
 
 from __future__ import absolute_import, division, with_statement
 import sys
-import unittest
+from tornado.test.util import unittest
 
 TEST_MODULES = [
     'tornado.httputil.doctests',
index dc717596a6687d8f1993f1d11503ab5decd4159d..d911d169135a8247a24e3b17e9c51b4ac0fa70ab 100644 (file)
@@ -3,12 +3,12 @@ from __future__ import absolute_import, division, with_statement
 
 from tornado.stack_context import StackContext, wrap
 from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, LogTrapTestCase
+from tornado.test.util import unittest
 from tornado.util import b
 from tornado.web import asynchronous, Application, RequestHandler
 import contextlib
 import functools
 import logging
-import unittest
 
 
 class TestRequestHandler(RequestHandler):
index 1de20df1c3d2ab92ffe7e988d5f69a21219547fe..77f55e7e5c69a6a666e914a02cd0df4fad47e3fe 100644 (file)
@@ -1,9 +1,9 @@
 #!/usr/bin/env python
 
 from __future__ import absolute_import, division, with_statement
-import unittest
 import time
 from tornado.testing import AsyncTestCase, LogTrapTestCase
+from tornado.test.util import unittest
 
 
 class AsyncTestCaseTest(AsyncTestCase, LogTrapTestCase):
index cd7fc60d938ac996890cf47ac3b7ae7dfeda0fbe..3178f94dd6f1389a2e9450da6fbf686bb7696139 100644 (file)
@@ -25,7 +25,6 @@ import signal
 import tempfile
 import thread
 import threading
-import unittest
 
 try:
     import fcntl
@@ -46,6 +45,7 @@ from tornado.httpclient import AsyncHTTPClient
 from tornado.ioloop import IOLoop
 from tornado.platform.auto import set_close_exec
 from tornado.testing import get_unused_port
+from tornado.test.util import unittest
 from tornado.util import import_object
 from tornado.web import RequestHandler, Application
 
diff --git a/tornado/test/util.py b/tornado/test/util.py
new file mode 100644 (file)
index 0000000..26d843d
--- /dev/null
@@ -0,0 +1,10 @@
+from __future__ import absolute_import, division, with_statement
+
+import sys
+
+# Encapsulate the choice of unittest or unittest2 here.
+# To be used as 'from tornado.test.util import unittest'.
+if sys.version_info >= (2, 7):
+    import unittest
+else:
+    import unittest2 as unittest
index 8707b0d58af1aa5d3c71582f6f0064e877f67303..338c16a96c6f89c7b1a4145283f731ca145c6276 100644 (file)
@@ -1,8 +1,8 @@
 from __future__ import absolute_import, division, with_statement
 import sys
-import unittest
 
 from tornado.util import raise_exc_info
+from tornado.test.util import unittest
 
 
 class RaiseExcInfoTest(unittest.TestCase):
@@ -23,4 +23,4 @@ class RaiseExcInfoTest(unittest.TestCase):
             raise_exc_info(exc_info)
             self.fail("didn't get expected exception")
         except TwoArgException, e:
-            self.assertTrue(e is exc_info[1])
+            self.assertIs(e, exc_info[1])
index c18f17be30c01dc872969476aeac2ea9ebb3b193..c597e3a77f1a9cb6acc832c42c11169fef2603e7 100644 (file)
@@ -41,7 +41,15 @@ import os
 import signal
 import sys
 import time
-import unittest
+
+# Tornado's own test suite requires the updated unittest module
+# (either py27+ or unittest2) so tornado.test.util enforces
+# this requirement, but for other users of tornado.testing we want
+# to allow the older version if unitest2 is not available.
+try:
+    import unittest2 as unittest
+except ImportError:
+    import unittest
 
 _next_port = 10000
 
diff --git a/tox.ini b/tox.ini
index e072d11960026edefc6bc95842759c48f6fbab3e..f4291e38518abb01e76756728100661844115b2e 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -28,7 +28,9 @@ changedir = {toxworkdir}
 
 [testenv:py25]
 basepython = python2.5
-deps = simplejson
+deps =
+     simplejson
+     unittest2
 
 [testenv:py25-full]
 basepython = python2.5
@@ -38,9 +40,14 @@ deps =
      simplejson
      # twisted is dropping python 2.5 support in 12.2.0
      twisted<=12.1.0
+     unittest2
      # zope.interface (used by twisted) dropped python 2.5 support in 4.0
      zope.interface<4.0
 
+[testenv:py26]
+basepython = python2.6
+deps = unittest2
+
 # py26-full deliberately runs an older version of twisted to ensure
 # we're still compatible with the oldest version we support.
 [testenv:py26-full]
@@ -49,6 +56,7 @@ deps =
      MySQL-python
      pycurl
      twisted==11.0.0
+     unittest2
 
 [testenv:py27-full]
 basepython = python2.7