~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Robert Collins
  • Date: 2009-03-12 02:43:46 UTC
  • mto: This revision was merged to the branch mainline in revision 4133.
  • Revision ID: robertc@robertcollins.net-20090312024346-jx3vpibkrwo1qxar
Create a single registry of all Hooks classes, removing the test suite knowledge of such hooks and allowing plugins to sensibly and safely define new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    bzrdir,
54
54
    debug,
55
55
    errors,
 
56
    hooks,
56
57
    memorytree,
57
58
    osutils,
58
59
    progress,
814
815
 
815
816
    def _clear_hooks(self):
816
817
        # prevent hooks affecting tests
817
 
        import bzrlib.branch
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,
826
 
            }
 
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())
833
827
 
834
828
    def _silenceUI(self):
835
829
        """Turn off UI for duration of test"""
1288
1282
            osutils.set_or_unset_env(name, value)
1289
1283
 
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)
1293
1287
 
1294
1288
    def knownFailure(self, reason):
1295
1289
        """This test has failed for some known reason."""