/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Aaron Bentley
  • Date: 2006-06-21 13:37:30 UTC
  • mfrom: (1799 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1802.
  • Revision ID: abentley@panoramicfeedback.com-20060621133730-6f6f965f4d2e3743
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import bzrlib
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 (
 
29
        StringIOWrapper,
 
30
        TestCase, 
 
31
        TestCaseInTempDir, 
 
32
        TestSkipped,
 
33
        )
29
34
 
30
35
 
31
36
class TestOSUtils(TestCaseInTempDir):
342
347
        self.assertEqual(
343
348
            dir_sorted_paths,
344
349
            sorted(original_paths, cmp=osutils.compare_paths_prefix_order))
 
350
 
 
351
 
 
352
class TestTerminalEncoding(TestCase):
 
353
    """Test the auto-detection of proper terminal encoding."""
 
354
 
 
355
    def setUp(self):
 
356
        self._stdout = sys.stdout
 
357
        self._stderr = sys.stderr
 
358
        self._stdin = sys.stdin
 
359
        self._user_encoding = bzrlib.user_encoding
 
360
 
 
361
        self.addCleanup(self._reset)
 
362
 
 
363
        sys.stdout = StringIOWrapper()
 
364
        sys.stdout.encoding = 'stdout_encoding'
 
365
        sys.stderr = StringIOWrapper()
 
366
        sys.stderr.encoding = 'stderr_encoding'
 
367
        sys.stdin = StringIOWrapper()
 
368
        sys.stdin.encoding = 'stdin_encoding'
 
369
        bzrlib.user_encoding = 'user_encoding'
 
370
 
 
371
    def _reset(self):
 
372
        sys.stdout = self._stdout
 
373
        sys.stderr = self._stderr
 
374
        sys.stdin = self._stdin
 
375
        bzrlib.user_encoding = self._user_encoding
 
376
 
 
377
    def test_get_terminal_encoding(self):
 
378
        # first preference is stdout encoding
 
379
        self.assertEqual('stdout_encoding', osutils.get_terminal_encoding())
 
380
 
 
381
        sys.stdout.encoding = None
 
382
        # if sys.stdout is None, fall back to sys.stdin
 
383
        self.assertEqual('stdin_encoding', osutils.get_terminal_encoding())
 
384
 
 
385
        sys.stdin.encoding = None
 
386
        # and in the worst case, use bzrlib.user_encoding
 
387
        self.assertEqual('user_encoding', osutils.get_terminal_encoding())
 
388