~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

  • Committer: Jelmer Vernooij
  • Date: 2009-01-28 18:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3968.
  • Revision ID: jelmer@samba.org-20090128184255-bdmklkvm83ltk191
Update NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import os
22
22
import sys
23
23
 
24
 
import bzrlib
25
24
from bzrlib import (
26
25
    errors,
27
26
    osutils,
29
28
from bzrlib.tests import (
30
29
        StringIOWrapper,
31
30
        TestCase, 
32
 
        TestSkipped,
33
31
        )
34
32
 
35
33
 
79
77
        self._stdout = sys.stdout
80
78
        self._stderr = sys.stderr
81
79
        self._stdin = sys.stdin
82
 
        self._user_encoding = bzrlib.user_encoding
 
80
        self._user_encoding = osutils._cached_user_encoding
83
81
 
84
82
        self.addCleanup(self._reset)
85
83
 
95
93
        sys.stderr.encoding = stderr_encoding
96
94
        sys.stdin = StringIOWrapper()
97
95
        sys.stdin.encoding = stdin_encoding
98
 
        bzrlib.user_encoding = user_encoding
 
96
        osutils._cached_user_encoding = user_encoding
99
97
        if enable_fake_encodings:
100
98
            fake_codec.add(stdout_encoding)
101
99
            fake_codec.add(stderr_encoding)
105
103
        sys.stdout = self._stdout
106
104
        sys.stderr = self._stderr
107
105
        sys.stdin = self._stdin
108
 
        bzrlib.user_encoding = self._user_encoding
 
106
        osutils._cached_user_encoding = self._user_encoding
109
107
 
110
108
    def test_get_terminal_encoding(self):
111
109
        self.make_wrapped_streams('stdout_encoding',
120
118
        self.assertEqual('stdin_encoding', osutils.get_terminal_encoding())
121
119
 
122
120
        sys.stdin.encoding = None
123
 
        # and in the worst case, use bzrlib.user_encoding
 
121
        # and in the worst case, use osutils.get_user_encoding()
124
122
        self.assertEqual('user_encoding', osutils.get_terminal_encoding())
125
123
 
126
124
    def test_terminal_cp0(self):
198
196
                          ' Continuing with ascii encoding.\n',
199
197
                          sys.stderr.getvalue())
200
198
 
 
199
    def test_user_empty(self):
 
200
        """Running bzr from a vim script gives '' for a preferred locale"""
 
201
        def f():
 
202
            return ''
 
203
 
 
204
        locale.getpreferredencoding = f
 
205
        self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
 
206
        self.assertEquals('', sys.stderr.getvalue())
 
207
 
201
208
    def test_user_locale_error(self):
202
209
        def f():
203
210
            raise locale.Error, 'unsupported locale'