~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-27 22:29:55 UTC
  • mto: (3735.39.2 clean)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090327222955-utifmfm888zerixt
Implement apply_delta_to_source which doesn't have to malloc another string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    tests,
32
32
    win32utils,
33
33
    )
 
34
from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
 
35
from bzrlib.osutils import (
 
36
        is_inside_any,
 
37
        is_inside_or_parent_of_any,
 
38
        pathjoin,
 
39
        pumpfile,
 
40
        pump_string_file,
 
41
        canonical_relpath,
 
42
        )
34
43
from bzrlib.tests import (
35
 
    file_utils,
36
 
    test__walkdirs_win32,
 
44
        Feature,
 
45
        probe_unicode_in_user_encoding,
 
46
        StringIOWrapper,
 
47
        SymlinkFeature,
 
48
        CaseInsCasePresFilenameFeature,
 
49
        TestCase,
 
50
        TestCaseInTempDir,
 
51
        TestSkipped,
 
52
        )
 
53
from bzrlib.tests.file_utils import (
 
54
    FakeReadFile,
37
55
    )
38
 
 
39
 
 
40
 
class _UTF8DirReaderFeature(tests.Feature):
 
56
from bzrlib.tests.test__walkdirs_win32 import Win32ReadDirFeature
 
57
 
 
58
 
 
59
class _UTF8DirReaderFeature(Feature):
41
60
 
42
61
    def _probe(self):
43
62
        try:
53
72
UTF8DirReaderFeature = _UTF8DirReaderFeature()
54
73
 
55
74
 
56
 
class TestOSUtils(tests.TestCaseInTempDir):
 
75
class TestOSUtils(TestCaseInTempDir):
57
76
 
58
77
    def test_contains_whitespace(self):
59
78
        self.failUnless(osutils.contains_whitespace(u' '))
132
151
        self.assertTrue(is_inside('', 'foo.c'))
133
152
 
134
153
    def test_is_inside_any(self):
135
 
        SRC_FOO_C = osutils.pathjoin('src', 'foo.c')
 
154
        SRC_FOO_C = pathjoin('src', 'foo.c')
136
155
        for dirs, fn in [(['src', 'doc'], SRC_FOO_C),
137
156
                         (['src'], SRC_FOO_C),
138
157
                         (['src'], 'src'),
139
158
                         ]:
140
 
            self.assert_(osutils.is_inside_any(dirs, fn))
 
159
            self.assert_(is_inside_any(dirs, fn))
141
160
        for dirs, fn in [(['src'], 'srccontrol'),
142
161
                         (['src'], 'srccontrol/foo')]:
143
 
            self.assertFalse(osutils.is_inside_any(dirs, fn))
 
162
            self.assertFalse(is_inside_any(dirs, fn))
144
163
 
145
164
    def test_is_inside_or_parent_of_any(self):
146
165
        for dirs, fn in [(['src', 'doc'], 'src/foo.c'),
149
168
                         (['src/bar.c', 'bla/foo.c'], 'src'),
150
169
                         (['src'], 'src'),
151
170
                         ]:
152
 
            self.assert_(osutils.is_inside_or_parent_of_any(dirs, fn))
 
171
            self.assert_(is_inside_or_parent_of_any(dirs, fn))
153
172
 
154
173
        for dirs, fn in [(['src'], 'srccontrol'),
155
174
                         (['srccontrol/foo.c'], 'src'),
156
175
                         (['src'], 'srccontrol/foo')]:
157
 
            self.assertFalse(osutils.is_inside_or_parent_of_any(dirs, fn))
 
176
            self.assertFalse(is_inside_or_parent_of_any(dirs, fn))
158
177
 
159
178
    def test_rmtree(self):
160
179
        # Check to remove tree with read-only files/dirs
221
240
            return
222
241
 
223
242
        orig_umask = osutils.get_umask()
