Rev 5317: (lifeless) Polish and adjust news for Martin's output_encoding branch. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 23 09:14:29 BST 2010


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

------------------------------------------------------------
revno: 5317 [merge]
revision-id: pqm at pqm.ubuntu.com-20100623081421-53539k281zgrktsu
parent: pqm at pqm.ubuntu.com-20100622235834-85ugj691i2o5sxno
parent: robertc at robertcollins.net-20100621222938-2ca4dybx3c55huhn
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-06-23 09:14:21 +0100
message:
  (lifeless) Polish and adjust news for Martin's output_encoding branch.
   (Robert Collins)
added:
  bzrlib/tests/fixtures.py       fixtures.py-20100514150609-1kpa1jqaciel01wn-1
  bzrlib/tests/test_fixtures.py  test_fixtures.py-20100514150609-1kpa1jqaciel01wn-2
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_ui.py        test_ui.py-20051130162854-458e667a7414af09
  bzrlib/ui/__init__.py          ui.py-20050824083933-8cf663c763ba53a9
=== modified file 'NEWS'
--- a/NEWS	2010-06-22 22:40:29 +0000
+++ b/NEWS	2010-06-23 08:14:21 +0000
@@ -119,6 +119,10 @@
   formats is needed or when the format string for the object is
   encountered. (Robert Collins, Jelmer Vernooij)
 
