~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

Merge Tree.changes_from work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
                           TransportNotPossible,
26
26
                           ConnectionError,
27
27
                           DependencyNotPresent,
 
28
                           UnsupportedProtocol,
28
29
                           )
29
30
from bzrlib.tests import TestCase, TestCaseInTempDir
30
31
from bzrlib.transport import (_get_protocol_handlers,
32
33
                              get_transport,
33
34
                              register_lazy_transport,
34
35
                              _set_protocol_handlers,
35
 
                              urlescape,
36
36
                              Transport,
37
37
                              )
38
38
from bzrlib.transport.memory import MemoryTransport
42
42
class TestTransport(TestCase):
43
43
    """Test the non transport-concrete class functionality."""
44
44
 
45
 
    def test_urlescape(self):
46
 
        self.assertEqual('%25', urlescape('%'))
47
 
 
48
45
    def test__get_set_protocol_handlers(self):
49
46
        handlers = _get_protocol_handlers()
50
47
        self.assertNotEqual({}, handlers)
74
71
        try:
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))
 
74
            try:
 
75
                get_transport('foo://fooserver/foo')
 
76
            except UnsupportedProtocol, e:
 
77
                e_str = str(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))
 
82
            else:
 
83
                self.fail('Did not raise UnsupportedProtocol')
80
84
        finally:
81
85
            # restore original values
82
86
            _set_protocol_handlers(saved_handlers)
107
111
 
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'))
111
115
 
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"""
309
313
    pass
 
314
 
 
315
 
 
316
class TestTransportImplementation(TestCaseInTempDir):
 
317
    """Implementation verification for transports.
 
318
    
 
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.
 
322
    
 
323
    That Server is then used to construct transport instances and test
 
324
    the transport via loopback activity.
 
325
 
 
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.
 
333
 
 
334
    This also tests to make sure that the functions work with both
 
335
    generators and lists (assuming iter(list) is effectively a generator)
 
336
    """
 
337
    
 
338
    def setUp(self):
 
339
        super(TestTransportImplementation, self).setUp()
 
340
        self._server = self.transport_server()
 
341
        self._server.setUp()
 
342
 
 
343
    def tearDown(self):
 
344
        super(TestTransportImplementation, self).tearDown()
 
345
        self._server.tearDown()
 
346
        
 
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)
 
356
        return t