~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-02 16:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2225.
  • Revision ID: bialix@ukr.net-20070102160411-tkmtr5yzu7eha6w1
get_user_encoding: if locale.Error raised we need to set user_encoding to 'ascii' as warning says

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import codecs
20
20
import locale   # XXX: Do I need a woodoo for MacOS?
 
21
import os
21
22
import sys
22
23
 
23
24
import bzrlib
154
155
        self._getpreferredencoding = locale.getpreferredencoding
155
156
        self.addCleanup(self._reset)
156
157
        sys.stderr = StringIOWrapper()
 
158
        # save $LANG
 
159
        self._LANG = os.environ.get('LANG')
157
160
 
158
161
    def _reset(self):
159
162
        locale.getpreferredencoding = self._getpreferredencoding
160
163
        sys.stderr = self._stderr
 
164
        # restore $LANG
 
165
        if self._LANG is not None:
 
166
            os.environ['LANG'] = self._LANG
 
167
        else:
 
168
            if os.environ.get('LANG') is not None:
 
169
                del os.environ['LANG']
161
170
 
162
171
    def test_get_user_encoding(self):
163
172
        def f():
185
194
        self.assertEquals('bzr: warning: unknown encoding cpUNKNOWN.'
186
195
                          ' Continuing with ascii encoding.\n',
187
196
                          sys.stderr.getvalue())
 
197
 
 
198
    def test_user_locale_error(self):
 
199
        def f():
 
200
            raise locale.Error, 'unsupported locale'
 
201
 
 
202
        locale.getpreferredencoding = f
 
203
        os.environ['LANG'] = 'BOGUS'
 
204
        self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
 
205
        self.assertEquals('bzr: warning: unsupported locale\n'
 
206
                          '  Could not determine what text encoding to use.\n'
 
207
                          '  This error usually means your Python interpreter\n'
 
208
                          '  doesn\'t support the locale set by $LANG (BOGUS)\n'
 
209
                          '  Continuing with ascii encoding.\n',
 
210
                          sys.stderr.getvalue())