← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~gz/testtools/trivial_all_function_in_compat_688724 into lp:testtools

 

Martin [gz] has proposed merging lp:~gz/testtools/trivial_all_function_in_compat_688724 into lp:testtools with lp:~gz/testtools/raises_regressions_675327 as a prerequisite.

Requested reviews:
  testtools developers (testtools-dev)
Related bugs:
  #688724 MultiTestResult.wasSuccessful broken in Python 2.4
  https://bugs.launchpad.net/bugs/688724


Implements the 'all' function for Python 2.4 and exposes it from testtools.compat so the wasSuccessful method that needs it will work. With this way of doing things, any code that wants to use 'all' will have to import it explicitly.

Note, this branch depends on the fix for bug 675327.
-- 
https://code.launchpad.net/~gz/testtools/trivial_all_function_in_compat_688724/+merge/43409
Your team testtools developers is requested to review the proposed merge of lp:~gz/testtools/trivial_all_function_in_compat_688724 into lp:testtools.
=== modified file 'testtools/compat.py'
--- testtools/compat.py	2010-11-19 18:11:39 +0000
+++ testtools/compat.py	2010-12-11 00:11:31 +0000
@@ -65,27 +65,58 @@
 _u.__doc__ = __u_doc
 
 
-if sys.version_info > (2, 5):
-    _error_repr = BaseException.__repr__
-    def isbaseexception(exception):
-        """Return whether exception inherits from BaseException only"""
-        return (isinstance(exception, BaseException)
-            and not isinstance(exception, Exception))
-else:
-    def _error_repr(exception):
-        """Format an exception instance as Python 2.5 and later do"""
-        return exception.__class__.__name__ + repr(exception.args)
-    def isbaseexception(exception):
-        """Return whether exception would inherit from BaseException only
-
-        This approximates the hierarchy in Python 2.5 and later, compare the
-        difference between the diagrams at the bottom of the pages:
-        <http://docs.python.org/release/2.4.4/lib/module-exceptions.html>
-        <http://docs.python.org/release/2.5.4/lib/module-exceptions.html>
-        """
-        return isinstance(exception, (KeyboardInterrupt, SystemExit))
-
-
+<<<<<<< TREE
+if sys.version_info > (2, 5):
+    _error_repr = BaseException.__repr__
+    def isbaseexception(exception):
+        """Return whether exception inherits from BaseException only"""
+        return (isinstance(exception, BaseException)
+            and not isinstance(exception, Exception))
+else:
+    def _error_repr(exception):
+        """Format an exception instance as Python 2.5 and later do"""
+        return exception.__class__.__name__ + repr(exception.args)
+    def isbaseexception(exception):
+        """Return whether exception would inherit from BaseException only
+
+        This approximates the hierarchy in Python 2.5 and later, compare the
+        difference between the diagrams at the bottom of the pages:
+        <http://docs.python.org/release/2.4.4/lib/module-exceptions.html>
+        <http://docs.python.org/release/2.5.4/lib/module-exceptions.html>
+        """
+        return isinstance(exception, (KeyboardInterrupt, SystemExit))
+
+
+=======
+if sys.version_info > (2, 5):
+    all = all
+    _error_repr = BaseException.__repr__
+    def isbaseexception(exception):
+        """Return whether exception inherits from BaseException only"""
+        return (isinstance(exception, BaseException)
+            and not isinstance(exception, Exception))
+else:
+    def all(iterable):
+        """If contents of iterable all evaluate as boolean True"""
+        for obj in iterable:
+            if not obj:
+                return False
+        return True
+    def _error_repr(exception):
+        """Format an exception instance as Python 2.5 and later do"""
+        return exception.__class__.__name__ + repr(exception.args)
+    def isbaseexception(exception):
+        """Return whether exception would inherit from BaseException only
+
+        This approximates the hierarchy in Python 2.5 and later, compare the
+        difference between the diagrams at the bottom of the pages:
+        <http://docs.python.org/release/2.4.4/lib/module-exceptions.html>
+        <http://docs.python.org/release/2.5.4/lib/module-exceptions.html>
+        """
+        return isinstance(exception, (KeyboardInterrupt, SystemExit))
+
+
+>>>>>>> MERGE-SOURCE
 def unicode_output_stream(stream):
     """Get wrapper for given stream that writes any unicode without exception
 

=== modified file 'testtools/testresult/real.py'
--- testtools/testresult/real.py	2010-12-05 23:58:48 +0000
+++ testtools/testresult/real.py	2010-12-11 00:11:31 +0000
@@ -14,7 +14,7 @@
 import sys
 import unittest
 
-from testtools.compat import _format_exc_info, str_is_unicode, _u
+from testtools.compat import all, _format_exc_info, str_is_unicode, _u
 
 
 class TestResult(unittest.TestResult):

=== modified file 'testtools/tests/test_run.py'
--- testtools/tests/test_run.py	2010-12-10 23:38:16 +0000
+++ testtools/tests/test_run.py	2010-12-11 00:11:31 +0000
@@ -1,3 +1,4 @@
+<<<<<<< TREE
 # Copyright (c) 2010 Testtools authors. See LICENSE for details.
 
 """Tests for the test runner logic."""
@@ -74,3 +75,82 @@
 def test_suite():
     from unittest import TestLoader
     return TestLoader().loadTestsFromName(__name__)
+=======
+# Copyright (c) 2010 Testtools authors. See LICENSE for details.
+
+"""Tests for the test runner logic."""
+
+import StringIO
+
+from testtools.helpers import try_import
+fixtures = try_import('fixtures')
+
+import testtools
+from testtools import TestCase, run
+
+
+if fixtures:
+    class SampleTestFixture(fixtures.Fixture):
+        """Creates testtools.runexample temporarily."""
+
+        def __init__(self):
+            self.package = fixtures.PythonPackage(
+            'runexample', [('__init__.py', """
+from testtools import TestCase
+
+class TestFoo(TestCase):
+    def test_bar(self):
+        pass
+    def test_quux(self):
+        pass
+def test_suite():
+    from unittest import TestLoader
+    return TestLoader().loadTestsFromName(__name__)
+""")])
+
+        def setUp(self):
+            super(SampleTestFixture, self).setUp()
+            self.useFixture(self.package)
+            testtools.__path__.append(self.package.base)
+            self.addCleanup(testtools.__path__.remove, self.package.base)
+
+
+class TestRun(TestCase):
+
+    def test_run_list(self):
+        if fixtures is None:
+            self.skipTest("Need fixtures")
+        package = self.useFixture(SampleTestFixture())
+        out = StringIO.StringIO()
+        run.main(['prog', '-l', 'testtools.runexample.test_suite'], out)
+        self.assertEqual("""testtools.runexample.TestFoo.test_bar
+testtools.runexample.TestFoo.test_quux
+""", out.getvalue())
+
+    def test_run_load_list(self):
+        if fixtures is None:
+            self.skipTest("Need fixtures")
+        package = self.useFixture(SampleTestFixture())
+        out = StringIO.StringIO()
+        # We load two tests - one that exists and one that doesn't, and we
+        # should get the one that exists and neither the one that doesn't nor
+        # the unmentioned one that does.
+        tempdir = self.useFixture(fixtures.TempDir())
+        tempname = tempdir.path + '/tests.list'
+        f = open(tempname, 'wb')
+        try:
+            f.write("""
+testtools.runexample.TestFoo.test_bar
+testtools.runexample.missingtest
+""")
+        finally:
+            f.close()
+        run.main(['prog', '-l', '--load-list', tempname,
+            'testtools.runexample.test_suite'], out)
+        self.assertEqual("""testtools.runexample.TestFoo.test_bar
+""", out.getvalue())
+
+def test_suite():
+    from unittest import TestLoader
+    return TestLoader().loadTestsFromName(__name__)
+>>>>>>> MERGE-SOURCE


Follow ups