1
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
709
669
except (ConnectionError, NoSuchFile), e:
711
671
except (Exception), e:
712
self.fail('Wrong exception thrown (%s): %s'
713
% (e.__class__.__name__, e))
672
self.fail('Wrong exception thrown (%s.%s): %s'
673
% (e.__class__.__module__, e.__class__.__name__, e))
715
675
self.fail('Did not get the expected ConnectionError or NoSuchFile.')
988
948
if transport.is_readonly():
989
949
file('a', 'w').write('0123456789')
991
transport.put('a', StringIO('01234567890'))
951
transport.put('a', StringIO('0123456789'))
993
953
d = list(transport.readv('a', ((0, 1), (1, 1), (3, 2), (9, 1))))
994
954
self.assertEqual(d[0], (0, '0'))
995
955
self.assertEqual(d[1], (1, '1'))
996
956
self.assertEqual(d[2], (3, '34'))
997
957
self.assertEqual(d[3], (9, '9'))
959
def test_readv_out_of_order(self):
960
transport = self.get_transport()
961
if transport.is_readonly():
962
file('a', 'w').write('0123456789')
964
transport.put('a', StringIO('01234567890'))
966
d = list(transport.readv('a', ((1, 1), (9, 1), (0, 1), (3, 2))))
967
self.assertEqual(d[0], (1, '1'))
968
self.assertEqual(d[1], (9, '9'))
969
self.assertEqual(d[2], (0, '0'))
970
self.assertEqual(d[3], (3, '34'))