264
class TestSafeUtf8(TestCase):
266
def test_from_ascii_string(self):
268
self.assertEqual('foobar', osutils.safe_utf8(f))
270
def test_from_unicode_string_ascii_contents(self):
271
self.assertEqual('bargam', osutils.safe_utf8(u'bargam'))
273
def test_from_unicode_string_unicode_contents(self):
274
self.assertEqual('bargam\xc2\xae', osutils.safe_utf8(u'bargam\xae'))
276
def test_from_utf8_string(self):
277
self.assertEqual('foo\xc2\xae', osutils.safe_utf8('foo\xc2\xae'))
279
def test_bad_utf8_string(self):
280
self.assertRaises(BzrBadParameterNotUnicode,
281
osutils.safe_utf8, '\xbb\xbb')
284
class TestSafeRevisionId(TestCase):
286
def test_from_ascii_string(self):
288
self.assertEqual('foobar', osutils.safe_revision_id(f))
289
self.assertIs(osutils.safe_utf8(f), f)
291
def test_from_unicode_string_ascii_contents(self):
292
self.assertEqual('bargam', osutils.safe_revision_id(u'bargam'))
294
def test_from_unicode_string_unicode_contents(self):
295
self.assertEqual('bargam\xc2\xae',
296
osutils.safe_revision_id(u'bargam\xae'))
298
def test_from_utf8_string(self):
299
self.assertEqual('foo\xc2\xae',
300
osutils.safe_revision_id('foo\xc2\xae'))
302
def test_bad_utf8_string(self):
303
# This check may eventually go away
304
self.assertRaises(BzrBadParameterNotUnicode,
305
osutils.safe_utf8, '\xbb\xbb')
308
"""Currently, None is a valid revision_id"""
309
self.assertEqual(None, osutils.safe_revision_id(None))
263
312
class TestWin32Funcs(TestCase):
264
313
"""Test that the _win32 versions of os utilities return appropriate paths."""
266
315
def test_abspath(self):
267
316
self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
268
317
self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
318
self.assertEqual('//HOST/path', osutils._win32_abspath(r'\\HOST\path'))
319
self.assertEqual('//HOST/path', osutils._win32_abspath('//HOST/path'))
270
321
def test_realpath(self):
271
322
self.assertEqual('C:/foo', osutils._win32_realpath('C:\\foo'))
299
350
self.assertEqual('H:/foo', osutils._win32_fixdrive('H:/foo'))
300
351
self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
353
def test_win98_abspath(self):
355
self.assertEqual('C:/foo', osutils._win98_abspath('C:\\foo'))
356
self.assertEqual('C:/foo', osutils._win98_abspath('C:/foo'))
358
self.assertEqual('//HOST/path', osutils._win98_abspath(r'\\HOST\path'))
359
self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
361
cwd = osutils.getcwd().rstrip('/')
362
drive = osutils._nt_splitdrive(cwd)[0]
363
self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
364
self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
367
self.assertEqual(cwd+'/'+u, osutils._win98_abspath(u))
303
370
class TestWin32FuncsDirs(TestCaseInTempDir):
304
371
"""Test win32 functions that create files."""
306
373
def test_getcwd(self):
374
if win32utils.winver == 'Windows 98':
375
raise TestSkipped('Windows 98 cannot handle unicode filenames')
307
376
# Make sure getcwd can handle unicode filenames
309
378
os.mkdir(u'mu-\xb5')