224
 
        self.addCleanup(os.umask, orig_umask)
225
 
        os.umask(0222)
226
 
        self.assertEqual(0222, osutils.get_umask())
227
 
        os.umask(0022)
228
 
        self.assertEqual(0022, osutils.get_umask())
229
 
        os.umask(0002)
230
 
        self.assertEqual(0002, osutils.get_umask())
231
 
        os.umask(0027)
232
 
        self.assertEqual(0027, osutils.get_umask())
 
243
        try:
 
244
            os.umask(0222)
 
245
            self.assertEqual(0222, osutils.get_umask())
 
246
            os.umask(0022)
 
247
            self.assertEqual(0022, osutils.get_umask())
 
248
            os.umask(0002)
 
249
            self.assertEqual(0002, osutils.get_umask())
 
250
            os.umask(0027)
 
251
            self.assertEqual(0027, osutils.get_umask())
 
252
        finally:
 
253
            os.umask(orig_umask)
233
254
 
234
255
    def assertFormatedDelta(self, expected, seconds):
235
256
        """Assert osutils.format_delta formats as expected"""
278
299
        # dates once they do occur in output strings.
279
300
 
280
301
    def test_dereference_path(self):
281
 
        self.requireFeature(tests.SymlinkFeature)
 
302
        self.requireFeature(SymlinkFeature)
282
303
        cwd = osutils.realpath('.')
283
304
        os.mkdir('bar')
284
305
        bar_path = osutils.pathjoin(cwd, 'bar')
335
356
        osutils.host_os_dereferences_symlinks()
336
357
 
337
358
 
338
 
class TestCanonicalRelPath(tests.TestCaseInTempDir):
 
359
class TestCanonicalRelPath(TestCaseInTempDir):
339
360
 
340
 
    _test_needs_features = [tests.CaseInsCasePresFilenameFeature]
 
361
    _test_needs_features = [CaseInsCasePresFilenameFeature]
341
362
 
342
363
    def test_canonical_relpath_simple(self):
343
364
        f = file('MixedCaseName', 'w')
344
365
        f.close()
345
 
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
346
 
        real_base_dir = osutils.realpath(self.test_base_dir)
347
 
        actual = osutils.canonical_relpath(real_base_dir, 'mixedcasename')
348
 
        self.failUnlessEqual('work/MixedCaseName', actual)
 
366
        self.failUnlessEqual(
 
367
            canonical_relpath(self.test_base_dir, 'mixedcasename'),
 
368
            'work/MixedCaseName')
349
369
 
350
370
    def test_canonical_relpath_missing_tail(self):
351
371
        os.mkdir('MixedCaseParent')
352
 
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
353
 
        real_base_dir = osutils.realpath(self.test_base_dir)
354
 
        actual = osutils.canonical_relpath(real_base_dir,
355
 
                                           'mixedcaseparent/nochild')
356
 
        self.failUnlessEqual('work/MixedCaseParent/nochild', actual)
357
 
 
358
 
 
359
 
class TestPumpFile(tests.TestCase):
 
372
        self.failUnlessEqual(
 
373
            canonical_relpath(self.test_base_dir, 'mixedcaseparent/nochild'),
 
374
            'work/MixedCaseParent/nochild')
 
375
 
 
376
 
 
377
class TestPumpFile(TestCase):
360
378
    """Test pumpfile method."""
361
 
 
362
379
    def setUp(self):
363
 
        tests.TestCase.setUp(self)
 
380
        TestCase.setUp(self)
364
381
        # create a test datablock
365
382
        self.block_size = 512
366
383
        pattern = '0123456789ABCDEF'
373
390
        # make sure test data is larger than max read size
374
391
        self.assertTrue(self.test_data_len > self.block_size)
375
392
 
376
 
        from_file = file_utils.FakeReadFile(self.test_data)
 
393
        from_file = FakeReadFile(self.test_data)
377
394
        to_file = StringIO()
