~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-26 10:49:57 UTC
  • mfrom: (4987.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100126104957-dmtqnc0pckuruyla
(vila,
        jam) 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()