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