378
395
 
379
396
        # read (max / 2) bytes and verify read size wasn't affected
380
397
        num_bytes_to_read = self.block_size / 2
381
 
        osutils.pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
398
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
382
399
        self.assertEqual(from_file.get_max_read_size(), num_bytes_to_read)
383
400
        self.assertEqual(from_file.get_read_count(), 1)
384
401
 
385
402
        # read (max) bytes and verify read size wasn't affected
386
403
        num_bytes_to_read = self.block_size
387
404
        from_file.reset_read_count()
388
 
        osutils.pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
405
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
389
406
        self.assertEqual(from_file.get_max_read_size(), num_bytes_to_read)
390
407
        self.assertEqual(from_file.get_read_count(), 1)
391
408
 
392
409
        # read (max + 1) bytes and verify read size was limited
393
410
        num_bytes_to_read = self.block_size + 1
394
411
        from_file.reset_read_count()
395
 
        osutils.pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
412
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
396
413
        self.assertEqual(from_file.get_max_read_size(), self.block_size)
397
414
        self.assertEqual(from_file.get_read_count(), 2)
398
415
 
399
416
        # finish reading the rest of the data
400
417
        num_bytes_to_read = self.test_data_len - to_file.tell()
401
 
        osutils.pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
418
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
402
419
 
403
420
        # report error if the data wasn't equal (we only report the size due
404
421
        # to the length of the data)
414
431
        self.assertTrue(self.test_data_len > self.block_size)
415
432
 
416
433
        # retrieve data in blocks
417
 
        from_file = file_utils.FakeReadFile(self.test_data)
 
434
        from_file = FakeReadFile(self.test_data)
418
435
        to_file = StringIO()
419
 
        osutils.pumpfile(from_file, to_file, self.test_data_len,
420
 
                         self.block_size)
 
436
        pumpfile(from_file, to_file, self.test_data_len, self.block_size)
421
437
 
422
438
        # verify read size was equal to the maximum read size
423
439
        self.assertTrue(from_file.get_max_read_size() > 0)
438
454
        self.assertTrue(self.test_data_len > self.block_size)
439
455
 
440
456
        # retrieve data to EOF
441
 
        from_file = file_utils.FakeReadFile(self.test_data)
 
457
        from_file = FakeReadFile(self.test_data)
442
458
        to_file = StringIO()
443
 
        osutils.pumpfile(from_file, to_file, -1, self.block_size)
 
459
        pumpfile(from_file, to_file, -1, self.block_size)
444
460
 
445
461
        # verify read size was equal to the maximum read size
446
462
        self.assertEqual(from_file.get_max_read_size(), self.block_size)
458
474
        test verifies that any existing usages of pumpfile will not be broken
