142
142
self.check_transport_contents('another contents\nfor d\n', t, 'd')
144
144
self.assertRaises(NoSuchFile,
145
t.put, 'path/doesnt/exist/c', 'contents')
145
t.put, 'path/doesnt/exist/c', StringIO('contents'))
147
147
def test_put_permissions(self):
148
148
t = self.get_transport()
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')
548
self.assertRaises(NoSuchFile, t.stat, 'adir')
550
self.assertRaises((NoSuchFile, PathError), t.rmdir, 'adir')
550
552
def test_rmdir_not_empty(self):
551
553
"""Deleting a non-empty directory raises an exception
746
748
t = t.clone('wd')
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)
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])
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'))
761
['a', 'a%2525b', 'b', 'c', 'c2'], sorted_list('.'))
762
self.assertEqual(['d', 'e'], sorted_list('c'))
759
764
if not t.is_readonly():
763
768
os.unlink('wd/c/d')
764
769
os.unlink('wd/b')
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'))
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')
778
def test_list_dir_result_is_url_escaped(self):
779
t = self.get_transport()
781
raise TestSkipped("transport not listable")
783
if not t.is_readonly():
784
self.build_tree(['a/', 'a/%'], transport=t)
786
self.build_tree(['a/', 'a/%'])
788
names = list(t.list_dir('a'))
789
self.assertEqual(['%25'], names)
790
self.assertIsInstance(names[0], str)
773
792
def test_clone(self):
774
793
# TODO: Test that clone moves up and down the filesystem
775
794
t1 = self.get_transport()
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']))
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)
918
if transport.is_readonly():
919
self.assertRaises(TransportNotPossible,
920
transport.put, 'a', 'some text for a\n')
922
self.build_tree(['from/',
926
'from/dir/b%25z', # make sure quoting is correct
929
transport.copy_tree('from', 'to')
930
paths = set(transport.iter_files_recursive())
931
self.assertEqual(paths,
887
941
def test_unicode_paths(self):
888
942
"""Test that we can read/write files with Unicode names."""