/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
7015.1.3 by Martin
Tweak copyright headers
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
2
# Copyright (C) 2017-2018 Breezy developers
7015.1.2 by Martin
Make last plugins tests pass again on Python 3
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
"""Blackbox tests for plugins behaviour and commands."""
19
20
import os
21
22
from ... import (
23
    commands,
24
    )
25
from ..test_plugins import (
26
    BaseTestPlugins,
27
    )
28
29
30
class TestPluginHelp(BaseTestPlugins):
31
32
    def run_bzr_utf8_out(self, *args, **kwargs):
33
        out, _ = self.run_bzr(*args, **kwargs)
7479.2.1 by Jelmer Vernooij
Drop python2 support.
34
        return out
7015.1.2 by Martin
Make last plugins tests pass again on Python 3
35
36
    def split_help_commands(self):
37
        help = {}
38
        current = None
39
        out = self.run_bzr_utf8_out('--no-plugins help commands')
40
        for line in out.splitlines():
41
            if not line.startswith(' '):
42
                current = line.split()[0]
43
            help[current] = help.get(current, '') + line
44
45
        return help
46
47
    def test_plugin_help_builtins_unaffected(self):
48
        # Check we don't get false positives
49
        help_commands = self.split_help_commands()
50
        for cmd_name in commands.builtin_command_names():
51
            if cmd_name in commands.plugin_command_names():
52
                continue
53
            try:
54
                help = commands.get_cmd_object(cmd_name).get_help_text()
55
            except NotImplementedError:
56
                # some commands have no help
57
                pass
58
            else:
59
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
60
61
            if cmd_name in help_commands:
62
                # some commands are hidden
63
                help = help_commands[cmd_name]
64
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
65
66
    def test_plugin_help_shows_plugin(self):
67
        # Create a test plugin
68
        os.mkdir('plugin_test')
69
        source = (
70
            "from breezy import commands\n"
71
            "class cmd_myplug(commands.Command):\n"
72
            "    __doc__ = '''Just a simple test plugin.'''\n"
73
            "    aliases = ['mplg']\n"
74
            "    def run(self):\n"
75
            "        print ('Hello from my plugin')\n"
76
        )
77
        self.create_plugin('myplug', source, 'plugin_test')
78
79
        # Check its help
80
        self.load_with_paths(['plugin_test'])
81
        myplug = self.plugins['myplug'].module
82
        commands.register_command(myplug.cmd_myplug)
83
        self.addCleanup(commands.plugin_cmds.remove, 'myplug')
84
        help = self.run_bzr_utf8_out('help myplug')
85
        self.assertContainsRe(help, 'plugin "myplug"')
86
        help = self.split_help_commands()['myplug']
87
        self.assertContainsRe(help, '\\[myplug\\]')