~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

[merge] bzr.dev

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