~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

Show diffs side-by-side

added added

removed removed

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