/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

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
        self.check_transport_contents('another contents\nfor d\n', t, 'd')
143
143
 
144
144
        self.assertRaises(NoSuchFile,
145
 
                          t.put, 'path/doesnt/exist/c', 'contents')
 
145
                          t.put, 'path/doesnt/exist/c', StringIO('contents'))
146
146
 
147
147
    def test_put_permissions(self):
148
148
        t = self.get_transport()
543
543
        t.mkdir('adir')
544
544
        t.mkdir('adir/bdir')
545
545
        t.rmdir('adir/bdir')
546
 
        self.assertRaises(NoSuchFile, t.stat, 'adir/bdir')
 
546
        # ftp may not be able to raise NoSuchFile for lack of
 
547
        # details when failing
 
548
        self.assertRaises((NoSuchFile, PathError), t.rmdir, 'adir/bdir')
547
549
        t.rmdir('adir')
548
 
        self.assertRaises(NoSuchFile, t.stat, 'adir')
 
550
        self.assertRaises((NoSuchFile, PathError), t.rmdir, 'adir')
549
551
 
550
552
    def test_rmdir_not_empty(self):
551
553
        """Deleting a non-empty directory raises an exception
745
747
            os.mkdir('wd')
746
748
        t = t.clone('wd')
747
749
 
748
 
        self.assertEqual([], sorted_list(u'.'))
 
750
        self.assertEqual([], sorted_list('.'))
749
751
        # c2 is precisely one letter longer than c here to test that
750
752
        # suffixing is not confused.
 
753
        # a%25b checks that quoting is done consistently across transports
 
754
        tree_names = ['a', 'a%25b', 'b', 'c/', 'c/d', 'c/e', 'c2/']
751
755
        if not t.is_readonly():
752
 
            self.build_tree(['a', 'b', 'c/', 'c/d', 'c/e', 'c2/'], transport=t)
 
756
            self.build_tree(tree_names, transport=t)
753
757
        else:
754
 
            self.build_tree(['wd/a', 'wd/b', 'wd/c/', 'wd/c/d', 'wd/c/e', 'wd/c2/'])
 
758
            self.build_tree(['wd/' + name for name in tree_names])
755
759
 
756
 
        self.assertEqual([u'a', u'b', u'c', u'c2'], sorted_list(u'.'))
757
 
        self.assertEqual([u'd', u'e'], sorted_list(u'c'))
 
760
        self.assertEqual(
 
761
            ['a', 'a%2525b', 'b', 'c', 'c2'], sorted_list('.'))
 
762
        self.assertEqual(['d', 'e'], sorted_list('c'))
758
763
 
759
764
        if not t.is_readonly():
760
765
            t.delete('c/d')
763
768
            os.unlink('wd/c/d')
764
769
            os.unlink('wd/b')
765
770
            
766
 
        self.assertEqual([u'a', u'c', u'c2'], sorted_list('.'))
767
 
        self.assertEqual([u'e'], sorted_list(u'c'))
 
771
        self.assertEqual(['a', 'a%2525b', 'c', 'c2'], sorted_list('.'))
 
772
        self.assertEqual(['e'], sorted_list('c'))
768
773
 
769
774
        self.assertListRaises(PathError, t.list_dir, 'q')
770
775
        self.assertListRaises(PathError, t.list_dir, 'c/f')
771
776
        self.assertListRaises(PathError, t.list_dir, 'a')
772
777
 
 
778
    def test_list_dir_result_is_url_escaped(self):
 
779
        t = self.get_transport()
 
780
        if not t.listable():
 
781
            raise TestSkipped("transport not listable")
 
782
 
 
783
        if not t.is_readonly():
 
784
            self.build_tree(['a/', 'a/%'], transport=t)
 
785
        else:
 
786
            self.build_tree(['a/', 'a/%'])
 
787
        
 
788
        names = list(t.list_dir('a'))
 
789
        self.assertEqual(['%25'], names)
 
790
        self.assertIsInstance(names[0], str)
 
791
 
773
792
    def test_clone(self):
774
793
        # TODO: Test that clone moves up and down the filesystem
775
794
        t1 = self.get_transport()
872
891
                         'isolated/dir/',
873
892
                         'isolated/dir/foo',
874
893
                         'isolated/dir/bar',
 
894
                         'isolated/dir/b%25z', # make sure quoting is correct
875
895
                         'isolated/bar'],
876
896
                        transport=transport)
877
897
        paths = set(transport.iter_files_recursive())
879
899
        self.assertEqual(paths,
880
900
                    set(['isolated/dir/foo',
881
901
                         'isolated/dir/bar',
 
902
                         'isolated/dir/b%2525z',
882
903
                         'isolated/bar']))
883
904
        sub_transport = transport.clone('isolated')
884
905
        paths = set(sub_transport.iter_files_recursive())
885
 
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
 
906
        self.assertEqual(paths,
 
907
            set(['dir/foo', 'dir/bar', 'dir/b%2525z', 'bar']))
 
908
 
 
909
    def test_copy_tree(self):
 
910
        # TODO: test file contents and permissions are preserved. This test was
 
911
        # added just to ensure that quoting was handled correctly.
 
912
        # -- David Allouche 2006-08-11
 
913
        transport = self.get_transport()
 
914
        if not transport.listable():
 
915
            self.assertRaises(TransportNotPossible,
 
916
                              transport.iter_files_recursive)
 
917
            return
 
918
        if transport.is_readonly():
 
919
            self.assertRaises(TransportNotPossible,
 
920
                              transport.put, 'a', 'some text for a\n')
 
921
            return
 
922
        self.build_tree(['from/',
 
923
                         'from/dir/',
 
924
                         'from/dir/foo',
 
925
                         'from/dir/bar',
 
926
                         'from/dir/b%25z', # make sure quoting is correct
 
927
                         'from/bar'],
 
928
                        transport=transport)
 
929
        transport.copy_tree('from', 'to')
 
930
        paths = set(transport.iter_files_recursive())
 
931
        self.assertEqual(paths,
 
932
                    set(['from/dir/foo',
 
933
                         'from/dir/bar',
 
934
                         'from/dir/b%2525z',
 
935
                         'from/bar',
 
936
                         'to/dir/foo',
 
937
                         'to/dir/bar',
 
938
                         'to/dir/b%2525z',
 
939
                         'to/bar',]))
886
940
 
887
941
    def test_unicode_paths(self):
888
942
        """Test that we can read/write files with Unicode names."""