459
475
        with this new version."""
460
476
        # retrieve data using default (old) pumpfile method
461
 
        from_file = file_utils.FakeReadFile(self.test_data)
 
477
        from_file = FakeReadFile(self.test_data)
462
478
        to_file = StringIO()
463
 
        osutils.pumpfile(from_file, to_file)
 
479
        pumpfile(from_file, to_file)
464
480
 
465
481
        # report error if the data wasn't equal (we only report the size due
466
482
        # to the length of the data)
475
491
            activity.append((length, direction))
476
492
        from_file = StringIO(self.test_data)
477
493
        to_file = StringIO()
478
 
        osutils.pumpfile(from_file, to_file, buff_size=500,
479
 
                         report_activity=log_activity, direction='read')
 
494
        pumpfile(from_file, to_file, buff_size=500,
 
495
                 report_activity=log_activity, direction='read')
480
496
        self.assertEqual([(500, 'read'), (500, 'read'), (500, 'read'),
481
497
                          (36, 'read')], activity)
482
498
 
483
499
        from_file = StringIO(self.test_data)
484
500
        to_file = StringIO()
485
501
        del activity[:]
486
 
        osutils.pumpfile(from_file, to_file, buff_size=500,
487
 
                         report_activity=log_activity, direction='write')
 
502
        pumpfile(from_file, to_file, buff_size=500,
 
503
                 report_activity=log_activity, direction='write')
488
504
        self.assertEqual([(500, 'write'), (500, 'write'), (500, 'write'),
489
505
                          (36, 'write')], activity)
490
506
 
492
508
        from_file = StringIO(self.test_data)
493
509
        to_file = StringIO()
494
510
        del activity[:]
495
 
        osutils.pumpfile(from_file, to_file, buff_size=500, read_length=1028,
496
 
                         report_activity=log_activity, direction='read')
 
511
        pumpfile(from_file, to_file, buff_size=500, read_length=1028,
 
512
                 report_activity=log_activity, direction='read')
497
513
        self.assertEqual([(500, 'read'), (500, 'read'), (28, 'read')], activity)
498
514
 
499
515
 
500
516
 
501
 
class TestPumpStringFile(tests.TestCase):
 
517
class TestPumpStringFile(TestCase):
502
518
 
503
519
    def test_empty(self):
504
520
        output = StringIO()
505
 
        osutils.pump_string_file("", output)
 
521
        pump_string_file("", output)
506
522
        self.assertEqual("", output.getvalue())
507
523
 
508
524
    def test_more_than_segment_size(self):
509
525
        output = StringIO()
510
 
        osutils.pump_string_file("123456789", output, 2)
 
526
        pump_string_file("123456789", output, 2)
511
527
        self.assertEqual("123456789", output.getvalue())
512
528
 
513
529
    def test_segment_size(self):
514
530
        output = StringIO()
515
 
        osutils.pump_string_file("12", output, 2)
 
531
        pump_string_file("12", output, 2)
516
532
        self.assertEqual("12", output.getvalue())
517
533
 
518
534
    def test_segment_size_multiple(self):
519
535
        output = StringIO()
520
 
        osutils.pump_string_file("1234", output, 2)
 
536
        pump_string_file("1234", output, 2)
521
537
        self.assertEqual("1234", output.getvalue())
522
538
 
523
539
 
524
 
class TestSafeUnicode(tests.TestCase):
 
540
class TestSafeUnicode(TestCase):
525
541
 
526
542
    def test_from_ascii_string(self):
527
543
        self.assertEqual(u'foobar', osutils.safe_unicode('foobar'))
536
552
        self.assertEqual(u'foo\xae', osutils.safe_unicode('foo\xc2\xae'))
537
553
 
538
554
    def test_bad_utf8_string(self):
539
 
        self.assertRaises(errors.BzrBadParameterNotUnicode,
 
555
        self.assertRaises(BzrBadParameterNotUnicode,
540
556
                          osutils.safe_unicode,
541
557
                          '\xbb\xbb')
542
558
 
543
559
 
544
 
class TestSafeUtf8(tests.TestCase):
 
560
class TestSafeUtf8(TestCase):
545
561
 
546
562
    def test_from_ascii_string(self):
547
563
        f = 'foobar'
557
573
        self.assertEqual('foo\xc2\xae', osutils.safe_utf8('foo\xc2\xae'))
558
574
 
559
575
    def test_bad_utf8_string(self):
560
 
        self.assertRaises(errors.BzrBadParameterNotUnicode,
 
576
        self.assertRaises(BzrBadParameterNotUnicode,
561
577
                          osutils.safe_utf8, '\xbb\xbb')
562
578
 
563
579
 
564
 
class TestSafeRevisionId(tests.TestCase):
 
580
class TestSafeRevisionId(TestCase):
565
581
 
566
582
    def test_from_ascii_string(self):
567
583
        # this shouldn't give a warning because it's getting an ascii string
589
605
        self.assertEqual(None, osutils.safe_revision_id(None))
590
606
 
591
607
 
592
 
class TestSafeFileId(tests.TestCase):
 
608
class TestSafeFileId(TestCase):
593
609
 
594
610
    def test_from_ascii_string(self):
595
611
        self.assertEqual('foobar', osutils.safe_file_id('foobar'))
615
631
        self.assertEqual(None, osutils.safe_file_id(None))
616
632
 
617
633
 
618
 
class TestWin32Funcs(tests.TestCase):
619
 
    """Test that _win32 versions of os utilities return appropriate paths."""
 
634
class TestWin32Funcs(TestCase):
 
635
    """Test that the _win32 versions of os utilities return appropriate paths."""
620
636
 
621
637
    def test_abspath(self):
622
638
        self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
629
645
        self.assertEqual('C:/foo', osutils._win32_realpath('C:/foo'))
630
646
 
631
647
    def test_pathjoin(self):
632
 
        self.assertEqual('path/to/foo',
633
 
                         osutils._win32_pathjoin('path', 'to', 'foo'))
634
 
        self.assertEqual('C:/foo',
635
 
                         osutils._win32_pathjoin('path\\to', 'C:\\foo'))
636
 
        self.assertEqual('C:/foo',
637
 
                         osutils._win32_pathjoin('path/to', 'C:/foo'))
638
 
        self.assertEqual('path/to/foo',
639
 
                         osutils._win32_pathjoin('path/to/', 'foo'))
640
 
        self.assertEqual('/foo',
641
 
                         osutils._win32_pathjoin('C:/path/to/', '/foo'))
642
 
        self.assertEqual('/foo',
643
 
                         osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
 
648
        self.assertEqual('path/to/foo', osutils._win32_pathjoin('path', 'to', 'foo'))
 
649
        self.assertEqual('C:/foo', osutils._win32_pathjoin('path\\to', 'C:\\foo'))
 
650
        self.assertEqual('C:/foo', osutils._win32_pathjoin('path/to', 'C:/foo'))
 
651
        self.assertEqual('path/to/foo', osutils._win32_pathjoin('path/to/', 'foo'))
 
652
        self.assertEqual('/foo', osutils._win32_pathjoin('C:/path/to/', '/foo'))
 
653
        self.assertEqual('/foo', osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
644
654
 
645
655
    def test_normpath(self):
646
 
        self.assertEqual('path/to/foo',
647
 
                         osutils._win32_normpath(r'path\\from\..\to\.\foo'))
648
 
        self.assertEqual('path/to/foo',
649
 
                         osutils._win32_normpath('path//from/../to/./foo'))
 
656
        self.assertEqual('path/to/foo', osutils._win32_normpath(r'path\\from\..\to\.\foo'))
 
657
        self.assertEqual('path/to/foo', osutils._win32_normpath('path//from/../to/./foo'))
650
658
 
651
659
    def test_getcwd(self):
652
660
        cwd = osutils._win32_getcwd()
681
689
        self.assertEqual(cwd+'/'+u, osutils._win98_abspath(u))
682
690
 
683
691
 
684
 
class TestWin32FuncsDirs(tests.TestCaseInTempDir):
 
692
class TestWin32FuncsDirs(TestCaseInTempDir):
685
693
    """Test win32 functions that create files."""
686
694
 
687
695
    def test_getcwd(self):
688
 
        self.requireFeature(tests.UnicodeFilenameFeature)
689
 
        os.mkdir(u'mu-\xb5')
 
696
        if win32utils.winver == 'Windows 98':
 
697
            raise TestSkipped('Windows 98 cannot handle unicode filenames')
 
698
        # Make sure getcwd can handle unicode filenames
 
699
        try:
 
700
            os.mkdir(u'mu-\xb5')
 
701
        except UnicodeError:
 
702
            raise TestSkipped("Unable to create Unicode filename")
 
703
 
690
704
        os.chdir(u'mu-\xb5')
691
705
        # TODO: jam 20060427 This will probably fail on Mac OSX because
692
706
        #       it will change the normalization of B\xe5gfors
764
778
        self.assertRaises(errors.BzrError, osutils.splitpath, 'a/../b')
765
779
 
766
780
 
767
 
class TestMacFuncsDirs(tests.TestCaseInTempDir):
 
781
class TestMacFuncsDirs(TestCaseInTempDir):
768
782
    """Test mac special functions that require directories."""
769
783
 
770
784
    def test_getcwd(self):
771
 
        self.requireFeature(tests.UnicodeFilenameFeature)
772
 
        os.mkdir(u'B\xe5gfors')
 
785
        # On Mac, this will actually create Ba\u030agfors
 
786
        # but chdir will still work, because it accepts both paths
 
787
        try:
 
788
            os.mkdir(u'B\xe5gfors')
 
789
        except UnicodeError:
 
790
            raise TestSkipped("Unable to create Unicode filename")
 
791
 
773
792
        os.chdir(u'B\xe5gfors')
774
793
        self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
775
794
 
776
795
    def test_getcwd_nonnorm(self):
777
 
        self.requireFeature(tests.UnicodeFilenameFeature)
778
796
        # Test that _mac_getcwd() will normalize this path
779
 
        os.mkdir(u'Ba\u030agfors')
 
797
        try:
 
798
            os.mkdir(u'Ba\u030agfors')
 
799
        except UnicodeError:
 
800
            raise TestSkipped("Unable to create Unicode filename")
 
801
 
780
802
        os.chdir(u'Ba\u030agfors')
781
803
        self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
782
804
 
783
805
 
784
 
class TestChunksToLines(tests.TestCase):
 
806
class TestChunksToLines(TestCase):
785
807
 
786
808
    def test_smoketest(self):
787
809
        self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
798
820
        self.assertIs(chunks_to_lines, osutils.chunks_to_lines)
799
821
 
800
822
 
801
 
class TestSplitLines(tests.TestCase):
 
823
class TestSplitLines(TestCase):
802
824
 
803
825
    def test_split_unicode(self):
804
826
        self.assertEqual([u'foo\n', u'bar\xae'],
811
833
                         osutils.split_lines('foo\rbar\n'))
812
834
 
813
835
 
814
 
class TestWalkDirs(tests.TestCaseInTempDir):
 
836
class TestWalkDirs(TestCaseInTempDir):
815
837
 
816
838
    def test_walkdirs(self):
817
839
        tree = [
981
1003
 
982
1004
    def test_force_walkdirs_utf8_nt(self):
983
1005
        # Disabled because the thunk of the whole walkdirs api is disabled.
984
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1006
        self.requireFeature(Win32ReadDirFeature)
985
1007
        self._save_platform_info()
986
1008
        win32utils.winver = 'Windows NT'
987
1009
        from bzrlib._walkdirs_win32 import Win32ReadDir
988
1010
        self.assertReadFSDirIs(Win32ReadDir)
989
1011
 
990
1012
    def test_force_walkdirs_utf8_98(self):
991
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1013
        self.requireFeature(Win32ReadDirFeature)
992
1014
        self._save_platform_info()
993
1015
        win32utils.winver = 'Windows 98'
994
1016
        self.assertReadFSDirIs(osutils.UnicodeDirReader)
995
1017
 
996
1018
    def test_unicode_walkdirs(self):
997
1019
        """Walkdirs should always return unicode paths."""
998
 
        self.requireFeature(tests.UnicodeFilenameFeature)
999
1020
        name0 = u'0file-\xb6'
1000
1021
        name1 = u'1dir-\u062c\u0648'
1001
1022
        name2 = u'2file-\u0633'
1006
1027
            name1 + '/' + name1 + '/',
1007
1028
            name2,
1008
1029
            ]
1009
 
        self.build_tree(tree)
 
1030
        try:
 
1031
            self.build_tree(tree)
 
1032
        except UnicodeError:
 
1033
            raise TestSkipped('Could not represent Unicode chars'
 
1034
                              ' in current encoding.')
1010
1035
        expected_dirblocks = [
1011
1036
                ((u'', u'.'),
1012
1037
                 [(name0, name0, 'file', './' + name0),
1038
1063
 
1039
1064
        The abspath portion might be in unicode or utf-8
1040
1065
        """
