1206
1226
self.requireFeature(UTF8DirReaderFeature)
1207
1227
self._save_platform_info()
1208
1228
win32utils.winver = None # Avoid the win32 detection code
1209
osutils._fs_enc = 'UTF-8'
1210
self.assertDirReaderIs(UTF8DirReaderFeature.reader)
1229
osutils._fs_enc = 'utf-8'
1230
self.assertDirReaderIs(
1231
UTF8DirReaderFeature.module.UTF8DirReader)
1212
1233
def test_force_walkdirs_utf8_fs_ascii(self):
1213
1234
self.requireFeature(UTF8DirReaderFeature)
1214
1235
self._save_platform_info()
1215
1236
win32utils.winver = None # Avoid the win32 detection code
1216
osutils._fs_enc = 'US-ASCII'
1217
self.assertDirReaderIs(UTF8DirReaderFeature.reader)
1219
def test_force_walkdirs_utf8_fs_ANSI(self):
1220
self.requireFeature(UTF8DirReaderFeature)
1221
self._save_platform_info()
1222
win32utils.winver = None # Avoid the win32 detection code
1223
osutils._fs_enc = 'ANSI_X3.4-1968'
1224
self.assertDirReaderIs(UTF8DirReaderFeature.reader)
1237
osutils._fs_enc = 'ascii'
1238
self.assertDirReaderIs(
1239
UTF8DirReaderFeature.module.UTF8DirReader)
1226
1241
def test_force_walkdirs_utf8_fs_latin1(self):
1227
1242
self._save_platform_info()
1228
1243
win32utils.winver = None # Avoid the win32 detection code
1229
osutils._fs_enc = 'latin1'
1244
osutils._fs_enc = 'iso-8859-1'
1230
1245
self.assertDirReaderIs(osutils.UnicodeDirReader)
1232
1247
def test_force_walkdirs_utf8_nt(self):
1856
1871
return filtered_dirblocks
1858
1873
def test_walk_unicode_tree(self):
1859
self.requireFeature(tests.UnicodeFilenameFeature)
1874
self.requireFeature(features.UnicodeFilenameFeature)
1860
1875
tree, expected_dirblocks = self._get_unicode_tree()
1861
1876
self.build_tree(tree)
1862
1877
result = list(osutils._walkdirs_utf8('.'))
1863
1878
self.assertEqual(expected_dirblocks, self._filter_out(result))
1865
1880
def test_symlink(self):
1866
self.requireFeature(tests.SymlinkFeature)
1867
self.requireFeature(tests.UnicodeFilenameFeature)
1881
self.requireFeature(features.SymlinkFeature)
1882
self.requireFeature(features.UnicodeFilenameFeature)
1868
1883
target = u'target\N{Euro Sign}'
1869
1884
link_name = u'l\N{Euro Sign}nk'
1870
1885
os.symlink(target, link_name)
2089
2104
self.assertEquals(self.gid, s.st_gid)
2107
class TestPathFromEnviron(tests.TestCase):
2109
def test_is_unicode(self):
2110
self.overrideEnv('BZR_TEST_PATH', './anywhere at all/')
2111
path = osutils.path_from_environ('BZR_TEST_PATH')
2112
self.assertIsInstance(path, unicode)
2113
self.assertEqual(u'./anywhere at all/', path)
2115
def test_posix_path_env_ascii(self):
2116
self.overrideEnv('BZR_TEST_PATH', '/tmp')
2117
home = osutils._posix_path_from_environ('BZR_TEST_PATH')
2118
self.assertIsInstance(home, unicode)
2119
self.assertEqual(u'/tmp', home)
2121
def test_posix_path_env_unicode(self):
2122
self.requireFeature(features.ByteStringNamedFilesystem)
2123
self.overrideEnv('BZR_TEST_PATH', '/home/\xa7test')
2124
self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2125
self.assertEqual(u'/home/\xa7test',
2126
osutils._posix_path_from_environ('BZR_TEST_PATH'))
2127
osutils._fs_enc = "iso8859-5"
2128
self.assertEqual(u'/home/\u0407test',
2129
osutils._posix_path_from_environ('BZR_TEST_PATH'))
2130
osutils._fs_enc = "utf-8"
2131
self.assertRaises(errors.BadFilenameEncoding,
2132
osutils._posix_path_from_environ, 'BZR_TEST_PATH')
2135
class TestGetHomeDir(tests.TestCase):
2137
def test_is_unicode(self):
2138
home = osutils._get_home_dir()
2139
self.assertIsInstance(home, unicode)
2141
def test_posix_homeless(self):
2142
self.overrideEnv('HOME', None)
2143
home = osutils._get_home_dir()
2144
self.assertIsInstance(home, unicode)
2146
def test_posix_home_ascii(self):
2147
self.overrideEnv('HOME', '/home/test')
2148
home = osutils._posix_get_home_dir()
2149
self.assertIsInstance(home, unicode)
2150
self.assertEqual(u'/home/test', home)
2152
def test_posix_home_unicode(self):
2153
self.requireFeature(features.ByteStringNamedFilesystem)
2154
self.overrideEnv('HOME', '/home/\xa7test')
2155
self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2156
self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2157
osutils._fs_enc = "iso8859-5"
2158
self.assertEqual(u'/home/\u0407test', osutils._posix_get_home_dir())
2159
osutils._fs_enc = "utf-8"
2160
self.assertRaises(errors.BadFilenameEncoding,
2161
osutils._posix_get_home_dir)
2092
2164
class TestGetuserUnicode(tests.TestCase):
2166
def test_is_unicode(self):
2167
user = osutils.getuser_unicode()
2168
self.assertIsInstance(user, unicode)
2170
def envvar_to_override(self):
2171
if sys.platform == "win32":
2172
# Disable use of platform calls on windows so envvar is used
2173
self.overrideAttr(win32utils, 'has_ctypes', False)
2174
return 'USERNAME' # only variable used on windows
2175
return 'LOGNAME' # first variable checked by getpass.getuser()
2094
2177
def test_ascii_user(self):
2095
self.overrideEnv('LOGNAME', 'jrandom')
2178
self.overrideEnv(self.envvar_to_override(), 'jrandom')
2096
2179
self.assertEqual(u'jrandom', osutils.getuser_unicode())
2098
2181
def test_unicode_user(self):
2104
2187
% (osutils.get_user_encoding(),))
2105
2188
uni_username = u'jrandom' + uni_val
2106
2189
encoded_username = uni_username.encode(ue)
2107
self.overrideEnv('LOGNAME', encoded_username)
2190
self.overrideEnv(self.envvar_to_override(), encoded_username)
2108
2191
self.assertEqual(uni_username, osutils.getuser_unicode())
2109
self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
2110
self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
2112
def test_no_username_bug_660174(self):
2113
self.requireFeature(features.win32_feature)
2114
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
2115
self.overrideEnv(name, None)
2116
self.assertEqual(u'UNKNOWN', osutils.getuser_unicode())
2119
2194
class TestBackupNames(tests.TestCase):
2166
2249
self.assertTrue(osutils.find_executable_on_path('sh') is not None)
2167
2250
self.assertTrue(
2168
2251
osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
2254
class TestEnvironmentErrors(tests.TestCase):
2255
"""Test handling of environmental errors"""
2257
def test_is_oserror(self):
2258
self.assertTrue(osutils.is_environment_error(
2259
OSError(errno.EINVAL, "Invalid parameter")))
2261
def test_is_ioerror(self):
2262
self.assertTrue(osutils.is_environment_error(
2263
IOError(errno.EINVAL, "Invalid parameter")))
2265
def test_is_socket_error(self):
2266
self.assertTrue(osutils.is_environment_error(
2267
socket.error(errno.EINVAL, "Invalid parameter")))
2269
def test_is_select_error(self):
2270
self.assertTrue(osutils.is_environment_error(
2271
select.error(errno.EINVAL, "Invalid parameter")))
2273
def test_is_pywintypes_error(self):
2274
self.requireFeature(features.pywintypes)
2276
self.assertTrue(osutils.is_environment_error(
2277
pywintypes.error(errno.EINVAL, "Invalid parameter", "Caller")))