+* The encoding that bzr uses to output things other than file content can
+  now be overridden via the output_encoding configuration option.
+  (Martin Pool, #340394)
+
 * Use lazy imports in ``bzrlib/merge.py`` so that plugins like ``news_merge``
   do not cause modules to be loaded unnecessarily just because the plugin
   registers a merge hook.  This improves ``bzr rocks`` time by about 25%
@@ -171,6 +175,9 @@
 Testing
 *******
 
+* Add ``bzrlib.tests.fixtures`` to hold code for setting up objects
+  to test.  (Martin Pool)
+
 * ``test_import_tariff`` now respects BZR_PLUGINS_AT and BZR_PLUGINS_DISABLE.
   (Vincent Ladeuil, #595587)
 

=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt	2010-06-02 05:03:31 +0000
+++ b/bzrlib/help_topics/en/configuration.txt	2010-06-21 22:29:38 +0000
@@ -496,6 +496,17 @@
     using deprecated formats.
 
 
+Unicode options
+---------------
+
+output_encoding
+~~~~~~~~~~~~~~~
+
+A Python unicode encoding name for text output from bzr, such as log
+information.  Values include: utf8, cp850, ascii, iso-8859-1.  The default
+is the terminal encoding prefered by the operating system.
+
+
 Branch type specific options
 ----------------------------
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-06-08 01:42:50 +0000
+++ b/bzrlib/tests/__init__.py	2010-06-21 22:29:38 +0000
@@ -3704,6 +3704,7 @@
         'bzrlib.tests.test_export',
         'bzrlib.tests.test_extract',
         'bzrlib.tests.test_fetch',
+        'bzrlib.tests.test_fixtures',
         'bzrlib.tests.test_fifo_cache',
         'bzrlib.tests.test_filters',
         'bzrlib.tests.test_ftp_transport',
@@ -3839,6 +3840,7 @@
         'bzrlib.option',
         'bzrlib.symbol_versioning',
         'bzrlib.tests',
+        'bzrlib.tests.fixtures',
         'bzrlib.timestamp',
         'bzrlib.version_info_formats.format_custom',
         ]

=== added file 'bzrlib/tests/fixtures.py'
--- a/bzrlib/tests/fixtures.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/fixtures.py	2010-06-21 22:29:38 +0000
@@ -0,0 +1,84 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+"""Fixtures that can be used within tests.
+
+Fixtures can be created during a test as a way to separate out creation of
+objects to test.  Fixture objects can hold some state so that different 
+objects created during a test instance can be related.  Normally a fixture
+should live only for the duration of a single test, and its tearDown method
+should be passed to `addCleanup` on the test.
+"""
+
+
+import itertools
+
+
+def generate_unicode_names():
+    """Generate a sequence of arbitrary unique unicode names.
+    
+    By default they are not representable in ascii.
+    
+    >>> gen = generate_unicode_names()
+    >>> n1 = gen.next()
+    >>> n2 = gen.next()
+    >>> type(n1)
+    <type 'unicode'>
+    >>> n1 == n2
+    False
+    >>> n1.encode('ascii', 'replace') == n1
+    False
+    """
+    # include a mathematical symbol unlikely to be in 8-bit encodings
+    return (u"\N{SINE WAVE}%d" % x for x in itertools.count())
+
+
+interesting_encodings = [
+    ('iso-8859-1', False),
+    ('ascii', False),
+    ('cp850', False),
+    ('utf-8', True),
+    ('ucs-2', True),
+    ]
+
+
+def generate_unicode_encodings(universal_encoding=None):
+    """Return a generator of unicode encoding names.
+
+    These can be passed to Python encode/decode/etc.
+    
+    :param universal_encoding: True/False/None tristate to say whether the
+        generated encodings either can or cannot encode all unicode 
+        strings.
+
+    >>> n1 = generate_unicode_names().next()
+    >>> enc = generate_unicode_encodings(universal_encoding=True).next()
+    >>> enc2 = generate_unicode_encodings(universal_encoding=False).next()
+    >>> n1.encode(enc).decode(enc) == n1
+    True
+    >>> try:
+    ...   n1.encode(enc2).decode(enc2)
+    ... except UnicodeError:
+    ...   print 'fail'
+    fail
+    """
+    # TODO: check they're supported on this platform?
+    if universal_encoding is not None:
+        e = [n for (n, u) in interesting_encodings if u == universal_encoding]
+    else:
+        e = [n for (n, u) in interesting_encodings]
+    return itertools.cycle(iter(e))

=== added file 'bzrlib/tests/test_fixtures.py'
--- a/bzrlib/tests/test_fixtures.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_fixtures.py	2010-06-21 22:29:38 +0000
@@ -0,0 +1,28 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests for test fixtures"""
+
+import codecs
+
+from bzrlib import (
+    tests,
+    )
+from bzrlib.tests import (
+    fixtures,
+    )
+
+

=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2010-05-20 18:23:17 +0000
+++ b/bzrlib/tests/test_ui.py	2010-06-21 22:29:38 +0000
@@ -24,6 +24,7 @@
 from StringIO import StringIO
 
 from bzrlib import (
+    config,
     errors,
     remote,
     repository,
@@ -33,10 +34,26 @@
 from bzrlib.symbol_versioning import (
     deprecated_in,
     )
-from bzrlib.tests import test_progress
+from bzrlib.tests import (
+    fixtures,
+    test_progress,
+    )
 from bzrlib.ui import text as _mod_ui_text
 
 
+class TestUIConfiguration(tests.TestCaseWithTransport):
+
+    def test_output_encoding_configuration(self):
+        enc = fixtures.generate_unicode_encodings().next()
+        config.GlobalConfig().set_user_option('output_encoding',
+            enc)
+        ui = tests.TestUIFactory(stdin=None,
+            stdout=tests.StringIOWrapper(),
+            stderr=tests.StringIOWrapper())
+        os = ui.make_output_stream()
+        self.assertEquals(os.encoding, enc)
+
+
 class TestTextUIFactory(tests.TestCase):
 
     def test_text_factory_ascii_password(self):

=== modified file 'bzrlib/ui/__init__.py'
--- a/bzrlib/ui/__init__.py	2010-06-21 20:03:23 +0000
+++ b/bzrlib/ui/__init__.py	2010-06-23 08:14:21 +0000
@@ -178,8 +178,9 @@
         version of stdout, but in a GUI it might be appropriate to send it to a 
         window displaying the text.
      
-        :param encoding: Unicode encoding for output; default is the 
-            terminal encoding, which may be different from the user encoding.
+        :param encoding: Unicode encoding for output; if not specified 
+            uses the configured 'output_encoding' if any; otherwise the 
+            terminal encoding. 
             (See get_terminal_encoding.)
 
         :param encoding_type: How to handle encoding errors:
@@ -187,6 +188,10 @@
         """
         # XXX: is the caller supposed to close the resulting object?
         if encoding is None:
+            from bzrlib import config
+            encoding = config.GlobalConfig().get_user_option(
+                'output_encoding')
+        if encoding is None:
             encoding = osutils.get_terminal_encoding()
         if encoding_type is None:
             encoding_type = 'replace'




More information about the bazaar-commits mailing list