Commits

Anonymous committed 4ca5dca Merge

Merged py2.7 fixes

  • Participants
  • Parent commits 34c6847, 92a11c7

Comments (0)

Files changed (13)

File functional_tests/test_buggy_generators.py

 from cStringIO import StringIO
 from nose.core import TestProgram
 from nose.config import Config
+from nose.result import _TextTestResult
 
 here = os.path.dirname(__file__)
 support = os.path.join(here, 'support')
 
 class TestRunner(unittest.TextTestRunner):
     def _makeResult(self):
-        self.result = unittest._TextTestResult(
+        self.result = _TextTestResult(
             self.stream, self.descriptions, self.verbosity)
         return self.result
 

File functional_tests/test_collector.py

 import unittest
 import warnings
 from cStringIO import StringIO
+from nose.result import _TextTestResult
 here = os.path.dirname(__file__)
 support = os.path.join(here, 'support')
 
 
 class TestRunner(unittest.TextTestRunner):
     def _makeResult(self):
-        self.result = unittest._TextTestResult(
+        self.result = _TextTestResult(
             self.stream, self.descriptions, self.verbosity)
         return self.result
     

File functional_tests/test_loader.py

 from nose.plugins.skip import Skip
 from nose import loader
 from nose import suite
+from nose.result import _TextTestResult
+try:
+    # 2.7+
+    from unittest.runner import _WritelnDecorator
+except ImportError:
+    from unittest import _WritelnDecorator
 
 support = os.path.abspath(os.path.join(os.path.dirname(__file__), 'support'))
 
         self.assertEqual(m.state, expect, diff(expect, m.state))
 
     def test_fixture_context_multiple_names_some_common_ancestors(self):
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, 2)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, 2)
         wd = os.path.join(support, 'ltfn')
         l = loader.TestLoader(workingDir=wd)
         suite = l.loadTestsFromNames(
         self.assertEqual(m.called, expect, diff(expect, m.called))
 
     def test_fixture_context_multiple_names_no_common_ancestors(self):
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, 2)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, 2)
         wd = os.path.join(support, 'ltfn')
         l = loader.TestLoader(workingDir=wd)
         suite = l.loadTestsFromNames(
         l = loader.TestLoader(workingDir=ctx)
         suite = l.loadTestsFromName('no_such_module.py')
 
-        res = unittest._TextTestResult(
-            stream=unittest._WritelnDecorator(sys.stdout),
+        res = _TextTestResult(
+            stream=_WritelnDecorator(sys.stdout),
             descriptions=0, verbosity=1)
         suite(res)
 
         l = loader.TestLoader(workingDir=ctx)
         suite = l.loadTestsFromName('no_such_module')
 
-        res = unittest._TextTestResult(
-            stream=unittest._WritelnDecorator(sys.stdout),
+        res = _TextTestResult(
+            stream=_WritelnDecorator(sys.stdout),
             descriptions=0, verbosity=1)
         suite(res)
         print res.errors
         l = loader.TestLoader(workingDir=ctx)
         suite = l.loadTestsFromName('fred!')
 
-        res = unittest._TextTestResult(
-            stream=unittest._WritelnDecorator(sys.stdout),
+        res = _TextTestResult(
+            stream=_WritelnDecorator(sys.stdout),
             descriptions=0, verbosity=1)
         suite(res)
         print res.errors
         gen = os.path.join(support, 'gen')
         l = loader.TestLoader(workingDir=gen)
         suite = l.loadTestsFromName('test')
-        res = unittest._TextTestResult(
-            stream=unittest._WritelnDecorator(sys.stdout),
+        res = _TextTestResult(
+            stream=_WritelnDecorator(sys.stdout),
             descriptions=0, verbosity=1)
         suite(res)
         assert not res.errors
         wdir = os.path.join(support, 'issue269')
         l = loader.TestLoader(workingDir=wdir)
         suite = l.loadTestsFromName('test_bad_class')
-        res = unittest._TextTestResult(
-            stream=unittest._WritelnDecorator(sys.stdout),
+        res = _TextTestResult(
+            stream=_WritelnDecorator(sys.stdout),
             descriptions=0, verbosity=1)
         suite(res)
         print res.errors

File functional_tests/test_program.py

 from nose.core import TestProgram
 from nose.config import Config
 from nose.plugins.manager import DefaultPluginManager
+from nose.result import _TextTestResult
 
 here = os.path.dirname(__file__)
 support = os.path.join(here, 'support')
 
 class TestRunner(unittest.TextTestRunner):
     def _makeResult(self):
-        self.result = unittest._TextTestResult(
+        self.result = _TextTestResult(
             self.stream, self.descriptions, self.verbosity)
         return self.result 
 

File nose/core.py

         self.config = config
         self.suite = suite
         self.exit = exit
+        extra_args = {}
+        if sys.version_info[0:2] >= (2,7):
+            extra_args['exit'] = exit
         unittest.TestProgram.__init__(
             self, module=module, defaultTest=defaultTest,
-            argv=argv, testRunner=testRunner, testLoader=testLoader)
+            argv=argv, testRunner=testRunner, testLoader=testLoader,
+            **extra_args)
 
     def makeConfig(self, env, plugins=None):
         """Load a Config, pre-filled with user config files if any are

File nose/plugins/errorclass.py

 
     >>> import sys
     >>> import unittest
-    >>> buf = unittest._WritelnDecorator(sys.stdout)
+    >>> try:
+    ...     # 2.7+
+    ...     from unittest.runner import _WritelnDecorator
+    ... except ImportError:
+    ...     from unittest import _WritelnDecorator
+    ... 
+    >>> buf = _WritelnDecorator(sys.stdout)
 
 Now define a test case that raises a Todo.
 
 each step.
 
     >>> plugin = TodoError()
-    >>> result = unittest._TextTestResult(stream=buf,
-    ...                                   descriptions=0, verbosity=2)
+    >>> from nose.result import _TextTestResult
+    >>> result = _TextTestResult(stream=buf, descriptions=0, verbosity=2)
     >>> plugin.prepareTestResult(result)
 
 Now run the test. TODO is printed.

File nose/plugins/multiprocess.py

 from nose.result import TextTestResult
 from nose.suite import ContextSuite
 from nose.util import test_address
+try:
+    # 2.7+
+    from unittest.runner import _WritelnDecorator
+except ImportError:
+    from unittest import _WritelnDecorator
 from Queue import Empty
 from warnings import warn
 try:
         return case
 
     def makeResult():
-        stream = unittest._WritelnDecorator(StringIO())
+        stream = _WritelnDecorator(StringIO())
         result = resultClass(stream, descriptions=1,
                              verbosity=config.verbosity,
                              config=config)

File nose/plugins/plugintest.py

             ...         raise ValueError("Now do something, plugin!")
             ... 
             >>> unittest.TestSuite([SomeTest()]) # doctest: +ELLIPSIS
-            <unittest.TestSuite tests=[<...SomeTest testMethod=runTest>]>
+            <unittest...TestSuite tests=[<...SomeTest testMethod=runTest>]>
         
         """
         raise NotImplementedError

File nose/result.py

 Test Result
 -----------
 
-Provides a TextTestResult that extends unittest._TextTestResult to
+Provides a TextTestResult that extends unittest's _TextTestResult to
 provide support for error classes (such as the builtin skip and
 deprecated classes), and hooks for plugins to take over or extend
 reporting.
 """
 
 import logging
-from unittest import _TextTestResult
+try:
+    # 2.7+
+    from unittest.runner import _TextTestResult
+except ImportError:
+    from unittest import _TextTestResult
 from nose.config import Config
 from nose.util import isclass, ln as _ln # backwards compat
 

File nose/suite.py

 _def = object()
 
 
+def _strclass(cls):
+    return "%s.%s" % (cls.__module__, cls.__name__)
+
 class MixedContextError(Exception):
     """Error raised when a context suite sees tests from more than
     one context.
         
     def __repr__(self):
         return "<%s tests=generator (%s)>" % (
-            unittest._strclass(self.__class__), id(self))
+            _strclass(self.__class__), id(self))
 
     def __hash__(self):
         return object.__hash__(self)
 
     def __repr__(self):
         return "<%s context=%s>" % (
-            unittest._strclass(self.__class__),
+            _strclass(self.__class__),
             getattr(self.context, '__name__', self.context))
     __str__ = __repr__
 

File unit_tests/test_deprecated_plugin.py

 import unittest
 from nose.config import Config
 from nose.plugins.deprecated import Deprecated, DeprecatedTest
-from nose.result import TextTestResult
+from nose.result import TextTestResult, _TextTestResult
 from StringIO import StringIO
 from optparse import OptionParser
+try:
+    # 2.7+
+    from unittest.runner import _WritelnDecorator
+except ImportError:
+    from unittest import _WritelnDecorator
 
 
 class TestDeprecatedPlugin(unittest.TestCase):
         sk.prepareTestResult        
 
     def test_prepare_patches_result(self):
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, 1)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, 1)
         sk = Deprecated()
         sk.prepareTestResult(res)
         res._orig_addError
             def test(self):
                 raise DeprecatedTest('deprecated me')
 
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, 1)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, 1)
         sk = Deprecated()
         sk.prepareTestResult(res)
 
             def test(self):
                 raise DeprecatedTest('deprecated me too')
         
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, verbosity=2)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, verbosity=2)
         sk = Deprecated()
         sk.prepareTestResult(res)
         test = TC('test')

