/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_plugins.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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 ...sixish import PY3
26
 
from ..test_plugins import (
27
 
    BaseTestPlugins,
28
 
    )
29
 
 
30
 
 
31
 
class TestPluginHelp(BaseTestPlugins):
32
 
 
33
 
    def run_bzr_utf8_out(self, *args, **kwargs):
34
 
        out, _ = self.run_bzr(*args, **kwargs)
35
 
        if PY3:
36
 
            return out
37
 
        else:
38
 
            return out.decode('utf-8')
39
 
 
40
 
    def split_help_commands(self):
41
 
        help = {}
42
 
        current = None
43
 
        out = self.run_bzr_utf8_out('--no-plugins help commands')
44
 
        for line in out.splitlines():
45
 
            if not line.startswith(' '):
46
 
                current = line.split()[0]
47
 
            help[current] = help.get(current, '') + line
48
 
 
49
 
        return help
50
 
 
51
 
    def test_plugin_help_builtins_unaffected(self):
52
 
        # Check we don't get false positives
53
 
        help_commands = self.split_help_commands()
54
 
        for cmd_name in commands.builtin_command_names():
55
 
            if cmd_name in commands.plugin_command_names():
56
 
                continue
57
 
            try:
58
 
                help = commands.get_cmd_object(cmd_name).get_help_text()
59
 
            except NotImplementedError:
60
 
                # some commands have no help
61
 
                pass
62
 
            else:
63
 
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
64
 
 
65
 
            if cmd_name in help_commands:
66
 
                # some commands are hidden
67
 
                help = help_commands[cmd_name]
68
 
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
69
 
 
70
 
    def test_plugin_help_shows_plugin(self):
71
 
        # Create a test plugin
72
 
        os.mkdir('plugin_test')
73
 
        source = (
74
 
            "from breezy import commands\n"
75
 
            "class cmd_myplug(commands.Command):\n"
76
 
            "    __doc__ = '''Just a simple test plugin.'''\n"
77
 
            "    aliases = ['mplg']\n"
78
 
            "    def run(self):\n"
79
 
            "        print ('Hello from my plugin')\n"
80
 
        )
81
 
        self.create_plugin('myplug', source, 'plugin_test')
82
 
 
83
 
        # Check its help
84
 
        self.load_with_paths(['plugin_test'])
85
 
        myplug = self.plugins['myplug'].module
86
 
        commands.register_command(myplug.cmd_myplug)
87
 
        self.addCleanup(commands.plugin_cmds.remove, 'myplug')
88
 
        help = self.run_bzr_utf8_out('help myplug')
89
 
        self.assertContainsRe(help, 'plugin "myplug"')
90
 
        help = self.split_help_commands()['myplug']
91
 
        self.assertContainsRe(help, '\\[myplug\\]')