~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Martin Pool
  • Date: 2006-02-10 09:04:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060210090435-a53447137885cb1f
Some support for falling back between transport implementations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from cStringIO import StringIO
22
22
 
23
23
from bzrlib.errors import (NoSuchFile, FileExists,
24
 
                           TransportNotPossible, ConnectionError)
 
24
                           TransportNotPossible,
 
25
                           ConnectionError,
 
26
                           DependencyNotPresent,
 
27
                           )
25
28
from bzrlib.tests import TestCase
26
29
from bzrlib.transport import (_get_protocol_handlers,
27
30
                              _get_transport_modules,
29
32
                              register_lazy_transport,
30
33
                              _set_protocol_handlers,
31
34
                              urlescape,
 
35
                              Transport,
32
36
                              )
33
37
from bzrlib.transport.memory import MemoryTransport
 
38
from bzrlib.transport.local import LocalTransport
34
39
 
35
40
 
36
41
class TestTransport(TestCase):
61
66
                             _get_transport_modules())
62
67
        finally:
63
68
            _set_protocol_handlers(handlers)
 
69
 
 
70
    def test_transport_dependency(self):
 
71
        """Transport with missing dependency causes no error"""
 
72
        saved_handlers = _get_protocol_handlers()
 
73
        try:
 
74
            register_lazy_transport('foo', 'bzrlib.tests.test_transport',
 
75
                    'BadTransportHandler')
 
76
            t = get_transport('foo://fooserver/foo')
 
77
            # because we failed to load the transport
 
78
            self.assertTrue(isinstance(t, LocalTransport))
 
79
        finally:
 
80
            _set_protocol_handlers(saved_handlers)
64
81
            
65
82
 
66
83
class TestMemoryTransport(TestCase):
181
198
            self.assertEqual(True, transport.is_readonly())
182
199
        finally:
183
200
            server.tearDown()
 
201
 
 
202
 
 
203
class BadTransportHandler(Transport):
 
204
    def __init__(self, base_url):
 
205
        raise DependencyNotPresent('some_lib', 'testing missing dependency')
 
206
 
 
207
 
 
208
class BackupTransportHandler(Transport):
 
209
    """Test transport that works as a backup for the BadTransportHandler"""