~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-27 16:10:10 UTC
  • mto: (4310.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4311.
  • Revision ID: v.ladeuil+lp@free.fr-20090427161010-7swfzeagf63cpixd
Fix bug #367726 by reverting some default user handling introduced
while fixing bug #256612.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Explicitly use getpass.getuser() as default
user.

* bzrlib/transport/ftp/_gssapi.py:
(GSSAPIFtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/tests/test_sftp_transport.py:
(TestUsesAuthConfig.test_sftp_is_none_if_no_config)
(TestUsesAuthConfig.test_sftp_doesnt_prompt_username): Revert to
None as the default user.

* bzrlib/tests/test_remote.py:
(TestRemoteSSHTransportAuthentication): The really offending one:
revert to None as the default user.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig.test_username_default_no_prompt): Update
test (and some PEP8).

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Revert to None as the default
user.

* bzrlib/plugins/launchpad/account.py:
(_get_auth_user): Revert default value handling.

* bzrlib/config.py:
(AuthenticationConfig.get_user): Fix doc-string. Leave default
value handling to callers.

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