~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/transport_util.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-20 18:55:04 UTC
  • mfrom: (4971.2.2 505762)
  • Revision ID: pqm@pqm.ubuntu.com-20100120185504-es1x5ntwauunwxvp
(nmb) Explain bound branches in "branches" help topic

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2009 Canonical Ltd
2
2
#
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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import bzrlib.hooks
18
 
from bzrlib import transport
19
18
from bzrlib.tests import features
20
19
 
21
20
# SFTPTransport offers better performances but relies on paramiko, if paramiko
35
34
 
36
35
from bzrlib.transport import (
37
36
    ConnectedTransport,
 
37
    get_transport,
38
38
    register_transport,
39
39
    register_urlparse_netloc_protocol,
40
40
    unregister_transport,
47
47
    """Dict-mapping hook name to a list of callables for transport hooks"""
48
48
 
49
49
    def __init__(self):
50
 
        super(TransportHooks, self).__init__("bzrlib.tests.transport_util",
51
 
            "InstrumentedTransport.hooks")
 
50
        super(TransportHooks, self).__init__()
52
51
        # Invoked when the transport has just created a new connection.
53
52
        # The api signature is (transport, connection, credentials)
54
53
        self['_set_connection'] = []
101
100
    def setUp(self):
102
101
        register_urlparse_netloc_protocol(_hooked_scheme)
103
102
        register_transport(_hooked_scheme, ConnectionHookedTransport)
104
 
        self.addCleanup(unregister_transport, _hooked_scheme,
105
 
                        ConnectionHookedTransport)
106
 
        self.addCleanup(_unregister_urlparse_netloc_protocol, _hooked_scheme)
 
103
 
 
104
        def unregister():
 
105
            unregister_transport(_hooked_scheme, ConnectionHookedTransport)
 
106
            _unregister_urlparse_netloc_protocol(_hooked_scheme)
 
107
 
 
108
        self.addCleanup(unregister)
107
109
        super(TestCaseWithConnectionHookedTransport, self).setUp()
108
110
        self.reset_connections()
109
111
        # Add the 'hooked' url to the permitted url list.
112
114
        # standard test support code will work and permit the server url
113
115
        # correctly.
114
116
        url = self.get_url()
115
 
        t = transport.get_transport(url)
 
117
        t = get_transport(url)
116
118
        if t.base.endswith('work/'):
117
119
            t = t.clone('../..')
118
120
        self.permit_url(t.base)
126
128
        return url
127
129
 
128
130
    def start_logging_connections(self):
129
 
        self.overrideAttr(InstrumentedTransport, 'hooks', TransportHooks())
130
 
        # We preserved the hooks class attribute. Now we install our hook.
131
131
        ConnectionHookedTransport.hooks.install_named_hook(
132
132
            '_set_connection', self._collect_connection, None)
 
133
        # uninstall our hooks when we are finished
 
134
        self.addCleanup(self.reset_hooks)
 
135
 
 
136
    def reset_hooks(self):
 
137
        InstrumentedTransport.hooks = TransportHooks()
133
138
 
134
139
    def reset_connections(self):
135
140
        self.connections = []