818
818
osutils.safe_utf8, b'\xbb\xbb')
821
class TestSafeRevisionId(tests.TestCase):
823
def test_from_ascii_string(self):
824
# this shouldn't give a warning because it's getting an ascii string
825
self.assertEqual(b'foobar', osutils.safe_revision_id(b'foobar'))
827
def test_from_unicode_string_ascii_contents(self):
828
self.assertRaises(TypeError,
829
osutils.safe_revision_id, u'bargam')
831
def test_from_unicode_string_unicode_contents(self):
832
self.assertRaises(TypeError,
833
osutils.safe_revision_id, u'bargam\xae')
835
def test_from_utf8_string(self):
836
self.assertEqual(b'foo\xc2\xae',
837
osutils.safe_revision_id(b'foo\xc2\xae'))
840
"""Currently, None is a valid revision_id"""
841
self.assertEqual(None, osutils.safe_revision_id(None))
844
class TestSafeFileId(tests.TestCase):
846
def test_from_ascii_string(self):
847
self.assertEqual(b'foobar', osutils.safe_file_id(b'foobar'))
849
def test_from_unicode_string_ascii_contents(self):
850
self.assertRaises(TypeError, osutils.safe_file_id, u'bargam')
852
def test_from_unicode_string_unicode_contents(self):
853
self.assertRaises(TypeError,
854
osutils.safe_file_id, u'bargam\xae')
856
def test_from_utf8_string(self):
857
self.assertEqual(b'foo\xc2\xae',
858
osutils.safe_file_id(b'foo\xc2\xae'))
861
"""Currently, None is a valid revision_id"""
862
self.assertEqual(None, osutils.safe_file_id(None))
865
821
class TestSendAll(tests.TestCase):
867
823
def test_send_with_disconnected_socket(self):
2137
2093
self.assertEqual(self.gid, s.st_gid)
2140
class TestPathFromEnviron(tests.TestCase):
2142
def test_is_unicode(self):
2143
self.overrideEnv('BRZ_TEST_PATH', './anywhere at all/')
2144
path = osutils.path_from_environ('BRZ_TEST_PATH')
2145
self.assertIsInstance(path, str)
2146
self.assertEqual(u'./anywhere at all/', path)
2148
def test_posix_path_env_ascii(self):
2149
self.overrideEnv('BRZ_TEST_PATH', '/tmp')
2150
home = osutils._posix_path_from_environ('BRZ_TEST_PATH')
2151
self.assertIsInstance(home, str)
2152
self.assertEqual(u'/tmp', home)
2154
def test_posix_path_env_unicode(self):
2155
self.requireFeature(features.ByteStringNamedFilesystem)
2156
self.overrideEnv('BRZ_TEST_PATH', '/home/\xa7test')
2157
self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2158
self.assertEqual(u'/home/\xa7test',
2159
osutils._posix_path_from_environ('BRZ_TEST_PATH'))
2160
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'))
2166
2096
class TestGetHomeDir(tests.TestCase):
2168
2098
def test_is_unicode(self):
2282
2212
osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
2285
class TestEnvironmentErrors(tests.TestCase):
2286
"""Test handling of environmental errors"""
2288
def test_is_oserror(self):
2289
self.assertTrue(osutils.is_environment_error(
2290
OSError(errno.EINVAL, "Invalid parameter")))
2292
def test_is_ioerror(self):
2293
self.assertTrue(osutils.is_environment_error(
2294
IOError(errno.EINVAL, "Invalid parameter")))
2296
def test_is_socket_error(self):
2297
self.assertTrue(osutils.is_environment_error(
2298
socket.error(errno.EINVAL, "Invalid parameter")))
2300
def test_is_select_error(self):
2301
self.assertTrue(osutils.is_environment_error(
2302
select.error(errno.EINVAL, "Invalid parameter")))
2304
def test_is_pywintypes_error(self):
2305
self.requireFeature(features.pywintypes)
2307
self.assertTrue(osutils.is_environment_error(
2308
pywintypes.error(errno.EINVAL, "Invalid parameter", "Caller")))
2311
2215
class SupportsExecutableTests(tests.TestCaseInTempDir):
2313
2217
def test_returns_bool(self):