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
self.assertRaises(PathError, t.rmdir, 'adir/bdir')
548
self.assertRaises(NoSuchFile, t.stat, 'adir')
548
self.assertRaises(PathError, t.rmdir, 'adir')
550
550
def test_rmdir_not_empty(self):
551
551
"""Deleting a non-empty directory raises an exception
746
746
t = t.clone('wd')
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)
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])
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'))
759
['a', 'a%2525b', 'b', 'c', 'c2'], sorted_list('.'))
760
self.assertEqual(['d', 'e'], sorted_list('c'))
759
762
if not t.is_readonly():
763
766
os.unlink('wd/c/d')
764
767
os.unlink('wd/b')
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'))
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')
776
def test_list_dir_result_is_url_escaped(self):
777
t = self.get_transport()
779
raise TestSkipped("transport not listable")
781
if not t.is_readonly():
782
self.build_tree(['a/', 'a/%'], transport=t)
784
self.build_tree(['a/', 'a/%'])
786
names = list(t.list_dir('a'))
787
self.assertEqual(['%25'], names)
788
self.assertIsInstance(names[0], str)
773
790
def test_clone(self):
774
791
# TODO: Test that clone moves up and down the filesystem
775
792
t1 = self.get_transport()
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']))
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)
916
if transport.is_readonly():
917
self.assertRaises(TransportNotPossible,
918
transport.put, 'a', 'some text for a\n')
920
self.build_tree(['from/',
924
'from/dir/b%25z', # make sure quoting is correct
927
transport.copy_tree('from', 'to')
928
paths = set(transport.iter_files_recursive())
929
self.assertEqual(paths,
887
939
def test_unicode_paths(self):
888
940
"""Test that we can read/write files with Unicode names."""