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