556
555
mod = FakeModule(None, 'demo')
557
556
topic = plugin.ModuleHelpTopic(mod)
558
557
self.assertEqual("Plugin 'demo' has no docstring.\n",
559
topic.get_help_text())
558
topic.get_help_text())
561
560
def test_get_help_text_no_carriage_return(self):
562
561
"""ModuleHelpTopic.get_help_text adds a \n if needed."""
563
562
mod = FakeModule('one line of help', 'demo')
564
563
topic = plugin.ModuleHelpTopic(mod)
565
564
self.assertEqual("one line of help\n",
566
topic.get_help_text())
565
topic.get_help_text())
568
567
def test_get_help_text_carriage_return(self):
569
568
"""ModuleHelpTopic.get_help_text adds a \n if needed."""
570
569
mod = FakeModule('two lines of help\nand more\n', 'demo')
571
570
topic = plugin.ModuleHelpTopic(mod)
572
571
self.assertEqual("two lines of help\nand more\n",
573
topic.get_help_text())
572
topic.get_help_text())
575
574
def test_get_help_text_with_additional_see_also(self):
576
575
mod = FakeModule('two lines of help\nand more', 'demo')
577
576
topic = plugin.ModuleHelpTopic(mod)
578
self.assertEqual("two lines of help\nand more\n\n:See also: bar, foo\n",
579
topic.get_help_text(['foo', 'bar']))
578
"two lines of help\nand more\n\n:See also: bar, foo\n",
579
topic.get_help_text(['foo', 'bar']))
581
581
def test_get_help_topic(self):
582
582
"""The help topic for a plugin is its module name."""
602
603
os.environ['BRZ_PLUGIN_PATH'] = os.pathsep.join(setting_dirs)
603
604
actual = [(p if t == 'path' else t.upper())
604
for p, t in plugin._env_plugin_path()]
605
for p, t in plugin._env_plugin_path()]
605
606
self.assertEqual(expected_dirs, actual)
607
608
def test_default(self):
608
self.check_path([self.user, self.core, self.site],
609
self.check_path([self.user, self.core, self.entrypoints, self.site],
611
612
def test_adhoc_policy(self):
612
self.check_path([self.user, self.core, self.site],
613
self.check_path([self.user, self.core, self.site, self.entrypoints],
613
614
['+user', '+core', '+site'])
615
616
def test_fallback_policy(self):
616
self.check_path([self.core, self.site, self.user],
617
self.check_path([self.core, self.site, self.user, self.entrypoints],
617
618
['+core', '+site', '+user'])
619
620
def test_override_policy(self):
620
self.check_path([self.user, self.site, self.core],
621
self.check_path([self.user, self.site, self.core, self.entrypoints],
621
622
['+user', '+site', '+core'])
623
624
def test_disable_user(self):
624
self.check_path([self.core, self.site], ['-user'])
625
self.check_path([self.core, self.entrypoints, self.site], ['-user'])
626
627
def test_disable_user_twice(self):
627
628
# Ensures multiple removals don't left cruft
628
self.check_path([self.core, self.site], ['-user', '-user'])
629
self.check_path([self.core, self.entrypoints, self.site], ['-user', '-user'])
630
631
def test_duplicates_are_removed(self):
631
self.check_path([self.user, self.core, self.site],
632
self.check_path([self.user, self.core, self.entrypoints, self.site],
632
633
['+user', '+user'])
633
634
# And only the first reference is kept (since the later references will
634
635
# only produce '<plugin> already loaded' mutters)
635
self.check_path([self.user, self.core, self.site],
636
self.check_path([self.user, self.core, self.site, self.entrypoints],
636
637
['+user', '+user', '+core',
637
638
'+user', '+site', '+site',
640
641
def test_disable_overrides_enable(self):
641
self.check_path([self.core, self.site], ['-user', '+user'])
642
self.check_path([self.core, self.entrypoints, self.site], ['-user', '+user'])
643
644
def test_disable_core(self):
644
self.check_path([self.site], ['-core'])
645
self.check_path([self.user, self.site], ['+user', '-core'])
645
self.check_path([self.entrypoints, self.site], ['-core'])
646
self.check_path([self.user, self.entrypoints, self.site], ['+user', '-core'])
647
648
def test_disable_site(self):
648
self.check_path([self.core], ['-site'])
649
self.check_path([self.user, self.core], ['-site', '+user'])
649
self.check_path([self.core, self.entrypoints], ['-site'])
650
self.check_path([self.user, self.core, self.entrypoints], ['-site', '+user'])
651
652
def test_override_site(self):
652
self.check_path(['mysite', self.user, self.core],
653
self.check_path(['mysite', self.user, self.core, self.entrypoints],
653
654
['mysite', '-site', '+user'])
654
self.check_path(['mysite', self.core],
655
self.check_path(['mysite', self.core, self.entrypoints],
655
656
['mysite', '-site'])
657
658
def test_override_core(self):
658
self.check_path(['mycore', self.user, self.site],
659
self.check_path(['mycore', self.user, self.site, self.entrypoints],
659
660
['mycore', '-core', '+user', '+site'])
660
self.check_path(['mycore', self.site],
661
self.check_path(['mycore', self.entrypoints, self.site],
661
662
['mycore', '-core'])
663
664
def test_my_plugin_only(self):
664
self.check_path(['myplugin'], ['myplugin', '-user', '-core', '-site'])
667
['myplugin', '-user', '-core', '-site', '-entrypoints'])
666
669
def test_my_plugin_first(self):
667
self.check_path(['myplugin', self.core, self.site, self.user],
670
self.check_path(['myplugin', self.core, self.site, self.user, self.entrypoints],
668
671
['myplugin', '+core', '+site', '+user'])
670
673
def test_bogus_references(self):
671
self.check_path(['+foo', '-bar', self.core, self.site],
674
self.check_path(['+foo', '-bar', self.core, self.entrypoints, self.site],
672
675
['+foo', '-bar'])
891
897
""", ''.join(plugin.describe_plugins(state=self)))
900
class DummyPlugin(object):
904
class TestLoadEnvPlugin(BaseTestPlugins):
906
_test_needs_features = [pkg_resources_feature]
908
def setup_plugin(self, source=""):
909
# This test tests a new plugin appears in breezy.plugin.plugins().
910
# check the plugin is not loaded already
911
self.assertPluginUnknown('plugin')
912
# write a plugin that _cannot_ fail to load.
914
d = pkg_resources.Distribution(__file__)
915
ep = pkg_resources.EntryPoint.parse(
916
'plugin = ' + __name__ + ':DummyPlugin', dist=d)
917
d._ep_map = {'breezy.plugin': {'plugin': ep}}
918
pkg_resources.working_set.add(d, 'plugin', replace=True)
919
eps = list(pkg_resources.iter_entry_points('breezy.plugin'))
920
self.assertEqual(['plugin'], [ep.name for ep in eps])
921
self.load_with_paths(['.'])
922
self.addCleanup(d._ep_map.clear)
924
def test_plugin_loaded(self):
925
self.assertPluginUnknown('plugin')
927
p = self.plugins['plugin']
928
self.assertIsInstance(p, breezy.plugin.PlugIn)
929
self.assertIs(p.module, sys.modules[self.module_prefix + 'plugin'])
931
def test_plugin_loaded_disabled(self):
932
self.assertPluginUnknown('plugin')
933
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'plugin')
935
self.assertNotIn('plugin', self.plugins)