32
32
from bzrlib.osutils import getcwd
33
33
from bzrlib.tests import TestCaseInTempDir, TestSkipped
34
from bzrlib.tests.test_transport import TestTransportImplementation
34
35
from bzrlib.transport import memory
35
36
import bzrlib.transport
36
37
import bzrlib.urlutils as urlutils
48
class TestTransportImplementation(TestCaseInTempDir):
49
"""Implementation verification for transports.
51
To verify a transport we need a server factory, which is a callable
52
that accepts no parameters and returns an implementation of
53
bzrlib.transport.Server.
55
That Server is then used to construct transport instances and test
56
the transport via loopback activity.
58
Currently this assumes that the Transport object is connected to the
59
current working directory. So that whatever is done
60
through the transport, should show up in the working
61
directory, and vice-versa. This is a bug, because its possible to have
62
URL schemes which provide access to something that may not be
63
result in storage on the local disk, i.e. due to file system limits, or
64
due to it being a database or some other non-filesystem tool.
66
This also tests to make sure that the functions work with both
67
generators and lists (assuming iter(list) is effectively a generator)
71
super(TestTransportImplementation, self).setUp()
72
self._server = self.transport_server()
76
super(TestTransportImplementation, self).tearDown()
77
self._server.tearDown()
49
class TransportTests(TestTransportImplementation):
79
51
def check_transport_contents(self, content, transport, relpath):
80
52
"""Check that transport.get(relpath).read() == content."""
81
53
self.assertEqualDiff(content, transport.get(relpath).read())
83
def get_transport(self):
84
"""Return a connected transport to the local directory."""
85
base_url = self._server.get_url()
86
t = bzrlib.transport.get_transport(base_url)
87
if not isinstance(t, self.transport_class):
88
# we want to make sure to construct one particular class, even if
89
# there are several available implementations of this transport;
90
# therefore construct it by hand rather than through the regular
91
# get_transport method
92
t = self.transport_class(base_url)
95
55
def assertListRaises(self, excClass, func, *args, **kwargs):
96
56
"""Fail unless excClass is raised when the iterator from func is used.
187
147
if t.is_readonly():
149
if not t._can_roundtrip_unix_modebits():
150
# Can't roundtrip, so no need to run this test
189
152
t.put('mode644', StringIO('test text\n'), mode=0644)
190
153
self.assertTransportMode(t, 'mode644', 0644)
191
154
t.put('mode666', StringIO('test text\n'), mode=0666)
700
663
except NotImplementedError:
701
664
raise TestSkipped("Transport %s has no bogus URL support." %
702
665
self._server.__class__)
703
t = bzrlib.transport.get_transport(url)
667
t = bzrlib.transport.get_transport(url)
705
668
t.get('.bzr/branch')
706
669
except (ConnectionError, NoSuchFile), e:
708
671
except (Exception), e:
709
self.fail('Wrong exception thrown (%s): %s'
710
% (e.__class__.__name__, e))
672
self.fail('Wrong exception thrown (%s.%s): %s'
673
% (e.__class__.__module__, e.__class__.__name__, e))
712
675
self.fail('Did not get the expected ConnectionError or NoSuchFile.')
913
876
"""Test that we can read/write files with Unicode names."""
914
877
t = self.get_transport()
916
files = [u'\xe5', # a w/ circle iso-8859-1
917
u'\xe4', # a w/ dots iso-8859-1
879
# With FAT32 and certain encodings on win32
880
# '\xe5' and '\xe4' actually map to the same file
881
# adding a suffix kicks in the 'preserving but insensitive'
882
# route, and maintains the right files
883
files = [u'\xe5.1', # a w/ circle iso-8859-1
884
u'\xe4.2', # a w/ dots iso-8859-1
918
885
u'\u017d', # Z with umlat iso-8859-2
919
886
u'\u062c', # Arabic j
920
887
u'\u0410', # Russian A
981
948
if transport.is_readonly():
982
949
file('a', 'w').write('0123456789')
984
transport.put('a', StringIO('01234567890'))
951
transport.put('a', StringIO('0123456789'))
986
953
d = list(transport.readv('a', ((0, 1), (1, 1), (3, 2), (9, 1))))
987
954
self.assertEqual(d[0], (0, '0'))
988
955
self.assertEqual(d[1], (1, '1'))
989
956
self.assertEqual(d[2], (3, '34'))
990
957
self.assertEqual(d[3], (9, '9'))