~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
 
19
19
import codecs
20
20
import locale
 
21
import os
21
22
import sys
22
23
 
23
24
from bzrlib import (
 
25
    errors,
24
26
    osutils,
25
27
    )
26
28
from bzrlib.tests import (
112
114
        # and in the worst case, use osutils.get_user_encoding()
113
115
        self.assertEqual('user_encoding', osutils.get_terminal_encoding())
114
116
 
115
 
    def test_get_terminal_encoding_silent(self):
116
 
        self.make_wrapped_streams('stdout_encoding',
117
 
                                  'stderr_encoding',
118
 
                                  'stdin_encoding')
119
 
        # Calling get_terminal_encoding should not mutter when silent=True is
120
 
        # passed.
121
 
        log = self.get_log()
122
 
        osutils.get_terminal_encoding()
123
 
        self.assertEqual(log, self.get_log())
124
 
 
125
 
    def test_get_terminal_encoding_trace(self):
126
 
        self.make_wrapped_streams('stdout_encoding',
127
 
                                  'stderr_encoding',
128
 
                                  'stdin_encoding')
129
 
        # Calling get_terminal_encoding should not mutter when silent=True is
130
 
        # passed.
131
 
        log = self.get_log()
132
 
        osutils.get_terminal_encoding(trace=True)
133
 
        self.assertNotEqual(log, self.get_log())
134
 
 
135
117
    def test_terminal_cp0(self):
136
118
        # test cp0 encoding (Windows returns cp0 when there is no encoding)
137
119
        self.make_wrapped_streams('cp0',
169
151
    def setUp(self):
170
152
        TestCase.setUp(self)
171
153
        self.overrideAttr(locale, 'getpreferredencoding')
 
154
        self.addCleanup(osutils.set_or_unset_env,
 
155
                        'LANG', os.environ.get('LANG'))
172
156
        self.overrideAttr(sys, 'stderr', StringIOWrapper())
173
157
 
174
158
    def test_get_user_encoding(self):
177
161
 
178
162
        locale.getpreferredencoding = f
179
163
        fake_codec.add('user_encoding')
180
 
        self.assertEquals('user_encoding',
181
 
                          osutils.get_user_encoding(use_cache=False))
 
164
        self.assertEquals('user_encoding', osutils.get_user_encoding(use_cache=False))
182
165
        self.assertEquals('', sys.stderr.getvalue())
183
166
 
184
167
    def test_user_cp0(self):
213
196
            raise locale.Error, 'unsupported locale'
214
197
 
215
198
        locale.getpreferredencoding = f
216
 
        self.overrideEnv('LANG', 'BOGUS')
 
199
        os.environ['LANG'] = 'BOGUS'
217
200
        self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
218
201
        self.assertEquals('bzr: warning: unsupported locale\n'
219
202
                          '  Could not determine what text encoding to use.\n'