~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/transport_util.py

Add a NEWS entry and prepare submission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2007 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.tests import features
19
18
 
20
19
# SFTPTransport offers better performances but relies on paramiko, if paramiko
21
20
# is not available, we fallback to FtpTransport
22
 
if features.paramiko.available():
23
 
    from bzrlib.tests import test_sftp_transport
 
21
from bzrlib.tests import test_sftp_transport
 
22
if test_sftp_transport.paramiko_loaded:
24
23
    from bzrlib.transport import sftp
25
24
    _backing_scheme = 'sftp'
26
25
    _backing_transport_class = sftp.SFTPTransport
100
99
    def setUp(self):
101
100
        register_urlparse_netloc_protocol(_hooked_scheme)
102
101
        register_transport(_hooked_scheme, ConnectionHookedTransport)
103
 
        self.addCleanup(unregister_transport, _hooked_scheme,
104
 
                        ConnectionHookedTransport)
105
 
        self.addCleanup(_unregister_urlparse_netloc_protocol, _hooked_scheme)
 
102
 
 
103
        def unregister():
 
104
            unregister_transport(_hooked_scheme, ConnectionHookedTransport)
 
105
            _unregister_urlparse_netloc_protocol(_hooked_scheme)
 
106
 
 
107
        self.addCleanup(unregister)
106
108
        super(TestCaseWithConnectionHookedTransport, self).setUp()
107
109
        self.reset_connections()
108
110
        # Add the 'hooked' url to the permitted url list.
125
127
        return url
126
128
 
127
129
    def start_logging_connections(self):
128
 
        self.overrideAttr(InstrumentedTransport, 'hooks', TransportHooks())
129
 
        # We preserved the hooks class attribute. Now we install our hook.
130
130
        ConnectionHookedTransport.hooks.install_named_hook(
131
131
            '_set_connection', self._collect_connection, None)
 
132
        # uninstall our hooks when we are finished
 
133
        self.addCleanup(self.reset_hooks)
 
134
 
 
135
    def reset_hooks(self):
 
136
        InstrumentedTransport.hooks = TransportHooks()
132
137
 
133
138
    def reset_connections(self):
134
139
        self.connections = []