863
860
self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
865
862
cwd = osutils.getcwd().rstrip('/')
866
drive = osutils.ntpath.splitdrive(cwd)[0]
863
drive = osutils._nt_splitdrive(cwd)[0]
867
864
self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
868
865
self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
1066
1063
self.assertExpectedBlocks(expected_dirblocks[1:], result)
1068
1065
def test_walkdirs_os_error(self):
1069
# <https://bugs.launchpad.net/bzr/+bug/338653>
1066
# <https://bugs.edge.launchpad.net/bzr/+bug/338653>
1070
1067
# Pyrex readdir didn't raise useful messages if it had an error
1071
1068
# reading the directory
1072
1069
if sys.platform == 'win32':
1085
1082
# Ensure the message contains the file name
1086
1083
self.assertContainsRe(str(e), "\./test-unreadable")
1089
def test_walkdirs_encoding_error(self):
1090
# <https://bugs.launchpad.net/bzr/+bug/488519>
1091
# walkdirs didn't raise a useful message when the filenames
1092
# are not using the filesystem's encoding
1094
# require a bytestring based filesystem
1095
self.requireFeature(tests.ByteStringNamedFilesystem)
1106
self.build_tree(tree)
1108
# rename the 1file to a latin-1 filename
1109
os.rename("./1file", "\xe8file")
1111
self._save_platform_info()
1112
win32utils.winver = None # Avoid the win32 detection code
1113
osutils._fs_enc = 'UTF-8'
1115
# this should raise on error
1117
for dirdetail, dirblock in osutils.walkdirs('.'):
1120
self.assertRaises(errors.BadFilenameEncoding, attempt)
1122
1085
def test__walkdirs_utf8(self):
1708
1671
class TestReCompile(tests.TestCase):
1710
def _deprecated_re_compile_checked(self, *args, **kwargs):
1711
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1712
osutils.re_compile_checked, *args, **kwargs)
1714
1673
def test_re_compile_checked(self):
1715
r = self._deprecated_re_compile_checked(r'A*', re.IGNORECASE)
1674
r = osutils.re_compile_checked(r'A*', re.IGNORECASE)
1716
1675
self.assertTrue(r.match('aaaa'))
1717
1676
self.assertTrue(r.match('aAaA'))
1719
1678
def test_re_compile_checked_error(self):
1720
1679
# like https://bugs.launchpad.net/bzr/+bug/251352
1722
# Due to possible test isolation error, re.compile is not lazy at
1723
# this point. We re-install lazy compile.
1724
lazy_regex.install_lazy_compile()
1725
1680
err = self.assertRaises(
1726
1681
errors.BzrCommandError,
1727
self._deprecated_re_compile_checked, '*', re.IGNORECASE, 'test case')
1682
osutils.re_compile_checked, '*', re.IGNORECASE, 'test case')
1728
1683
self.assertEqual(
1729
'Invalid regular expression in test case: '
1730
'"*" nothing to repeat',
1684
"Invalid regular expression in test case: '*': "
1685
"nothing to repeat",
1955
1910
class TestTerminalWidth(tests.TestCase):
1958
tests.TestCase.setUp(self)
1959
self._orig_terminal_size_state = osutils._terminal_size_state
1960
self._orig_first_terminal_size = osutils._first_terminal_size
1961
self.addCleanup(self.restore_osutils_globals)
1962
osutils._terminal_size_state = 'no_data'
1963
osutils._first_terminal_size = None
1965
def restore_osutils_globals(self):
1966
osutils._terminal_size_state = self._orig_terminal_size_state
1967
osutils._first_terminal_size = self._orig_first_terminal_size
1969
1912
def replace_stdout(self, new):
1970
1913
self.overrideAttr(sys, 'stdout', new)
2032
1975
del os.environ['COLUMNS']
2033
1976
# Whatever the result is, if we don't raise an exception, it's ok.
2034
1977
osutils.terminal_width()
2036
class TestCreationOps(tests.TestCaseInTempDir):
2037
_test_needs_features = [features.chown_feature]
2040
tests.TestCaseInTempDir.setUp(self)
2041
self.overrideAttr(os, 'chown', self._dummy_chown)
2043
# params set by call to _dummy_chown
2044
self.path = self.uid = self.gid = None
2046
def _dummy_chown(self, path, uid, gid):
2047
self.path, self.uid, self.gid = path, uid, gid
2049
def test_copy_ownership_from_path(self):
2050
"""copy_ownership_from_path test with specified src."""
2052
f = open('test_file', 'wt')
2053
osutils.copy_ownership_from_path('test_file', ownsrc)
2056
self.assertEquals(self.path, 'test_file')
2057
self.assertEquals(self.uid, s.st_uid)
2058
self.assertEquals(self.gid, s.st_gid)
2060
def test_copy_ownership_nonesrc(self):
2061
"""copy_ownership_from_path test with src=None."""
2062
f = open('test_file', 'wt')
2063
# should use parent dir for permissions
2064
osutils.copy_ownership_from_path('test_file')
2067
self.assertEquals(self.path, 'test_file')
2068
self.assertEquals(self.uid, s.st_uid)
2069
self.assertEquals(self.gid, s.st_gid)
2071
class TestGetuserUnicode(tests.TestCase):
2073
def test_ascii_user(self):
2074
osutils.set_or_unset_env('LOGNAME', 'jrandom')
2075
self.assertEqual(u'jrandom', osutils.getuser_unicode())
2077
def test_unicode_user(self):
2078
ue = osutils.get_user_encoding()
2079
osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
2080
self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())