~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
575
575
 
576
576
    def setUp(self):
577
577
        super(TestLoadFromPath, self).setUp()
578
 
        # Save the attributes that we're about to monkey-patch.
579
 
        old_plugins_path = bzrlib.plugins.__path__
580
 
        old_loaded = plugin._loaded
581
 
        old_load_from_path = plugin.load_from_path
582
 
 
583
 
        def restore():
584
 
            bzrlib.plugins.__path__ = old_plugins_path
585
 
            plugin._loaded = old_loaded
586
 
            plugin.load_from_path = old_load_from_path
587
 
 
588
 
        self.addCleanup(restore)
589
 
 
590
578
        # Change bzrlib.plugin to think no plugins have been loaded yet.
 
579
        self.addAttrCleanup(bzrlib.plugins, '__path__')
591
580
        bzrlib.plugins.__path__ = []
 
581
        self.addAttrCleanup(plugin, '_loaded')
592
582
        plugin._loaded = False
593
583
 
 
584
        self.addAttrCleanup(plugin, 'load_from_path')
594
585
        # Monkey-patch load_from_path to stop it from actually loading anything.
595
586
        def load_from_path(dirs):
596
587
            pass
645
636
 
646
637
    def setUp(self):
647
638
        super(TestEnvPluginPath, self).setUp()
648
 
        old_default = plugin.DEFAULT_PLUGIN_PATH
649
 
 
650
 
        def restore():
651
 
            plugin.DEFAULT_PLUGIN_PATH = old_default
652
 
 
653
 
        self.addCleanup(restore)
654
 
 
 
639
        self.addAttrCleanup(plugin, 'DEFAULT_PLUGIN_PATH')
655
640
        plugin.DEFAULT_PLUGIN_PATH = None
656
641
 
657
642
        self.user = plugin.get_user_plugin_path()