399
405
self.assertRaises(osutils.UnsupportedTimezoneFormat,
400
406
osutils.format_date, 0, timezone='foo')
401
407
self.assertIsInstance(osutils.format_date(0), str)
402
self.assertIsInstance(osutils.format_local_date(0), str)
408
self.assertIsInstance(osutils.format_local_date(0), text_type)
403
409
# Testing for the actual value of the local weekday without
404
410
# duplicating the code from format_date is difficult.
405
411
# Instead blackbox.test_locale should check for localized
941
947
osutils._win32_pathjoin('path/to/', 'foo'))
943
949
def test_pathjoin_late_bugfix(self):
950
if sys.version_info < (2, 7, 6):
945
954
self.assertEqual(expected,
946
955
osutils._win32_pathjoin('C:/path/to/', '/foo'))
947
956
self.assertEqual(expected,
1400
1409
# all abspaths are Unicode, and encode them back into utf8.
1401
1410
for dirdetail, dirblock in osutils._walkdirs_utf8('.'):
1402
1411
self.assertIsInstance(dirdetail[0], bytes)
1403
if isinstance(dirdetail[1], str):
1412
if isinstance(dirdetail[1], text_type):
1404
1413
dirdetail = (dirdetail[0], dirdetail[1].encode('utf8'))
1405
1414
dirblock = [list(info) for info in dirblock]
1406
1415
for info in dirblock:
1407
self.assertIsInstance(info[4], str)
1416
self.assertIsInstance(info[4], text_type)
1408
1417
info[4] = info[4].encode('utf8')
1409
1418
new_dirblock = []
1410
1419
for info in dirblock:
1731
1740
% (osutils.get_user_encoding(),))
1733
1742
osutils.set_or_unset_env('BRZ_TEST_ENV_VAR', uni_val)
1734
self.assertEqual(uni_val, os.environ.get('BRZ_TEST_ENV_VAR'))
1744
self.assertEqual(uni_val, os.environ.get('BRZ_TEST_ENV_VAR'))
1746
self.assertEqual(env_val, os.environ.get('BRZ_TEST_ENV_VAR'))
1736
1748
def test_unset(self):
1737
1749
"""Test that passing None will remove the env var"""
1992
2004
def test_failure_to_load(self):
1993
2005
self._try_loading()
1994
2006
self.assertLength(1, osutils._extension_load_failures)
1996
osutils._extension_load_failures[0],
1997
"No module named 'breezy._fictional_extension_py'")
2009
osutils._extension_load_failures[0],
2010
"No module named 'breezy._fictional_extension_py'")
2012
self.assertEqual(osutils._extension_load_failures[0],
2013
"No module named _fictional_extension_py")
1999
2015
def test_report_extension_load_failures_no_warning(self):
2000
2016
self.assertTrue(self._try_loading())
2142
2158
def test_is_unicode(self):
2143
2159
self.overrideEnv('BRZ_TEST_PATH', './anywhere at all/')
2144
2160
path = osutils.path_from_environ('BRZ_TEST_PATH')
2145
self.assertIsInstance(path, str)
2161
self.assertIsInstance(path, text_type)
2146
2162
self.assertEqual(u'./anywhere at all/', path)
2148
2164
def test_posix_path_env_ascii(self):
2149
2165
self.overrideEnv('BRZ_TEST_PATH', '/tmp')
2150
2166
home = osutils._posix_path_from_environ('BRZ_TEST_PATH')
2151
self.assertIsInstance(home, str)
2167
self.assertIsInstance(home, text_type)
2152
2168
self.assertEqual(u'/tmp', home)
2154
2170
def test_posix_path_env_unicode(self):
2158
2174
self.assertEqual(u'/home/\xa7test',
2159
2175
osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2160
2176
osutils._fs_enc = "iso8859-5"
2161
# In Python 3, os.environ returns unicode.
2162
self.assertEqual(u'/home/\xa7test',
2163
osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2178
# In Python 3, os.environ returns unicode.
2179
self.assertEqual(u'/home/\xa7test',
2180
osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2182
self.assertEqual(u'/home/\u0407test',
2183
osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2184
osutils._fs_enc = "utf-8"
2186
errors.BadFilenameEncoding,
2187
osutils._posix_path_from_environ, 'BRZ_TEST_PATH')
2166
2190
class TestGetHomeDir(tests.TestCase):
2168
2192
def test_is_unicode(self):
2169
2193
home = osutils._get_home_dir()
2170
self.assertIsInstance(home, str)
2194
self.assertIsInstance(home, text_type)
2172
2196
def test_posix_homeless(self):
2173
2197
self.overrideEnv('HOME', None)
2174
2198
home = osutils._get_home_dir()
2175
self.assertIsInstance(home, str)
2199
self.assertIsInstance(home, text_type)
2177
2201
def test_posix_home_ascii(self):
2178
2202
self.overrideEnv('HOME', '/home/test')
2179
2203
home = osutils._posix_get_home_dir()
2180
self.assertIsInstance(home, str)
2204
self.assertIsInstance(home, text_type)
2181
2205
self.assertEqual(u'/home/test', home)
2183
2207
def test_posix_home_unicode(self):
2186
2210
self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2187
2211
self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2188
2212
osutils._fs_enc = "iso8859-5"
2189
# In python 3, os.environ returns unicode
2190
self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2214
# In python 3, os.environ returns unicode
2215
self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2217
self.assertEqual(u'/home/\u0407test',
2218
osutils._posix_get_home_dir())
2219
osutils._fs_enc = "utf-8"
2220
self.assertRaises(errors.BadFilenameEncoding,
2221
osutils._posix_get_home_dir)
2193
2224
class TestGetuserUnicode(tests.TestCase):
2195
2226
def test_is_unicode(self):
2196
2227
user = osutils.getuser_unicode()
2197
self.assertIsInstance(user, str)
2228
self.assertIsInstance(user, text_type)
2199
2230
def envvar_to_override(self):
2200
2231
if sys.platform == "win32":
2216
2247
% (osutils.get_user_encoding(),))
2217
2248
uni_username = u'jrandom' + uni_val
2218
2249
encoded_username = uni_username.encode(ue)
2219
self.overrideEnv(self.envvar_to_override(), uni_username)
2251
self.overrideEnv(self.envvar_to_override(), uni_username)
2253
self.overrideEnv(self.envvar_to_override(), encoded_username)
2220
2254
self.assertEqual(uni_username, osutils.getuser_unicode())
2341
2375
def test_returns_string_or_none(self):
2342
2376
ret = osutils.get_fs_type(self.test_dir)
2343
self.assertTrue(isinstance(ret, str) or ret is None)
2377
self.assertTrue(isinstance(ret, text_type) or ret is None)
2345
2379
def test_returns_most_specific(self):
2346
2380
self.overrideAttr(