~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-11-06 16:01:48 UTC
  • mfrom: (5527.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101106160148-8maemz21jbrhpzky
(vila) Move NEWS entry into the correct section (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
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
18
19
 
19
20
# SFTPTransport offers better performances but relies on paramiko, if paramiko
20
21
# is not available, we fallback to FtpTransport
21
 
from bzrlib.tests import test_sftp_transport
22
 
if test_sftp_transport.paramiko_loaded:
 
22
if features.paramiko.available():
 
23
    from bzrlib.tests import test_sftp_transport
23
24
    from bzrlib.transport import sftp
24
25
    _backing_scheme = 'sftp'
25
26
    _backing_transport_class = sftp.SFTPTransport
33
34
 
34
35
from bzrlib.transport import (
35
36
    ConnectedTransport,
 
37
    get_transport,
36
38
    register_transport,
37
39
    register_urlparse_netloc_protocol,
38
40
    unregister_transport,
65
67
    hooks = TransportHooks()
66
68
 
67
69
    def __init__(self, base, _from_transport=None):
68
 
        assert base.startswith(_hooked_scheme + '://')
 
70
        if not base.startswith(_hooked_scheme + '://'):
 
71
            raise ValueError(base)
69
72
        # We need to trick the backing transport class about the scheme used
70
73
        # We'll do the reverse when we need to talk to the backing server
71
74
        fake_base = _change_scheme_in(base, _hooked_scheme, _backing_scheme)
97
100
    def setUp(self):
98
101
        register_urlparse_netloc_protocol(_hooked_scheme)
99
102
        register_transport(_hooked_scheme, ConnectionHookedTransport)
100
 
 
101
 
        def unregister():
102
 
            unregister_transport(_hooked_scheme, ConnectionHookedTransport)
103
 
            _unregister_urlparse_netloc_protocol(_hooked_scheme)
104
 
 
105
 
        self.addCleanup(unregister)
 
103
        self.addCleanup(unregister_transport, _hooked_scheme,
 
104
                        ConnectionHookedTransport)
 
105
        self.addCleanup(_unregister_urlparse_netloc_protocol, _hooked_scheme)
106
106
        super(TestCaseWithConnectionHookedTransport, self).setUp()
107
107
        self.reset_connections()
 
108
        # Add the 'hooked' url to the permitted url list.
 
109
        # XXX: See TestCase.start_server. This whole module shouldn't need to
 
110
        # exist - a bug has been filed on that. once its cleanedup/removed, the
 
111
        # standard test support code will work and permit the server url
 
112
        # correctly.
 
113
        url = self.get_url()
 
114
        t = get_transport(url)
 
115
        if t.base.endswith('work/'):
 
116
            t = t.clone('../..')
 
117
        self.permit_url(t.base)
108
118
 
109
119
    def get_url(self, relpath=None):
110
120
        super_self = super(TestCaseWithConnectionHookedTransport, self)
115
125
        return url
116
126
 
117
127
    def start_logging_connections(self):
118
 
        ConnectionHookedTransport.hooks.install_hook('_set_connection',
119
 
                                                     self._collect_connection)
120
 
        # uninstall our hooks when we are finished
121
 
        self.addCleanup(self.reset_hooks)
122
 
 
123
 
    def reset_hooks(self):
124
 
        InstrumentedTransport.hooks = TransportHooks()
 
128
        self.overrideAttr(InstrumentedTransport, 'hooks', TransportHooks())
 
129
        # We preserved the hooks class attribute. Now we install our hook.
 
130
        ConnectionHookedTransport.hooks.install_named_hook(
 
131
            '_set_connection', self._collect_connection, None)
125
132
 
126
133
    def reset_connections(self):
127
134
        self.connections = []