1
# Copyright (C) 2005-2012, 2016 Canonical Ltd, 2017 Breezy developers
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
2
# Copyright (C) 2017-2018 Breezy developers
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
52
50
super(BaseTestPlugins, self).setUp()
53
51
self.module_name = "breezy.testingplugins"
54
52
self.module_prefix = self.module_name + "."
55
self.module = module_from_spec(self.module_name)
53
self.module = types.ModuleType(self.module_name)
57
55
self.overrideAttr(plugin, "_MODULE_PREFIX", self.module_prefix)
58
56
self.overrideAttr(breezy, "testingplugins", self.module)
482
480
self.assertEqual("1.2.3.2", plugin.__version__)
485
# GZ 2017-06-02: Move this suite to blackbox, as it's what it actually is.
486
class TestPluginHelp(BaseTestPlugins):
488
def split_help_commands(self):
491
out, err = self.run_bzr('--no-plugins help commands')
492
for line in out.splitlines():
493
if not line.startswith(' '):
494
current = line.split()[0]
495
help[current] = help.get(current, '') + line
499
def test_plugin_help_builtins_unaffected(self):
500
# Check we don't get false positives
501
help_commands = self.split_help_commands()
502
for cmd_name in breezy.commands.builtin_command_names():
503
if cmd_name in breezy.commands.plugin_command_names():
506
help = breezy.commands.get_cmd_object(cmd_name).get_help_text()
507
except NotImplementedError:
508
# some commands have no help
511
self.assertNotContainsRe(help, 'plugin "[^"]*"')
513
if cmd_name in help_commands:
514
# some commands are hidden
515
help = help_commands[cmd_name]
516
self.assertNotContainsRe(help, 'plugin "[^"]*"')
518
def test_plugin_help_shows_plugin(self):
519
# Create a test plugin
520
os.mkdir('plugin_test')
522
"from breezy import commands\n"
523
"class cmd_myplug(commands.Command):\n"
524
" __doc__ = '''Just a simple test plugin.'''\n"
525
" aliases = ['mplg']\n"
527
" print ('Hello from my plugin')\n"
529
self.create_plugin('myplug', source, 'plugin_test')
532
self.load_with_paths(['plugin_test'])
533
myplug = self.plugins['myplug'].module
534
breezy.commands.register_command(myplug.cmd_myplug)
535
self.addCleanup(breezy.commands.plugin_cmds.remove, 'myplug')
536
help = self.run_bzr('help myplug')[0]
537
self.assertContainsRe(help, 'plugin "myplug"')
538
help = self.split_help_commands()['myplug']
539
self.assertContainsRe(help, '\\[myplug\\]')
542
483
class TestHelpIndex(tests.TestCase):
543
484
"""Tests for the PluginsHelpIndex class."""