File unit_tests/test_multiprocess.py

 from nose.plugins.skip import SkipTest
 from nose.config import Config
 from nose.loader import TestLoader
+try:
+    # 2.7+
+    from unittest.runner import _WritelnDecorator
+except ImportError:
+    from unittest import _WritelnDecorator
 
 
 class ArgChecker:
     config.multiprocess_workers = 2
     config.multiprocess_timeout = 0.1
     runner = multiprocess.MultiProcessTestRunner(
-        stream=unittest._WritelnDecorator(sys.stdout),
+        stream=_WritelnDecorator(sys.stdout),
         verbosity=2,
         loaderClass=TestLoader,
         config=config)

File unit_tests/test_skip_plugin.py

 from nose.plugins.skip import Skip, SkipTest
 from nose.result import TextTestResult
 from StringIO import StringIO
+from nose.result import _TextTestResult
 from optparse import OptionParser
+try:
+    # 2.7+
+    from unittest.runner import _WritelnDecorator
+except ImportError:
+    from unittest import _WritelnDecorator
 
 
 class TestSkipPlugin(unittest.TestCase):
         sk.prepareTestResult        
 
     def test_prepare_patches_result(self):
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, 1)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, 1)
         sk = Skip()
         sk.prepareTestResult(res)
         res._orig_addError
             def test(self):
                 raise SkipTest('skip me')
 
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, 1)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, 1)
         sk = Skip()
         sk.prepareTestResult(res)
 
             def test(self):
                 raise SkipTest('skip me too')
         
-        stream = unittest._WritelnDecorator(StringIO())
-        res = unittest._TextTestResult(stream, 0, verbosity=2)
+        stream = _WritelnDecorator(StringIO())
+        res = _TextTestResult(stream, 0, verbosity=2)
         sk = Skip()
         sk.prepareTestResult(res)
         test = TC('test')