1041
 
        self.requireFeature(tests.UnicodeFilenameFeature)
1042
1066
        name0 = u'0file-\xb6'
1043
1067
        name1 = u'1dir-\u062c\u0648'
1044
1068
        name2 = u'2file-\u0633'
1049
1073
            name1 + '/' + name1 + '/',
1050
1074
            name2,
1051
1075
            ]
1052
 
        self.build_tree(tree)
 
1076
        try:
 
1077
            self.build_tree(tree)
 
1078
        except UnicodeError:
 
1079
            raise TestSkipped('Could not represent Unicode chars'
 
1080
                              ' in current encoding.')
1053
1081
        name0 = name0.encode('utf8')
1054
1082
        name1 = name1.encode('utf8')
1055
1083
        name2 = name2.encode('utf8')
1099
1127
 
1100
1128
        The abspath portion should be in unicode
1101
1129
        """
1102
 
        self.requireFeature(tests.UnicodeFilenameFeature)
1103
1130
        # Use the unicode reader. TODO: split into driver-and-driven unit
1104
1131
        # tests.
1105
1132
        self._save_platform_info()
1114
1141
            name1u + '/' + name1u + '/',
1115
1142
            name2u,
1116
1143
            ]
1117
 
        self.build_tree(tree)
 
1144
        try:
 
1145
            self.build_tree(tree)
 
1146
        except UnicodeError:
 
1147
            raise TestSkipped('Could not represent Unicode chars'
 
1148
                              ' in current encoding.')
1118
1149
        name0 = name0u.encode('utf8')
1119
1150
        name1 = name1u.encode('utf8')
1120
1151
        name2 = name2u.encode('utf8')
1145
1176
        self.assertEqual(expected_dirblocks, result)
1146
1177
 
1147
1178
    def test__walkdirs_utf8_win32readdir(self):
1148
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1179
        self.requireFeature(Win32ReadDirFeature)
1149
1180
        self.requireFeature(tests.UnicodeFilenameFeature)
1150
1181
        from bzrlib._walkdirs_win32 import Win32ReadDir
1151
1182
        self._save_platform_info()
1202
1233
 
1203
1234
    def test__walkdirs_utf_win32_find_file_stat_file(self):
1204
1235
        """make sure our Stat values are valid"""
1205
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1236
        self.requireFeature(Win32ReadDirFeature)
1206
1237
        self.requireFeature(tests.UnicodeFilenameFeature)
1207
1238
        from bzrlib._walkdirs_win32 import Win32ReadDir
1208
1239
        name0u = u'0file-\xb6'
1226
1257
 
1227
1258
    def test__walkdirs_utf_win32_find_file_stat_directory(self):
1228
1259
        """make sure our Stat values are valid"""
1229
 
        self.requireFeature(test__walkdirs_win32.Win32ReadDirFeature)
 
1260
        self.requireFeature(Win32ReadDirFeature)
1230
1261
        self.requireFeature(tests.UnicodeFilenameFeature)
1231
1262
        from bzrlib._walkdirs_win32 import Win32ReadDir
1232
1263
        name0u = u'0dir-\u062c\u0648'
1317
1348
            sorted(original_paths, cmp=osutils.compare_paths_prefix_order))
1318
1349
 
1319
1350
 
1320
 
class TestCopyTree(tests.TestCaseInTempDir):
 
1351
class TestCopyTree(TestCaseInTempDir):
1321
1352
 
1322
1353
    def test_copy_basic_tree(self):
1323
1354
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
1333
1364
        self.assertEqual(['c'], os.listdir('target/b'))
1334
1365
 
1335
1366
    def test_copy_tree_symlinks(self):
1336
 
        self.requireFeature(tests.SymlinkFeature)
 
1367
        self.requireFeature(SymlinkFeature)
1337
1368
        self.build_tree(['source/'])
1338
1369
        os.symlink('a/generic/path', 'source/lnk')
1339
1370
        osutils.copy_tree('source', 'target')
1369
1400
            self.assertEqual([('source/lnk', 'target/lnk')], processed_links)
1370
1401
 
1371
1402
 
1372
 
class TestSetUnsetEnv(tests.TestCase):
 
1403
#class TestTerminalEncoding has been moved to test_osutils_encodings.py
 
1404
# [bialix] 2006/12/26
 
1405
 
 
1406
 
 
1407
class TestSetUnsetEnv(TestCase):
1373
1408
    """Test updating the environment"""
1374
1409
 
1375
1410
    def setUp(self):
1402
1437
 
1403
1438
        So Unicode strings must be encoded.
1404
1439
        """
