~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-06-02 05:03:31 UTC
  • mto: This revision was merged to the branch mainline in revision 5279.
  • Revision ID: mbp@canonical.com-20100602050331-n2p1qt8hfsahspnv
Correct more sloppy use of the term 'Linux'

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
17
17
"""Tests for the osutils wrapper."""
18
18
 
19
19
import codecs
20
 
import errno
21
20
import locale
22
21
import os
23
22
import sys
24
23
 
25
24
from bzrlib import (
 
25
    errors,
26
26
    osutils,
27
27
    )
28
28
from bzrlib.tests import (
114
114
        # and in the worst case, use osutils.get_user_encoding()
115
115
        self.assertEqual('user_encoding', osutils.get_terminal_encoding())
116
116
 
117
 
    def test_get_terminal_encoding_silent(self):
118
 
        self.make_wrapped_streams('stdout_encoding',
119
 
                                  'stderr_encoding',
120
 
                                  'stdin_encoding')
121
 
        # Calling get_terminal_encoding should not mutter when silent=True is
122
 
        # passed.
123
 
        log = self.get_log()
124
 
        osutils.get_terminal_encoding()
125
 
        self.assertEqual(log, self.get_log())
126
 
 
127
 
    def test_get_terminal_encoding_trace(self):
128
 
        self.make_wrapped_streams('stdout_encoding',
129
 
                                  'stderr_encoding',
130
 
                                  'stdin_encoding')
131
 
        # Calling get_terminal_encoding should not mutter when silent=True is
132
 
        # passed.
133
 
        log = self.get_log()
134
 
        osutils.get_terminal_encoding(trace=True)
135
 
        self.assertNotEqual(log, self.get_log())
136
 
 
137
117
    def test_terminal_cp0(self):
138
118
        # test cp0 encoding (Windows returns cp0 when there is no encoding)
139
119
        self.make_wrapped_streams('cp0',
171
151
    def setUp(self):
172
152
        TestCase.setUp(self)
173
153
        self.overrideAttr(locale, 'getpreferredencoding')
 
154
        self.addCleanup(osutils.set_or_unset_env,
 
155
                        'LANG', os.environ.get('LANG'))
174
156
        self.overrideAttr(sys, 'stderr', StringIOWrapper())
175
157
 
176
158
    def test_get_user_encoding(self):
179
161
 
180
162
        locale.getpreferredencoding = f
181
163
        fake_codec.add('user_encoding')
182
 
        self.assertEquals('user_encoding',
183
 
                          osutils.get_user_encoding(use_cache=False))
 
164
        self.assertEquals('user_encoding', osutils.get_user_encoding(use_cache=False))
184
165
        self.assertEquals('', sys.stderr.getvalue())
185
166
 
186
167
    def test_user_cp0(self):
215
196
            raise locale.Error, 'unsupported locale'
216
197
 
217
198
        locale.getpreferredencoding = f
218
 
        self.overrideEnv('LANG', 'BOGUS')
 
199
        os.environ['LANG'] = 'BOGUS'
219
200
        self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
220
201
        self.assertEquals('bzr: warning: unsupported locale\n'
221
202
                          '  Could not determine what text encoding to use.\n'
223
204
                          '  doesn\'t support the locale set by $LANG (BOGUS)\n'
224
205
                          '  Continuing with ascii encoding.\n',
225
206
                          sys.stderr.getvalue())
226
 
 
227
 
 
228
 
class TestMessageEncoding(TestCase):
229
 
    """Tests for getting the encoding used by system messages"""
230
 
 
231
 
    def test_get_message_encoding(self):
232
 
        encoding_name = osutils.get_message_encoding()
233
 
        "".decode(encoding_name) # should be a valid encoding name
234
 
 
235
 
    def test_get_message_encoding_decodes_strerror(self):
236
 
        encoding_name = osutils.get_message_encoding()
237
 
        for number, name in errno.errorcode.iteritems():
238
 
            string = os.strerror(number)
239
 
            string.decode(encoding_name)