Rev 5888: (gz) Make test unexpected successes count as failures (Martin [gz]) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed May 18 09:11:42 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5888 [merge]
revision-id: pqm at pqm.ubuntu.com-20110518091137-0b8tbe13tfw14ogn
parent: pqm at pqm.ubuntu.com-20110518033943-sgm50fqtljmq8ixc
parent: gzlist at googlemail.com-20110517170358-fonomozaw65x4od2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-05-18 09:11:37 +0000
message:
  (gz) Make test unexpected successes count as failures (Martin [gz])
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/per_workingtree/test_smart_add.py test_smart_add.py-20070215175752-9s5mxoz8aqpd80fm-1
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-05-16 23:19:29 +0000
+++ b/bzrlib/tests/__init__.py	2011-05-17 17:03:58 +0000
@@ -449,6 +449,19 @@
         self.known_failure_count += 1
         self.report_known_failure(test, err)
 
+    def addUnexpectedSuccess(self, test, details=None):
+        """Tell result the test unexpectedly passed, counting as a failure
+
+        When the minimum version of testtools required becomes 0.9.8 this
+        can be updated to use the new handling there.
+        """
+        super(ExtendedTestResult, self).addFailure(test, details=details)
+        self.failure_count += 1
+        self.report_unexpected_success(test,
+            "".join(details["reason"].iter_text()))
+        if self.stop_early:
+            self.stop()
+
     def addNotSupported(self, test, feature):
         """The test will not be run because of a missing feature.
         """
@@ -613,6 +626,13 @@
     def report_known_failure(self, test, err):
         pass
 
+    def report_unexpected_success(self, test, reason):
+        self.stream.write('FAIL: %s\n    %s: %s\n' % (
+            self._test_description(test),
+            "Unexpected success. Should have failed",
+            reason,
+            ))
+
     def report_skip(self, test, reason):
         pass
 
@@ -670,6 +690,12 @@
                 % (self._testTimeString(test),
                    self._error_summary(err)))
 
+    def report_unexpected_success(self, test, reason):
+        self.stream.write(' FAIL %s\n%s: %s\n'
+                % (self._testTimeString(test),
+                   "Unexpected success. Should have failed",
+                   reason))
+
     def report_success(self, test):
         self.stream.write('   OK %s\n' % self._testTimeString(test))
         for bench_called, stats in getattr(test, '_benchcalls', []):

=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
--- a/bzrlib/tests/per_workingtree/test_smart_add.py	2011-05-04 21:10:36 +0000
+++ b/bzrlib/tests/per_workingtree/test_smart_add.py	2011-05-17 10:18:58 +0000
@@ -296,15 +296,25 @@
         self.wt = self.make_branch_and_tree('.')
         self.overrideAttr(osutils, 'normalized_filename')
 
+    def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
+        """Adding unnormalized unicode filenames fail if and only if the
+        workingtree format has the requires_normalized_unicode_filenames flag
+        set.
+        """
+        osutils.normalized_filename = osutils._accessible_normalized_filename
+        if self.workingtree_format.requires_normalized_unicode_filenames:
+            self.assertRaises(
+                errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
+        else:
+            self.wt.smart_add([u'a\u030a'])
+
     def test_accessible_explicit(self):
         osutils.normalized_filename = osutils._accessible_normalized_filename
         if self.workingtree_format.requires_normalized_unicode_filenames:
-            self.expectFailure(
-                'Working tree format smart_add requires normalized unicode filenames',
-                self.assertRaises, errors.NoSuchFile,
-                self.wt.smart_add, [u'a\u030a'])
-        else:
-            self.wt.smart_add([u'a\u030a'])
+            raise tests.TestNotApplicable(
+                'Working tree format smart_add requires normalized unicode '
+                'filenames')
+        self.wt.smart_add([u'a\u030a'])
         self.wt.lock_read()
         self.addCleanup(self.wt.unlock)
         self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
@@ -314,12 +324,10 @@
     def test_accessible_implicit(self):
         osutils.normalized_filename = osutils._accessible_normalized_filename
         if self.workingtree_format.requires_normalized_unicode_filenames:
-            self.expectFailure(
-                'Working tree format smart_add requires normalized unicode filenames',
-                self.assertRaises, errors.NoSuchFile,
-                self.wt.smart_add, [])
-        else:
-            self.wt.smart_add([])
+            raise tests.TestNotApplicable(
+                'Working tree format smart_add requires normalized unicode '
+                'filenames')
+        self.wt.smart_add([])
         self.wt.lock_read()
         self.addCleanup(self.wt.unlock)
         self.assertEqual([('', 'directory'), (u'\xe5', 'file')],

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-05-16 17:20:43 +0000
@@ -1083,6 +1083,24 @@
             '\n'
             'OK \\(known_failures=1\\)\n')
 
+    def test_unexpected_success_bad(self):
+        class Test(tests.TestCase):
+            def test_truth(self):
+                self.expectFailure("No absolute truth", self.assertTrue, True)
+        runner = tests.TextTestRunner(stream=StringIO())
+        result = self.run_test_runner(runner, Test("test_truth"))
+        self.assertContainsRe(runner.stream.getvalue(),
+            "=+\n"
+            "FAIL: \\S+\.test_truth\n"
+            "-+\n"
+            "(?:.*\n)*"
+            "No absolute truth\n"
+            "(?:.*\n)*"
+            "-+\n"
+            "Ran 1 test in .*\n"
+            "\n"
+            "FAILED \\(failures=1\\)\n\\Z")
+
     def test_result_decorator(self):
         # decorate results
         calls = []

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-05-18 01:02:52 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-05-18 09:11:37 +0000
@@ -150,6 +150,9 @@
    suite.  This can include new facilities for writing tests, fixes to 
    spurious test failures and changes to the way things should be tested.
 
+* A test that was expected to fail but passes instead now counts as a failure
+  catching up with new testtools and subunit handling. (Martin [GZ], #654474)
+
 * Make it easier for plugins to reuse the per_workingtree scenarios by
   restoring the wt_scenarios helper that was accidentally deleted.
   (Vincent Ladeuil, #783472)




More information about the bazaar-commits mailing list