/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

Merge from bzr.dev.  Breaks a few tests because there are new methods not yet implemented.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import (
27
27
    errors,
28
28
    osutils,
 
29
    win32utils,
29
30
    )
30
31
from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
31
32
from bzrlib.tests import (
260
261
                          '\xbb\xbb')
261
262
 
262
263
 
 
264
class TestSafeUtf8(TestCase):
 
265
 
 
266
    def test_from_ascii_string(self):
 
267
        f = 'foobar'
 
268
        self.assertEqual('foobar', osutils.safe_utf8(f))
 
269
 
 
270
    def test_from_unicode_string_ascii_contents(self):
 
271
        self.assertEqual('bargam', osutils.safe_utf8(u'bargam'))
 
272
 
 
273
    def test_from_unicode_string_unicode_contents(self):
 
274
        self.assertEqual('bargam\xc2\xae', osutils.safe_utf8(u'bargam\xae'))
 
275
 
 
276
    def test_from_utf8_string(self):
 
277
        self.assertEqual('foo\xc2\xae', osutils.safe_utf8('foo\xc2\xae'))
 
278
 
 
279
    def test_bad_utf8_string(self):
 
280
        self.assertRaises(BzrBadParameterNotUnicode,
 
281
                          osutils.safe_utf8, '\xbb\xbb')
 
282
 
 
283
 
 
284
class TestSafeRevisionId(TestCase):
 
285
 
 
286
    def test_from_ascii_string(self):
 
287
        f = 'foobar'
 
288
        self.assertEqual('foobar', osutils.safe_revision_id(f))
 
289
        self.assertIs(osutils.safe_utf8(f), f)
 
290
 
 
291
    def test_from_unicode_string_ascii_contents(self):
 
292
        self.assertEqual('bargam', osutils.safe_revision_id(u'bargam'))
 
293
 
 
294
    def test_from_unicode_string_unicode_contents(self):
 
295
        self.assertEqual('bargam\xc2\xae',
 
296
                         osutils.safe_revision_id(u'bargam\xae'))
 
297
 
 
298
    def test_from_utf8_string(self):
 
299
        self.assertEqual('foo\xc2\xae',
 
300
                         osutils.safe_revision_id('foo\xc2\xae'))
 
301
 
 
302
    def test_bad_utf8_string(self):
 
303
        # This check may eventually go away
 
304
        self.assertRaises(BzrBadParameterNotUnicode,
 
305
                          osutils.safe_revision_id, '\xbb\xbb')
 
306
 
 
307
    def test_none(self):
 
308
        """Currently, None is a valid revision_id"""
 
309
        self.assertEqual(None, osutils.safe_revision_id(None))
 
310
 
 
311
 
 
312
class TestSafeFileId(TestCase):
 
313
 
 
314
    def test_from_ascii_string(self):
 
315
        f = 'foobar'
 
316
        self.assertEqual('foobar', osutils.safe_file_id(f))
 
317
 
 
318
    def test_from_unicode_string_ascii_contents(self):
 
319
        self.assertEqual('bargam', osutils.safe_file_id(u'bargam'))
 
320
 
 
321
    def test_from_unicode_string_unicode_contents(self):
 
322
        self.assertEqual('bargam\xc2\xae',
 
323
                         osutils.safe_file_id(u'bargam\xae'))
 
324
 
 
325
    def test_from_utf8_string(self):
 
326
        self.assertEqual('foo\xc2\xae',
 
327
                         osutils.safe_file_id('foo\xc2\xae'))
 
328
 
 
329
    def test_bad_utf8_string(self):
 
330
        # This check may eventually go away
 
331
        self.assertRaises(BzrBadParameterNotUnicode,
 
332
                          osutils.safe_file_id, '\xbb\xbb')
 
333
 
 
334
    def test_none(self):
 
335
        """Currently, None is a valid revision_id"""
 
336
        self.assertEqual(None, osutils.safe_file_id(None))
 
337
 
 
338
 
263
339
class TestWin32Funcs(TestCase):
264
340
    """Test that the _win32 versions of os utilities return appropriate paths."""
265
341
 
266
342
    def test_abspath(self):
267
343
        self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
268
344
        self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
 
345
        self.assertEqual('//HOST/path', osutils._win32_abspath(r'\\HOST\path'))
 
346
        self.assertEqual('//HOST/path', osutils._win32_abspath('//HOST/path'))
269
347
 
270
348
    def test_realpath(self):
271
349
        self.assertEqual('C:/foo', osutils._win32_realpath('C:\\foo'))
299
377
        self.assertEqual('H:/foo', osutils._win32_fixdrive('H:/foo'))
300
378
        self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
301
379
 
 
380
    def test_win98_abspath(self):
 
381
        # absolute path
 
382
        self.assertEqual('C:/foo', osutils._win98_abspath('C:\\foo'))
 
383
        self.assertEqual('C:/foo', osutils._win98_abspath('C:/foo'))
 
384
        # UNC path
 
385
        self.assertEqual('//HOST/path', osutils._win98_abspath(r'\\HOST\path'))
 
386
        self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
 
387
        # relative path
 
388
        cwd = osutils.getcwd().rstrip('/')
 
389
        drive = osutils._nt_splitdrive(cwd)[0]
 
390
        self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
 
391
        self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
 
392
        # unicode path
 
393
        u = u'\u1234'
 
394
        self.assertEqual(cwd+'/'+u, osutils._win98_abspath(u))
 
395
 
302
396
 
303
397
class TestWin32FuncsDirs(TestCaseInTempDir):
304
398
    """Test win32 functions that create files."""
305
399
    
306
400
    def test_getcwd(self):
 
401
        if win32utils.winver == 'Windows 98':
 
402
            raise TestSkipped('Windows 98 cannot handle unicode filenames')
307
403
        # Make sure getcwd can handle unicode filenames
308
404
        try:
309
405
            os.mkdir(u'mu-\xb5')