~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
20
21
import locale
21
22
import os
22
23
import sys
23
24
 
24
25
from bzrlib import (
25
 
    errors,
26
26
    osutils,
27
27
    )
28
28
from bzrlib.tests import (
171
171
    def setUp(self):
172
172
        TestCase.setUp(self)
173
173
        self.overrideAttr(locale, 'getpreferredencoding')
174
 
        self.addCleanup(osutils.set_or_unset_env,
175
 
                        'LANG', os.environ.get('LANG'))
176
174
        self.overrideAttr(sys, 'stderr', StringIOWrapper())
177
175
 
178
176
    def test_get_user_encoding(self):
181
179
 
182
180
        locale.getpreferredencoding = f
183
181
        fake_codec.add('user_encoding')
184
 
        self.assertEquals('user_encoding', osutils.get_user_encoding(use_cache=False))
 
182
        self.assertEquals('user_encoding',
 
183
                          osutils.get_user_encoding(use_cache=False))
185
184
        self.assertEquals('', sys.stderr.getvalue())
186
185
 
187
186
    def test_user_cp0(self):
216
215
            raise locale.Error, 'unsupported locale'
217
216
 
218
217
        locale.getpreferredencoding = f
219
 
        os.environ['LANG'] = 'BOGUS'
 
218
        self.overrideEnv('LANG', 'BOGUS')
220
219
        self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
221
220
        self.assertEquals('bzr: warning: unsupported locale\n'
222
221
                          '  Could not determine what text encoding to use.\n'
224
223
                          '  doesn\'t support the locale set by $LANG (BOGUS)\n'
225
224
                          '  Continuing with ascii encoding.\n',
226
225
                          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)