81
81
def get_transport(self):
82
82
"""Return a connected transport to the local directory."""
83
t = bzrlib.transport.get_transport(self._server.get_url())
84
self.failUnless(isinstance(t, self.transport_class),
85
"Got the wrong class from get_transport"
86
"(%r, expected %r)" % (t.__class__,
87
self.transport_class))
83
base_url = self._server.get_url()
84
t = bzrlib.transport.get_transport(base_url)
85
if not isinstance(t, self.transport_class):
86
# we want to make sure to construct one particular class, even if
87
# there are several available implementations of this transport;
88
# therefore construct it by hand rather than through the regular
89
# get_transport method
90
t = self.transport_class(base_url)
90
93
def assertListRaises(self, excClass, func, *args, **kwargs):
244
247
t = self.get_transport()
245
248
if t.is_readonly():
250
if not t._can_roundtrip_unix_modebits():
251
# no sense testing on this transport
247
253
# Test mkdir with a mode
248
254
t.mkdir('dmode755', mode=0755)
249
255
self.assertTransportMode(t, 'dmode755', 0755)
500
506
self.check_transport_contents(t.get('f2').read(), t, 'c')
501
507
self.check_transport_contents(t.get('f3').read(), t, 'd')
509
def test_append_mode(self):
510
# check append accepts a mode
511
t = self.get_transport()
514
t.append('f', StringIO('f'), mode=None)
503
516
def test_delete(self):
504
517
# TODO: Test Transport.delete
505
518
t = self.get_transport()
775
788
self.assertEqual([u'a', u'c', u'c2'], sorted_list('.'))
776
789
self.assertEqual([u'e'], sorted_list(u'c'))
778
self.assertListRaises(NoSuchFile, t.list_dir, 'q')
779
self.assertListRaises(NoSuchFile, t.list_dir, 'c/f')
780
self.assertListRaises(NoSuchFile, t.list_dir, 'a')
791
self.assertListRaises(PathError, t.list_dir, 'q')
792
self.assertListRaises(PathError, t.list_dir, 'c/f')
793
self.assertListRaises(PathError, t.list_dir, 'a')
782
795
def test_clone(self):
783
796
# TODO: Test that clone moves up and down the filesystem
822
835
# trailing slash should be the same.
823
836
self.assertEqual('foo', t.relpath(t.base + 'foo/'))
838
def test_relpath_at_root(self):
839
t = self.get_transport()
840
# clone all the way to the top
841
new_transport = t.clone('..')
842
while new_transport.base != t.base:
844
new_transport = t.clone('..')
845
# we must be able to get a relpath below the root
846
self.assertEqual('', t.relpath(t.base))
847
# and a deeper one should work too
848
self.assertEqual('foo/bar', t.relpath(t.base + 'foo/bar'))
825
850
def test_abspath(self):
826
851
# smoke test for abspath. Corner cases for backends like unix fs's
827
852
# that have aliasing problems like symlinks should go in backend
828
853
# specific test cases.
829
854
transport = self.get_transport()
856
# disabled because some transports might normalize urls in generating
857
# the abspath - eg http+pycurl-> just http -- mbp 20060308
830
858
self.assertEqual(transport.base + 'relpath',
831
859
transport.abspath('relpath'))
861
def test_abspath_at_root(self):
862
t = self.get_transport()
863
# clone all the way to the top
864
new_transport = t.clone('..')
865
while new_transport.base != t.base:
867
new_transport = t.clone('..')
868
# we must be able to get a abspath of the root when we ask for
869
# t.abspath('..') - this due to our choice that clone('..')
870
# should return the root from the root, combined with the desire that
871
# the url from clone('..') and from abspath('..') should be the same.
872
self.assertEqual(t.base, t.abspath('..'))
873
# '' should give us the root
874
self.assertEqual(t.base, t.abspath(''))
875
# and a path should append to the url
876
self.assertEqual(t.base + 'foo', t.abspath('foo'))
833
878
def test_iter_files_recursive(self):
834
879
transport = self.get_transport()
835
880
if not transport.listable():