~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/transport_util.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

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
100
100
    def setUp(self):
101
101
        register_urlparse_netloc_protocol(_hooked_scheme)
102
102
        register_transport(_hooked_scheme, ConnectionHookedTransport)
103
 
        self.addCleanup(unregister_transport, _hooked_scheme,
104
 
                        ConnectionHookedTransport)
105
 
        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)
106
109
        super(TestCaseWithConnectionHookedTransport, self).setUp()
107
110
        self.reset_connections()
108
111
        # Add the 'hooked' url to the permitted url list.
125
128
        return url
126
129
 
127
130
    def start_logging_connections(self):
128
 
        self.overrideAttr(InstrumentedTransport, 'hooks', TransportHooks())
129
 
        # We preserved the hooks class attribute. Now we install our hook.
130
131
        ConnectionHookedTransport.hooks.install_named_hook(
131
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()
132
138
 
133
139
    def reset_connections(self):
134
140
        self.connections = []