PATCH] TextTestFixture report error

Henri Wiechers hwiechers at gmail.com
Sun Nov 12 07:47:42 GMT 2006


This patch fixes a bug that is currently crashing selftest on Windows.
The problem occurs in the TextTestResult error reporting functions.
They do something like this:

self.pb.note('FAIL: %s\n    %s\n' % (
   self._shortened_test_description(test),
   err[1],
   ))

The problem is that err[1] may contain %'s. ProgressBar.note() then
gets a format string without enough arguments. This causes a TypeError
and a selftest crash.

The patch changes all the note() calls to something like this:

self.pb.note('FAIL: %s\n    %s\n',
   self._shortened_test_description(test),
   err[1],
   )

In this case note() does the formatting and this isn't a problem anymore.

----

My last couple of patches have been screwed due to encoding problems.
If this one is also bad, I'll try something else and resend it.
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Changed TextTestResult's report methods to avoid % formatting in calls to ProgressBar.note(), instead args are passed and note() handles the formatting. This prevents bugs where note() might be passed a string with %'s in it because one of the args contain %'s.
# committer: Henri Wiechers <hwiechers at gmail.com>
# date: Sat 2006-11-11 19:33:35.453000069 +0200

=== modified file bzrlib/tests/__init__.py
--- bzrlib/tests/__init__.py
+++ bzrlib/tests/__init__.py
@@ -323,17 +323,17 @@
 
     def report_error(self, test, err):
         self.error_count += 1
-        self.pb.note('ERROR: %s\n    %s\n' % (
+        self.pb.note('ERROR: %s\n    %s\n', 
             self._shortened_test_description(test),
             err[1],
-            ))
+            )
 
     def report_failure(self, test, err):
         self.failure_count += 1
-        self.pb.note('FAIL: %s\n    %s\n' % (
+        self.pb.note('FAIL: %s\n    %s\n', 
             self._shortened_test_description(test),
             err[1],
-            ))
+            )
 
     def report_skip(self, test, skip_excinfo):
         self.skip_count += 1
@@ -343,13 +343,13 @@
             # to see them.
             if False:
                 # show test and reason for skip
-                self.pb.note('SKIP: %s\n    %s\n' % (
+                self.pb.note('SKIP: %s\n    %s\n', 
                     self._shortened_test_description(test),
-                    skip_excinfo[1]))
+                    skip_excinfo[1])
             else:
                 # since the class name was left behind in the still-visible
                 # progress bar...
-                self.pb.note('SKIP: %s' % (skip_excinfo[1]))
+                self.pb.note('SKIP: %s', skip_excinfo[1])
 
     def report_cleaning_up(self):
         self.pb.update('cleaning up...')

=== modified directory  // last-changed:hwiechers at gmail.com-20061111173335-d7ce
... 214babe3e9eb
# revision id: hwiechers at gmail.com-20061111173335-d7ce214babe3e9eb
# sha1: 4be9be72e45f454286ddc4b212120c38e24f5068
# inventory sha1: 1bc43d649112eff7cf202500d79f409ab94fac6c
# parent ids:
#   pqm at pqm.ubuntu.com-20061111010134-ead5a1dce74d0836
# base id: pqm at pqm.ubuntu.com-20061111010134-ead5a1dce74d0836
# properties:
#   branch-nick: winfix_report_failure



More information about the bazaar mailing list