~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Aaron Bentley
  • Date: 2008-11-15 19:41:37 UTC
  • mto: This revision was merged to the branch mainline in revision 3841.
  • Revision ID: aaron@aaronbentley.com-20081115194137-wghezl9da7aluk3p
Add tests for plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
629
629
        mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.foo_bar')
630
630
        topic = plugin.ModuleHelpTopic(mod)
631
631
        self.assertEqual('foo_bar', topic.get_help_topic())
 
632
 
 
633
 
 
634
def clear_plugins(test_case):
 
635
    old_plugins_path = bzrlib.plugins.__path__
 
636
    bzrlib.plugins.__path__ = []
 
637
    plugin._loaded = False
 
638
    def restore_plugins():
 
639
        bzrlib.plugins.__path__ = old_plugins_path
 
640
        plugin._loaded = False
 
641
    test_case.addCleanup(restore_plugins)
 
642
 
 
643
 
 
644
class TestPluginPaths(tests.TestCase):
 
645
 
 
646
    def test_set_plugins_path_with_args(self):
 
647
        clear_plugins(self)
 
648
        plugin.set_plugins_path(['a', 'b'])
 
649
        self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
 
650
 
 
651
    def test_set_plugins_path_defaults(self):
 
652
        clear_plugins(self)
 
653
        plugin.set_plugins_path()
 
654
        self.assertEqual(plugin.get_standard_plugins_path(),
 
655
                         bzrlib.plugins.__path__)
 
656
 
 
657
    def test_get_standard_plugins_path(self):
 
658
        path = plugin.get_standard_plugins_path()
 
659
        self.assertEqual(plugin.get_default_plugin_path(), path[0])
 
660
        for directory in path:
 
661
            self.assertNotContainsRe(r'\\/$', directory)
 
662
        try:
 
663
            from distutils.sysconfig import get_python_lib
 
664
        except ImportError:
 
665
            pass
 
666
        else:
 
667
            if sys.platform != 'win32':
 
668
                python_lib = get_python_lib()
 
669
                for directory in path:
 
670
                    if directory.startswith(python_lib):
 
671
                        break
 
672
                else:
 
673
                    self.fail('No path to global plugins')
 
674
 
 
675
    def test_get_standard_plugins_path_env(self):
 
676
        os.environ['BZR_PLUGIN_PATH'] = 'foo/'
 
677
        self.assertEqual('foo', plugin.get_standard_plugins_path()[0])
 
678
 
 
679
 
 
680
class TestLoadPlugins(tests.TestCaseInTempDir):
 
681
 
 
682
    def test_load_plugins(self):
 
683
        clear_plugins(self)
 
684
        plugin.load_plugins(['.'])
 
685
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
 
686
        # subsequent loads are no-ops
 
687
        plugin.load_plugins(['foo'])
 
688
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
 
689
 
 
690
    def test_load_plugins_default(self):
 
691
        clear_plugins(self)
 
692
        plugin.load_plugins()
 
693
        path = plugin.get_standard_plugins_path()
 
694
        self.assertEqual(path, bzrlib.plugins.__path__)