~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Robey Pointer
  • Date: 2006-07-01 19:03:33 UTC
  • mfrom: (1829 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1830.
  • Revision ID: robey@lag.net-20060701190333-f58465aec4bd3412
merge from 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):
171
176
        self.assertEqual('path/to/foo', osutils._win32_normpath('path//from/../to/./foo'))
172
177
 
173
178
    def test_getcwd(self):
174
 
        self.assertEqual(os.getcwdu().replace('\\', '/'), osutils._win32_getcwd())
 
179
        cwd = osutils._win32_getcwd()
 
180
        os_cwd = os.getcwdu()
 
181
        self.assertEqual(os_cwd[1:].replace('\\', '/'), cwd[1:])
 
182
        # win32 is inconsistent whether it returns lower or upper case
 
183
        # and even if it was consistent the user might type the other
 
184
        # so we force it to uppercase
 
185
        # running python.exe under cmd.exe return capital C:\\
 
186
        # running win32 python inside a cygwin shell returns lowercase
 
187
        self.assertEqual(os_cwd[0].upper(), cwd[0])
 
188
 
 
189
    def test_fixdrive(self):
 
190
        self.assertEqual('H:/foo', osutils._win32_fixdrive('h:/foo'))
 
191
        self.assertEqual('H:/foo', osutils._win32_fixdrive('H:/foo'))
 
192
        self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
175
193
 
176
194
 
177
195
class TestWin32FuncsDirs(TestCaseInTempDir):
342
360
        self.assertEqual(
343
361
            dir_sorted_paths,
344
362
            sorted(original_paths, cmp=osutils.compare_paths_prefix_order))
 
363
 
 
364
 
 
365
class TestTerminalEncoding(TestCase):
 
366
    """Test the auto-detection of proper terminal encoding."""
 
367
 
 
368
    def setUp(self):
 
369
        self._stdout = sys.stdout
 
370
        self._stderr = sys.stderr
 
371
        self._stdin = sys.stdin
 
372
        self._user_encoding = bzrlib.user_encoding
 
373
 
 
374
        self.addCleanup(self._reset)
 
375
 
 
376
        sys.stdout = StringIOWrapper()
 
377
        sys.stdout.encoding = 'stdout_encoding'
 
378
        sys.stderr = StringIOWrapper()
 
379
        sys.stderr.encoding = 'stderr_encoding'
 
380
        sys.stdin = StringIOWrapper()
 
381
        sys.stdin.encoding = 'stdin_encoding'
 
382
        bzrlib.user_encoding = 'user_encoding'
 
383
 
 
384
    def _reset(self):
 
385
        sys.stdout = self._stdout
 
386
        sys.stderr = self._stderr
 
387
        sys.stdin = self._stdin
 
388
        bzrlib.user_encoding = self._user_encoding
 
389
 
 
390
    def test_get_terminal_encoding(self):
 
391
        # first preference is stdout encoding
 
392
        self.assertEqual('stdout_encoding', osutils.get_terminal_encoding())
 
393
 
 
394
        sys.stdout.encoding = None
 
395
        # if sys.stdout is None, fall back to sys.stdin
 
396
        self.assertEqual('stdin_encoding', osutils.get_terminal_encoding())
 
397
 
 
398
        sys.stdin.encoding = None
 
399
        # and in the worst case, use bzrlib.user_encoding
 
400
        self.assertEqual('user_encoding', osutils.get_terminal_encoding())
 
401