26
26
from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
27
27
import bzrlib.osutils as osutils
28
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
28
from bzrlib.tests import (
31
36
class TestOSUtils(TestCaseInTempDir):
259
264
self.assertTrue(found_bzrdir)
260
265
self.assertEqual(expected_dirblocks,
261
266
[[line[0:3] for line in block] for block in result])
269
class TestTerminalEncoding(TestCase):
270
"""Test the auto-detection of proper terminal encoding."""
273
self._stdout = sys.stdout
274
self._stderr = sys.stderr
275
self._stdin = sys.stdin
276
self._user_encoding = bzrlib.user_encoding
278
self.addCleanup(self._reset)
280
sys.stdout = StringIOWrapper()
281
sys.stdout.encoding = 'stdout_encoding'
282
sys.stderr = StringIOWrapper()
283
sys.stderr.encoding = 'stderr_encoding'
284
sys.stdin = StringIOWrapper()
285
sys.stdin.encoding = 'stdin_encoding'
286
bzrlib.user_encoding = 'user_encoding'
289
sys.stdout = self._stdout
290
sys.stderr = self._stderr
291
sys.stdin = self._stdin
292
bzrlib.user_encoding = self._user_encoding
294
def test_get_terminal_encoding(self):
295
# first preference is stdout encoding
296
self.assertEqual('stdout_encoding', osutils.get_terminal_encoding())
298
sys.stdout.encoding = None
299
# if sys.stdout is None, fall back to sys.stdin
300
self.assertEqual('stdin_encoding', osutils.get_terminal_encoding())
302
sys.stdin.encoding = None
303
# and in the worst case, use bzrlib.user_encoding
304
self.assertEqual('user_encoding', osutils.get_terminal_encoding())