Rev 6572: Fix LC_ALL=C test failures related to utf8 stderr encoding in file:///home/vila/src/bzr/bugs/1086209-lc-all-c/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Dec 4 14:21:42 UTC 2012


At file:///home/vila/src/bzr/bugs/1086209-lc-all-c/

------------------------------------------------------------
revno: 6572
revision-id: v.ladeuil+lp at free.fr-20121204142142-mx8v8k2o5k3yi1ex
parent: pqm at pqm.ubuntu.com-20121025111327-p0ylql0nh9fla0rs
fixes bug: https://launchpad.net/bugs/1086209
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 1086209-lc-all-c
timestamp: Tue 2012-12-04 15:21:42 +0100
message:
  Fix LC_ALL=C test failures related to utf8 stderr encoding
-------------- next part --------------
=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2012-09-17 09:06:56 +0000
+++ b/bzrlib/tests/test_ui.py	2012-12-04 14:21:42 +0000
@@ -103,7 +103,6 @@
         ui.stdout = tests.StringIOWrapper()
         ui.stderr = tests.StringIOWrapper()
         ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
-        pb = ui.nested_progress_bar()
         password = ui.get_password(u'Hello \u1234 %(user)s', user=u'some\u1234')
         self.assertEqual(u'baz\u1234', password)
         self.assertEqual(u'Hello \u1234 some\u1234: ',

=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py	2012-10-10 18:45:21 +0000
+++ b/bzrlib/ui/text.py	2012-12-04 14:21:42 +0000
@@ -336,7 +336,13 @@
         if kwargs:
             # See <https://launchpad.net/bugs/365891>
             prompt = prompt % kwargs
-        prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
+        try:
+            prompt = prompt.encode(self.stderr.encoding)
+        except (UnicodeError, AttributeError):
+            # If stderr has no encoding attribute or can't properly encode,
+            # fallback to terminal encoding for robustness (better display
+            # something to the user than aborting with a traceback).
+            prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
         self.clear_term()
         self.stdout.flush()
         self.stderr.write(prompt)

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-10-23 10:22:25 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-12-04 14:21:42 +0000
@@ -104,9 +104,9 @@
 Testing
 *******
 
-.. Fixes and changes that are only relevant to bzr's test framework and 
-   suite.  This can include new facilities for writing tests, fixes to 
-   spurious test failures and changes to the way things should be tested.
+* Fix test failures occurring only with LC_ALL=C, when prompting a user,
+  ``stdee`` encoding should be preferred over terminal encoding if
+  available. (Vincent Ladeuil, #1086209)
 
 
 bzr 2.6b2



More information about the bazaar-commits mailing list