42
42
class TestTransport(TestCase):
43
43
"""Test the non transport-concrete class functionality."""
45
def test_urlescape(self):
46
self.assertEqual('%25', urlescape('%'))
48
45
def test__get_set_protocol_handlers(self):
49
46
handlers = _get_protocol_handlers()
50
47
self.assertNotEqual({}, handlers)
75
72
register_lazy_transport('foo', 'bzrlib.tests.test_transport',
76
73
'BadTransportHandler')
77
t = get_transport('foo://fooserver/foo')
78
# because we failed to load the transport
79
self.assertTrue(isinstance(t, LocalTransport))
75
get_transport('foo://fooserver/foo')
76
except UnsupportedProtocol, e:
78
self.assertEquals('Unsupported protocol'
79
' for url "foo://fooserver/foo":'
80
' Unable to import library "some_lib":'
81
' testing missing dependency', str(e))
83
self.fail('Did not raise UnsupportedProtocol')
81
85
# restore original values
82
86
_set_protocol_handlers(saved_handlers)
108
112
def test_abspath(self):
109
113
transport = MemoryTransport()
110
self.assertEqual("memory:/relpath", transport.abspath('relpath'))
114
self.assertEqual("memory:///relpath", transport.abspath('relpath'))
112
116
def test_relpath(self):
113
117
transport = MemoryTransport()
307
311
class BackupTransportHandler(Transport):
308
312
"""Test transport that works as a backup for the BadTransportHandler"""
316
class TestTransportImplementation(TestCaseInTempDir):
317
"""Implementation verification for transports.
319
To verify a transport we need a server factory, which is a callable
320
that accepts no parameters and returns an implementation of
321
bzrlib.transport.Server.
323
That Server is then used to construct transport instances and test
324
the transport via loopback activity.
326
Currently this assumes that the Transport object is connected to the
327
current working directory. So that whatever is done
328
through the transport, should show up in the working
329
directory, and vice-versa. This is a bug, because its possible to have
330
URL schemes which provide access to something that may not be
331
result in storage on the local disk, i.e. due to file system limits, or
332
due to it being a database or some other non-filesystem tool.
334
This also tests to make sure that the functions work with both
335
generators and lists (assuming iter(list) is effectively a generator)
339
super(TestTransportImplementation, self).setUp()
340
self._server = self.transport_server()
344
super(TestTransportImplementation, self).tearDown()
345
self._server.tearDown()
347
def get_transport(self):
348
"""Return a connected transport to the local directory."""
349
base_url = self._server.get_url()
350
# try getting the transport via the regular interface:
351
t = get_transport(base_url)
352
if not isinstance(t, self.transport_class):
353
# we did not get the correct transport class type. Override the
354
# regular connection behaviour by direct construction.
355
t = self.transport_class(base_url)