/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_transport_implementations.py

[merge] bzr.dev 1984

Show diffs side-by-side

added added

removed removed

Lines of Context:
509
509
        t.mkdir('adir')
510
510
        t.mkdir('adir/bdir')
511
511
        t.rmdir('adir/bdir')
512
 
        self.assertRaises(NoSuchFile, t.stat, 'adir/bdir')
 
512
        # ftp may not be able to raise NoSuchFile for lack of
 
513
        # details when failing
 
514
        self.assertRaises((NoSuchFile, PathError), t.rmdir, 'adir/bdir')
513
515
        t.rmdir('adir')
514
 
        self.assertRaises(NoSuchFile, t.stat, 'adir')
 
516
        self.assertRaises((NoSuchFile, PathError), t.rmdir, 'adir')
515
517
 
516
518
    def test_rmdir_not_empty(self):
517
519
        """Deleting a non-empty directory raises an exception
711
713
            os.mkdir('wd')
712
714
        t = t.clone('wd')
713
715
 
714
 
        self.assertEqual([], sorted_list(u'.'))
 
716
        self.assertEqual([], sorted_list('.'))
715
717
        # c2 is precisely one letter longer than c here to test that
716
718
        # suffixing is not confused.
 
719
        # a%25b checks that quoting is done consistently across transports
 
720
        tree_names = ['a', 'a%25b', 'b', 'c/', 'c/d', 'c/e', 'c2/']
717
721
        if not t.is_readonly():
718
 
            self.build_tree(['a', 'b', 'c/', 'c/d', 'c/e', 'c2/'], transport=t)
 
722
            self.build_tree(tree_names, transport=t)
719
723
        else:
720
 
            self.build_tree(['wd/a', 'wd/b', 'wd/c/', 'wd/c/d', 'wd/c/e', 'wd/c2/'])
 
724
            self.build_tree(['wd/' + name for name in tree_names])
721
725
 
722
 
        self.assertEqual([u'a', u'b', u'c', u'c2'], sorted_list(u'.'))
723
 
        self.assertEqual([u'd', u'e'], sorted_list(u'c'))
 
726
        self.assertEqual(
 
727
            ['a', 'a%2525b', 'b', 'c', 'c2'], sorted_list('.'))
 
728
        self.assertEqual(['d', 'e'], sorted_list('c'))
724
729
 
725
730
        if not t.is_readonly():
726
731
            t.delete('c/d')
729
734
            os.unlink('wd/c/d')
730
735
            os.unlink('wd/b')
731
736
            
732
 
        self.assertEqual([u'a', u'c', u'c2'], sorted_list('.'))
733
 
        self.assertEqual([u'e'], sorted_list(u'c'))
 
737
        self.assertEqual(['a', 'a%2525b', 'c', 'c2'], sorted_list('.'))
 
738
        self.assertEqual(['e'], sorted_list('c'))
734
739
 
735
740
        self.assertListRaises(PathError, t.list_dir, 'q')
736
741
        self.assertListRaises(PathError, t.list_dir, 'c/f')
737
742
        self.assertListRaises(PathError, t.list_dir, 'a')
738
743
 
 
744
    def test_list_dir_result_is_url_escaped(self):
 
745
        t = self.get_transport()
 
746
        if not t.listable():
 
747
            raise TestSkipped("transport not listable")
 
748
 
 
749
        if not t.is_readonly():
 
750
            self.build_tree(['a/', 'a/%'], transport=t)
 
751
        else:
 
752
            self.build_tree(['a/', 'a/%'])
 
753
        
 
754
        names = list(t.list_dir('a'))
 
755
        self.assertEqual(['%25'], names)
 
756
        self.assertIsInstance(names[0], str)
 
757
 
739
758
    def test_clone(self):
740
759
        # TODO: Test that clone moves up and down the filesystem
741
760
        t1 = self.get_transport()
838
857
                         'isolated/dir/',
839
858
                         'isolated/dir/foo',
840
859
                         'isolated/dir/bar',
 
860
                         'isolated/dir/b%25z', # make sure quoting is correct
841
861
                         'isolated/bar'],
842
862
                        transport=transport)
843
863
        paths = set(transport.iter_files_recursive())
845
865
        self.assertEqual(paths,
846
866
                    set(['isolated/dir/foo',
847
867
                         'isolated/dir/bar',
 
868
                         'isolated/dir/b%2525z',
848
869
                         'isolated/bar']))
849
870
        sub_transport = transport.clone('isolated')
850
871
        paths = set(sub_transport.iter_files_recursive())
851
 
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
 
872
        self.assertEqual(paths,
 
873
            set(['dir/foo', 'dir/bar', 'dir/b%2525z', 'bar']))
 
874
 
 
875
    def test_copy_tree(self):
 
876
        # TODO: test file contents and permissions are preserved. This test was
 
877
        # added just to ensure that quoting was handled correctly.
 
878
        # -- David Allouche 2006-08-11
 
879
        transport = self.get_transport()
 
880
        if not transport.listable():
 
881
            self.assertRaises(TransportNotPossible,
 
882
                              transport.iter_files_recursive)
 
883
            return
 
884
        if transport.is_readonly():
 
885
            self.assertRaises(TransportNotPossible,
 
886
                              transport.put, 'a', 'some text for a\n')
 
887
            return
 
888
        self.build_tree(['from/',
 
889
                         'from/dir/',
 
890
                         'from/dir/foo',
 
891
                         'from/dir/bar',
 
892
                         'from/dir/b%25z', # make sure quoting is correct
 
893
                         'from/bar'],
 
894
                        transport=transport)
 
895
        transport.copy_tree('from', 'to')
 
896
        paths = set(transport.iter_files_recursive())
 
897
        self.assertEqual(paths,
 
898
                    set(['from/dir/foo',
 
899
                         'from/dir/bar',
 
900
                         'from/dir/b%2525z',
 
901
                         'from/bar',
 
902
                         'to/dir/foo',
 
903
                         'to/dir/bar',
 
904
                         'to/dir/b%2525z',
 
905
                         'to/bar',]))
852
906
 
853
907
    def test_unicode_paths(self):
854
908
        """Test that we can read/write files with Unicode names."""