Merge lp:~lifeless/bzr/encoding-option into lp:bzr

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 5317
Proposed branch: lp:~lifeless/bzr/encoding-option
Merge into: lp:bzr
Diff against target: 255 lines (+157/-3)
7 files modified
NEWS (+7/-0)
bzrlib/help_topics/en/configuration.txt (+11/-0)
bzrlib/tests/__init__.py (+2/-0)
bzrlib/tests/fixtures.py (+84/-0)
bzrlib/tests/test_fixtures.py (+28/-0)
bzrlib/tests/test_ui.py (+18/-1)
bzrlib/ui/__init__.py (+7/-2)
To merge this branch: bzr merge lp:~lifeless/bzr/encoding-option
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+28126@code.launchpad.net

Commit message

Polish and adjust news for Martin's output_encoding branch.

Description of the change

Martins branch, NEWS moved to the right section, the config option added
to NEWS, copyright changed to 2010 for the new files.

Hmm, I may have missed the man page stuff, I think there is a bug open
about it not using the configuration help - but we should just fix that
bug.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

discussed it on the phone with poolie yesterday - marking approved now as it gives martin[gz] a test vehicle, and the questions I had are addressed.

Revision history for this message
Robert Collins (lifeless) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-06-21 04:16:16 +0000
+++ NEWS 2010-06-21 22:33:25 +0000
@@ -114,6 +114,10 @@
114 formats is needed or when the format string for the object is114 formats is needed or when the format string for the object is
115 encountered. (Robert Collins, Jelmer Vernooij)115 encountered. (Robert Collins, Jelmer Vernooij)
116116
117* The encoding that bzr uses to output things other than file content can
118 now be overridden via the output_encoding configuration option.
119 (Martin Pool, #340394)
120
117* Use lazy imports in ``bzrlib/merge.py`` so that plugins like ``news_merge``121* Use lazy imports in ``bzrlib/merge.py`` so that plugins like ``news_merge``
118 do not cause modules to be loaded unnecessarily just because the plugin122 do not cause modules to be loaded unnecessarily just because the plugin
119 registers a merge hook. This improves ``bzr rocks`` time by about 25%123 registers a merge hook. This improves ``bzr rocks`` time by about 25%
@@ -166,6 +170,9 @@
166Testing170Testing
167*******171*******
168172
173* Add ``bzrlib.tests.fixtures`` to hold code for setting up objects
174 to test. (Martin Pool)
175
169* ``test_import_tariff`` now respects BZR_PLUGINS_AT and BZR_PLUGINS_DISABLE.176* ``test_import_tariff`` now respects BZR_PLUGINS_AT and BZR_PLUGINS_DISABLE.
170 (Vincent Ladeuil, #595587)177 (Vincent Ladeuil, #595587)
171178
172179
=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- bzrlib/help_topics/en/configuration.txt 2010-06-02 05:03:31 +0000
+++ bzrlib/help_topics/en/configuration.txt 2010-06-21 22:33:25 +0000
@@ -496,6 +496,17 @@
496 using deprecated formats.496 using deprecated formats.
497497
498498
499Unicode options
500---------------
501
502output_encoding
503~~~~~~~~~~~~~~~
504
505A Python unicode encoding name for text output from bzr, such as log
506information. Values include: utf8, cp850, ascii, iso-8859-1. The default
507is the terminal encoding prefered by the operating system.
508
509
499Branch type specific options510Branch type specific options
500----------------------------511----------------------------
501512
502513
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2010-06-08 01:42:50 +0000
+++ bzrlib/tests/__init__.py 2010-06-21 22:33:25 +0000
@@ -3704,6 +3704,7 @@
3704 'bzrlib.tests.test_export',3704 'bzrlib.tests.test_export',
3705 'bzrlib.tests.test_extract',3705 'bzrlib.tests.test_extract',
3706 'bzrlib.tests.test_fetch',3706 'bzrlib.tests.test_fetch',
3707 'bzrlib.tests.test_fixtures',
3707 'bzrlib.tests.test_fifo_cache',3708 'bzrlib.tests.test_fifo_cache',
3708 'bzrlib.tests.test_filters',3709 'bzrlib.tests.test_filters',
3709 'bzrlib.tests.test_ftp_transport',3710 'bzrlib.tests.test_ftp_transport',
@@ -3839,6 +3840,7 @@
3839 'bzrlib.option',3840 'bzrlib.option',
3840 'bzrlib.symbol_versioning',3841 'bzrlib.symbol_versioning',
3841 'bzrlib.tests',3842 'bzrlib.tests',
3843 'bzrlib.tests.fixtures',
3842 'bzrlib.timestamp',3844 'bzrlib.timestamp',
3843 'bzrlib.version_info_formats.format_custom',3845 'bzrlib.version_info_formats.format_custom',
3844 ]3846 ]
38453847
=== added file 'bzrlib/tests/fixtures.py'
--- bzrlib/tests/fixtures.py 1970-01-01 00:00:00 +0000
+++ bzrlib/tests/fixtures.py 2010-06-21 22:33:25 +0000
@@ -0,0 +1,84 @@
1# Copyright (C) 2010 Canonical Ltd
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
18"""Fixtures that can be used within tests.
19
20Fixtures can be created during a test as a way to separate out creation of
21objects to test. Fixture objects can hold some state so that different
22objects created during a test instance can be related. Normally a fixture
23should live only for the duration of a single test, and its tearDown method
24should be passed to `addCleanup` on the test.
25"""
26
27
28import itertools
29
30
31def generate_unicode_names():
32 """Generate a sequence of arbitrary unique unicode names.
33
34 By default they are not representable in ascii.
35
36 >>> gen = generate_unicode_names()
37 >>> n1 = gen.next()
38 >>> n2 = gen.next()
39 >>> type(n1)
40 <type 'unicode'>
41 >>> n1 == n2
42 False
43 >>> n1.encode('ascii', 'replace') == n1
44 False
45 """
46 # include a mathematical symbol unlikely to be in 8-bit encodings
47 return (u"\N{SINE WAVE}%d" % x for x in itertools.count())
48
49
50interesting_encodings = [
51 ('iso-8859-1', False),
52 ('ascii', False),
53 ('cp850', False),
54 ('utf-8', True),
55 ('ucs-2', True),
56 ]
57
58
59def generate_unicode_encodings(universal_encoding=None):
60 """Return a generator of unicode encoding names.
61
62 These can be passed to Python encode/decode/etc.
63
64 :param universal_encoding: True/False/None tristate to say whether the
65 generated encodings either can or cannot encode all unicode
66 strings.
67
68 >>> n1 = generate_unicode_names().next()
69 >>> enc = generate_unicode_encodings(universal_encoding=True).next()
70 >>> enc2 = generate_unicode_encodings(universal_encoding=False).next()
71 >>> n1.encode(enc).decode(enc) == n1
72 True
73 >>> try:
74 ... n1.encode(enc2).decode(enc2)
75 ... except UnicodeError:
76 ... print 'fail'
77 fail
78 """
79 # TODO: check they're supported on this platform?
80 if universal_encoding is not None:
81 e = [n for (n, u) in interesting_encodings if u == universal_encoding]
82 else:
83 e = [n for (n, u) in interesting_encodings]
84 return itertools.cycle(iter(e))
085
=== added file 'bzrlib/tests/test_fixtures.py'
--- bzrlib/tests/test_fixtures.py 1970-01-01 00:00:00 +0000
+++ bzrlib/tests/test_fixtures.py 2010-06-21 22:33:25 +0000
@@ -0,0 +1,28 @@
1# Copyright (C) 2010 Canonical Ltd
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17"""Tests for test fixtures"""
18
19import codecs
20
21from bzrlib import (
22 tests,
23 )
24from bzrlib.tests import (
25 fixtures,
26 )
27
28
029
=== modified file 'bzrlib/tests/test_ui.py'
--- bzrlib/tests/test_ui.py 2010-05-20 18:23:17 +0000
+++ bzrlib/tests/test_ui.py 2010-06-21 22:33:25 +0000
@@ -24,6 +24,7 @@
24from StringIO import StringIO24from StringIO import StringIO
2525
26from bzrlib import (26from bzrlib import (
27 config,
27 errors,28 errors,
28 remote,29 remote,
29 repository,30 repository,
@@ -33,10 +34,26 @@
33from bzrlib.symbol_versioning import (34from bzrlib.symbol_versioning import (
34 deprecated_in,35 deprecated_in,
35 )36 )
36from bzrlib.tests import test_progress37from bzrlib.tests import (
38 fixtures,
39 test_progress,
40 )
37from bzrlib.ui import text as _mod_ui_text41from bzrlib.ui import text as _mod_ui_text
3842
3943
44class TestUIConfiguration(tests.TestCaseWithTransport):
45
46 def test_output_encoding_configuration(self):
47 enc = fixtures.generate_unicode_encodings().next()
48 config.GlobalConfig().set_user_option('output_encoding',
49 enc)
50 ui = tests.TestUIFactory(stdin=None,
51 stdout=tests.StringIOWrapper(),
52 stderr=tests.StringIOWrapper())
53 os = ui.make_output_stream()
54 self.assertEquals(os.encoding, enc)
55
56
40class TestTextUIFactory(tests.TestCase):57class TestTextUIFactory(tests.TestCase):
4158
42 def test_text_factory_ascii_password(self):59 def test_text_factory_ascii_password(self):
4360
=== modified file 'bzrlib/ui/__init__.py'
--- bzrlib/ui/__init__.py 2010-06-21 20:03:23 +0000
+++ bzrlib/ui/__init__.py 2010-06-21 22:33:25 +0000
@@ -178,8 +178,9 @@
178 version of stdout, but in a GUI it might be appropriate to send it to a 178 version of stdout, but in a GUI it might be appropriate to send it to a
179 window displaying the text.179 window displaying the text.
180 180
181 :param encoding: Unicode encoding for output; default is the 181 :param encoding: Unicode encoding for output; if not specified
182 terminal encoding, which may be different from the user encoding.182 uses the configured 'output_encoding' if any; otherwise the
183 terminal encoding.
183 (See get_terminal_encoding.)184 (See get_terminal_encoding.)
184185
185 :param encoding_type: How to handle encoding errors:186 :param encoding_type: How to handle encoding errors:
@@ -187,6 +188,10 @@
187 """188 """
188 # XXX: is the caller supposed to close the resulting object?189 # XXX: is the caller supposed to close the resulting object?
189 if encoding is None:190 if encoding is None:
191 from bzrlib import config
192 encoding = config.GlobalConfig().get_user_option(
193 'output_encoding')
194 if encoding is None:
190 encoding = osutils.get_terminal_encoding()195 encoding = osutils.get_terminal_encoding()
191 if encoding_type is None:196 if encoding_type is None:
192 encoding_type = 'replace'197 encoding_type = 'replace'