1405
 
        uni_val, env_val = tests.probe_unicode_in_user_encoding()
 
1440
        uni_val, env_val = probe_unicode_in_user_encoding()
1406
1441
        if uni_val is None:
1407
 
            raise tests.TestSkipped(
1408
 
                'Cannot find a unicode character that works in encoding %s'
1409
 
                % (osutils.get_user_encoding(),))
 
1442
            raise TestSkipped('Cannot find a unicode character that works in'
 
1443
                              ' encoding %s' % (osutils.get_user_encoding(),))
1410
1444
 
1411
1445
        old = osutils.set_or_unset_env('BZR_TEST_ENV_VAR', uni_val)
1412
1446
        self.assertEqual(env_val, os.environ.get('BZR_TEST_ENV_VAR'))
1420
1454
        self.failIf('BZR_TEST_ENV_VAR' in os.environ)
1421
1455
 
1422
1456
 
1423
 
class TestLocalTimeOffset(tests.TestCase):
 
1457
class TestLocalTimeOffset(TestCase):
1424
1458
 
1425
1459
    def test_local_time_offset(self):
1426
1460
        """Test that local_time_offset() returns a sane value."""
1442
1476
        self.assertTrue(-eighteen_hours < offset < eighteen_hours)
1443
1477
 
1444
1478
 
