815
816
def _clear_hooks(self):
816
817
# prevent hooks affecting tests
818
import bzrlib.smart.client
819
import bzrlib.smart.server
820
self._preserved_hooks = {
821
bzrlib.branch.Branch: bzrlib.branch.Branch.hooks,
822
bzrlib.mutabletree.MutableTree: bzrlib.mutabletree.MutableTree.hooks,
823
bzrlib.smart.client._SmartClient: bzrlib.smart.client._SmartClient.hooks,
824
bzrlib.smart.server.SmartTCPServer: bzrlib.smart.server.SmartTCPServer.hooks,
825
bzrlib.commands.Command: bzrlib.commands.Command.hooks,
818
self._preserved_hooks = {}
819
for key, factory in hooks.known_hooks.items():
820
parent, name = hooks.known_hooks_key_to_parent_and_attribute(key)
821
current_hooks = hooks.known_hooks_key_to_object(key)
822
self._preserved_hooks[parent] = (name, current_hooks)
827
823
self.addCleanup(self._restoreHooks)
828
# reset all hooks to an empty instance of the appropriate type
829
bzrlib.branch.Branch.hooks = bzrlib.branch.BranchHooks()
830
bzrlib.smart.client._SmartClient.hooks = bzrlib.smart.client.SmartClientHooks()
831
bzrlib.smart.server.SmartTCPServer.hooks = bzrlib.smart.server.SmartServerHooks()
832
bzrlib.commands.Command.hooks = bzrlib.commands.CommandHooks()
824
for key, factory in hooks.known_hooks.items():
825
parent, name = hooks.known_hooks_key_to_parent_and_attribute(key)
826
setattr(parent, name, factory())
834
828
def _silenceUI(self):
835
829
"""Turn off UI for duration of test"""
1288
1282
osutils.set_or_unset_env(name, value)
1290
1284
def _restoreHooks(self):
1291
for klass, hooks in self._preserved_hooks.items():
1292
setattr(klass, 'hooks', hooks)
1285
for klass, (name, hooks) in self._preserved_hooks.items():
1286
setattr(klass, name, hooks)
1294
1288
def knownFailure(self, reason):
1295
1289
"""This test has failed for some known reason."""