Rev 5551: (gz) Backslash escape selftest output when printing to non-unicode consoles in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Nov 24 18:09:34 GMT 2010


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

------------------------------------------------------------
revno: 5551 [merge]
revision-id: pqm at pqm.ubuntu.com-20101124180929-wxyctfo7dlfa0las
parent: pqm at pqm.ubuntu.com-20101124172055-79va5spncm8wu6ay
parent: gzlist at googlemail.com-20101119230319-qxzpitj2x2p5iuqh
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-11-24 18:09:29 +0000
message:
  (gz) Backslash escape selftest output when printing to non-unicode consoles
   (Martin [gz])
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-11-19 22:58:31 +0000
+++ b/bzrlib/tests/__init__.py	2010-11-19 23:03:19 +0000
@@ -651,7 +651,10 @@
             encode = codec[0]
         else:
             encode = codec.encode
-        stream = osutils.UnicodeOrBytesToBytesWriter(encode, stream)
+        # GZ 2010-09-08: Really we don't want to be writing arbitrary bytes,
+        #                so should swap to the plain codecs.StreamWriter
+        stream = osutils.UnicodeOrBytesToBytesWriter(encode, stream,
+            "backslashreplace")
         stream.encoding = new_encoding
         self.stream = stream
         self.descriptions = descriptions

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2010-10-15 11:20:45 +0000
+++ b/bzrlib/tests/test_selftest.py	2010-11-19 23:03:19 +0000
@@ -1282,6 +1282,23 @@
         result = self.run_test_runner(runner, test)
         self.assertLength(1, calls)
 
+    def test_unicode_test_output_on_ascii_stream(self):
+        """Showing results should always succeed even on an ascii console"""
+        class FailureWithUnicode(tests.TestCase):
+            def test_log_unicode(self):
+                self.log(u"\u2606")
+                self.fail("Now print that log!")
+        out = StringIO()
+        self.overrideAttr(osutils, "get_terminal_encoding",
+            lambda trace=False: "ascii")
+        result = self.run_test_runner(tests.TextTestRunner(stream=out),
+            FailureWithUnicode("test_log_unicode"))
+        self.assertContainsRe(out.getvalue(),
+            "Text attachment: log\n"
+            "-+\n"
+            "\d+\.\d+  \\\\u2606\n"
+            "-+\n")
+
 
 class SampleTestCase(tests.TestCase):
 

=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt	2010-11-24 17:20:55 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2010-11-24 18:09:29 +0000
@@ -112,6 +112,10 @@
   to 0.9.5 which will allow tests that need the fixed unicode handling to be
   written. (Martin [gz])
 
+* Printing selftest results to a non-UTF-8 console will now escape characters
+  that can't be encoded rather than aborting the test run with an exception.
+  (Martin [gz], #633216)
+
 
 bzr 2.3b3
 #########




More information about the bazaar-commits mailing list