~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
18
18
 
19
19
import codecs
20
20
import locale
21
 
import os
22
21
import sys
23
22
 
24
23
from bzrlib import (
25
 
    errors,
26
24
    osutils,
27
25
    )
28
26
from bzrlib.tests import (
114
112
        # and in the worst case, use osutils.get_user_encoding()
115
113
        self.assertEqual('user_encoding', osutils.get_terminal_encoding())
116
114
 
 
115
    def test_get_terminal_encoding_silent(self):
 
116
        self.make_wrapped_streams('stdout_encoding',
 
117
                                  'stderr_encoding',
 
118
                                  'stdin_encoding')
 
119
        # Calling get_terminal_encoding should not mutter when silent=True is
 
120
        # passed.
 
121
        log = self.get_log()
 
122
        osutils.get_terminal_encoding()
 
123
        self.assertEqual(log, self.get_log())
 
124
 
 
125
    def test_get_terminal_encoding_trace(self):
 
126
        self.make_wrapped_streams('stdout_encoding',
 
127
                                  'stderr_encoding',
 
128
                                  'stdin_encoding')
 
129
        # Calling get_terminal_encoding should not mutter when silent=True is
 
130
        # passed.
 
131
        log = self.get_log()
 
132
        osutils.get_terminal_encoding(trace=True)
 
133
        self.assertNotEqual(log, self.get_log())
 
134
 
117
135
    def test_terminal_cp0(self):
118
136
        # test cp0 encoding (Windows returns cp0 when there is no encoding)
119
137
        self.make_wrapped_streams('cp0',
151
169
    def setUp(self):
152
170
        TestCase.setUp(self)
153
171
        self.overrideAttr(locale, 'getpreferredencoding')
154
 
        self.addCleanup(osutils.set_or_unset_env,
155
 
                        'LANG', os.environ.get('LANG'))
156
172
        self.overrideAttr(sys, 'stderr', StringIOWrapper())
157
173
 
158
174
    def test_get_user_encoding(self):
161
177
 
162
178
        locale.getpreferredencoding = f
163
179
        fake_codec.add('user_encoding')
164
 
        self.assertEquals('user_encoding', osutils.get_user_encoding(use_cache=False))
 
180
        self.assertEquals('user_encoding',
 
181
                          osutils.get_user_encoding(use_cache=False))
165
182
        self.assertEquals('', sys.stderr.getvalue())
166
183
 
167
184
    def test_user_cp0(self):
196
213
            raise locale.Error, 'unsupported locale'
197
214
 
198
215
        locale.getpreferredencoding = f
199
 
        os.environ['LANG'] = 'BOGUS'
 
216
        self.overrideEnv('LANG', 'BOGUS')
200
217
        self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
201
218
        self.assertEquals('bzr: warning: unsupported locale\n'
202
219
                          '  Could not determine what text encoding to use.\n'