1445
 
class TestSizeShaFile(tests.TestCaseInTempDir):
 
1479
class TestSizeShaFile(TestCaseInTempDir):
1446
1480
 
1447
1481
    def test_sha_empty(self):
1448
1482
        self.build_tree_contents([('foo', '')])
1464
1498
        self.assertEqual(expected_sha, sha)
1465
1499
 
1466
1500
 
1467
 
class TestShaFileByName(tests.TestCaseInTempDir):
 
1501
class TestShaFileByName(TestCaseInTempDir):
1468
1502
 
1469
1503
    def test_sha_empty(self):
1470
1504
        self.build_tree_contents([('foo', '')])
1478
1512
        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
1479
1513
 
1480
1514
 
1481
 
class TestResourceLoading(tests.TestCaseInTempDir):
 
1515
class TestResourceLoading(TestCaseInTempDir):
1482
1516
 
1483
1517
    def test_resource_string(self):
1484
1518
        # test resource in bzrlib
1494
1528
        self.assertRaises(IOError, osutils.resource_string, 'bzrlib', 'yyy.xx')
1495
1529
 
1496
1530
 
1497
 
class TestReCompile(tests.TestCase):
 
1531
class TestReCompile(TestCase):
1498
1532
 
1499
1533
    def test_re_compile_checked(self):
1500
1534
        r = osutils.re_compile_checked(r'A*', re.IGNORECASE)