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')
514
self.assertRaises(NoSuchFile, t.stat, 'adir')
516
self.assertRaises((NoSuchFile, PathError), t.rmdir, 'adir')
516
518
def test_rmdir_not_empty(self):
517
519
"""Deleting a non-empty directory raises an exception
712
714
t = t.clone('wd')
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)
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])
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'))
727
['a', 'a%2525b', 'b', 'c', 'c2'], sorted_list('.'))
728
self.assertEqual(['d', 'e'], sorted_list('c'))
725
730
if not t.is_readonly():
729
734
os.unlink('wd/c/d')
730
735
os.unlink('wd/b')
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'))
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')
744
def test_list_dir_result_is_url_escaped(self):
745
t = self.get_transport()
747
raise TestSkipped("transport not listable")
749
if not t.is_readonly():
750
self.build_tree(['a/', 'a/%'], transport=t)
752
self.build_tree(['a/', 'a/%'])
754
names = list(t.list_dir('a'))
755
self.assertEqual(['%25'], names)
756
self.assertIsInstance(names[0], str)
739
758
def test_clone(self):
740
759
# TODO: Test that clone moves up and down the filesystem
741
760
t1 = self.get_transport()
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']))
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)
884
if transport.is_readonly():
885
self.assertRaises(TransportNotPossible,
886
transport.put, 'a', 'some text for a\n')
888
self.build_tree(['from/',
892
'from/dir/b%25z', # make sure quoting is correct
895
transport.copy_tree('from', 'to')
896
paths = set(transport.iter_files_recursive())
897
self.assertEqual(paths,
853
907
def test_unicode_paths(self):
854
908
"""Test that we can read/write files with Unicode names."""