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())
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)
644
class TestPluginPaths(tests.TestCase):
646
def test_set_plugins_path_with_args(self):
648
plugin.set_plugins_path(['a', 'b'])
649
self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
651
def test_set_plugins_path_defaults(self):
653
plugin.set_plugins_path()
654
self.assertEqual(plugin.get_standard_plugins_path(),
655
bzrlib.plugins.__path__)
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)
663
from distutils.sysconfig import get_python_lib
667
if sys.platform != 'win32':
668
python_lib = get_python_lib()
669
for directory in path:
670
if directory.startswith(python_lib):
673
self.fail('No path to global plugins')
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])
680
class TestLoadPlugins(tests.TestCaseInTempDir):
682
def test_load_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__, ['.'])
690
def test_load_plugins_default(self):
692
plugin.load_plugins()
693
path = plugin.get_standard_plugins_path()
694
self.assertEqual(path, bzrlib.plugins.__path__)