~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Robert Collins
  • Date: 2006-02-11 11:58:06 UTC
  • mto: (1534.1.22 integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060211115806-732dabc1e35714ed
Give format3 working trees their own last-revision marker.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 by Canonical Ltd
2
 
#
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
22
# comments.
23
23
 
24
24
import os
25
 
from StringIO import StringIO
26
25
 
27
26
import bzrlib.plugin
28
27
import bzrlib.plugins
29
 
import bzrlib.commands
30
 
import bzrlib.help
31
28
from bzrlib.tests import TestCaseInTempDir
32
29
from bzrlib.osutils import pathjoin, abspath
33
30
 
140
137
            if getattr(bzrlib.plugins, 'plugin', None):
141
138
                del bzrlib.plugins.plugin
142
139
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
143
 
 
144
 
 
145
 
class TestPluginHelp(TestCaseInTempDir):
146
 
 
147
 
    def split_help_commands(self):
148
 
        help = {}
149
 
        current = None
150
 
        for line in self.capture('help commands').splitlines():
151
 
            if line.startswith('bzr '):
152
 
                current = line.split()[1]
153
 
            help[current] = help.get(current, '') + line
154
 
 
155
 
        return help
156
 
 
157
 
    def test_plugin_help_builtins_unaffected(self):
158
 
        # Check we don't get false positives
159
 
        help_commands = self.split_help_commands()
160
 
        for cmd_name in bzrlib.commands.builtin_command_names():
161
 
            if cmd_name in bzrlib.commands.plugin_command_names():
162
 
                continue
163
 
            help = StringIO()
164
 
            try:
165
 
                bzrlib.help.help_on_command(cmd_name, help)
166
 
            except NotImplementedError:
167
 
                # some commands have no help
168
 
                pass
169
 
            else:
170
 
                help.seek(0)
171
 
                self.assertNotContainsRe(help.read(), 'From plugin "[^"]*"')
172
 
 
173
 
            if help in help_commands.keys():
174
 
                # some commands are hidden
175
 
                help = help_commands[cmd_name]
176
 
                self.assertNotContainsRe(help, 'From plugin "[^"]*"')
177
 
 
178
 
    def test_plugin_help_shows_plugin(self):
179
 
        # Create a test plugin
180
 
        os.mkdir('plugin_test')
181
 
        f = open(pathjoin('plugin_test', 'myplug.py'), 'w')
182
 
        f.write(PLUGIN_TEXT)
183
 
        f.close()
184
 
 
185
 
        try:
186
 
            # Check its help
187
 
            bzrlib.plugin.load_from_dirs(['plugin_test'])
188
 
            bzrlib.commands.register_command( bzrlib.plugins.myplug.cmd_myplug)
189
 
            help = self.capture('help myplug')
190
 
            self.assertContainsRe(help, 'From plugin "myplug"')
191
 
            help = self.split_help_commands()['myplug']
192
 
            self.assertContainsRe(help, 'From plugin "myplug"')
193
 
        finally:
194
 
            # remove the plugin 'plugin'
195
 
            if getattr(bzrlib.plugins, 'plugin', None):
196
 
                del bzrlib.plugins.plugin