~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-26 10:17:22 UTC
  • mfrom: (4985.1.5 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100126101722-y213sv39buw3dgi2
Implement TestCase.overrideAttr to simplify tests setUp/cleanup

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.
591
 
        bzrlib.plugins.__path__ = []
592
 
        plugin._loaded = False
 
579
        self.overrideAttr(bzrlib.plugins, '__path__', [])
 
580
        self.overrideAttr(plugin, '_loaded', False)
593
581
 
594
582
        # Monkey-patch load_from_path to stop it from actually loading anything.
595
 
        def load_from_path(dirs):
596
 
            pass
597
 
        plugin.load_from_path = load_from_path
 
583
        self.overrideAttr(plugin, 'load_from_path', lambda dirs: None)
598
584
 
599
585
    def test_set_plugins_path_with_args(self):
600
586
        plugin.set_plugins_path(['a', 'b'])
645
631
 
646
632
    def setUp(self):
647
633
        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
 
 
655
 
        plugin.DEFAULT_PLUGIN_PATH = None
 
634
        self.overrideAttr(plugin, 'DEFAULT_PLUGIN_PATH', None)
656
635
 
657
636
        self.user = plugin.get_user_plugin_path()
658
637
        self.site = plugin.get_site_plugin_path()