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):
171
176
self.assertEqual('path/to/foo', osutils._win32_normpath('path//from/../to/./foo'))
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])
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'))
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))
365
class TestTerminalEncoding(TestCase):
366
"""Test the auto-detection of proper terminal encoding."""
369
self._stdout = sys.stdout
370
self._stderr = sys.stderr
371
self._stdin = sys.stdin
372
self._user_encoding = bzrlib.user_encoding
374
self.addCleanup(self._reset)
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'
385
sys.stdout = self._stdout
386
sys.stderr = self._stderr
387
sys.stdin = self._stdin
388
bzrlib.user_encoding = self._user_encoding
390
def test_get_terminal_encoding(self):
391
# first preference is stdout encoding
392
self.assertEqual('stdout_encoding', osutils.get_terminal_encoding())
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())
398
sys.stdin.encoding = None
399
# and in the worst case, use bzrlib.user_encoding
400
self.assertEqual('user_encoding', osutils.get_terminal_encoding())