/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 bzrlib/tests/test_plugins.py

  • Committer: Marius Kruger
  • Date: 2007-08-12 08:15:15 UTC
  • mfrom: (2695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2979.
  • Revision ID: amanic@gmail.com-20070812081515-vgekipfhohcuj6rn
merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2007 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
148
148
    def split_help_commands(self):
149
149
        help = {}
150
150
        current = None
151
 
        for line in self.capture('help commands').splitlines():
 
151
        for line in self.run_bzr('help commands')[0].splitlines():
152
152
            if not line.startswith(' '):
153
153
                current = line.split()[0]
154
154
            help[current] = help.get(current, '') + line
167
167
                # some commands have no help
168
168
                pass
169
169
            else:
170
 
                self.assertNotContainsRe(help, 'From plugin "[^"]*"')
 
170
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
171
171
 
172
172
            if cmd_name in help_commands.keys():
173
173
                # some commands are hidden
174
174
                help = help_commands[cmd_name]
175
 
                self.assertNotContainsRe(help, 'From plugin "[^"]*"')
 
175
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
176
176
 
177
177
    def test_plugin_help_shows_plugin(self):
178
178
        # Create a test plugin
185
185
            # Check its help
186
186
            bzrlib.plugin.load_from_path(['plugin_test'])
187
187
            bzrlib.commands.register_command( bzrlib.plugins.myplug.cmd_myplug)
188
 
            help = self.capture('help myplug')
189
 
            self.assertContainsRe(help, 'From plugin "myplug"')
 
188
            help = self.run_bzr('help myplug')[0]
 
189
            self.assertContainsRe(help, 'plugin "myplug"')
190
190
            help = self.split_help_commands()['myplug']
191
191
            self.assertContainsRe(help, '\[myplug\]')
192
192
        finally:
208
208
    def check_plugin_load(self, zip_name, plugin_name):
209
209
        self.assertFalse(plugin_name in dir(bzrlib.plugins),
210
210
                         'Plugin already loaded')
 
211
        old_path = bzrlib.plugins.__path__
211
212
        try:
 
213
            # this is normally done by load_plugins -> set_plugins_path
 
214
            bzrlib.plugins.__path__ = [zip_name]
212
215
            bzrlib.plugin.load_from_zip(zip_name)
213
216
            self.assertTrue(plugin_name in dir(bzrlib.plugins),
214
217
                            'Plugin is not loaded')
216
219
            # unregister plugin
217
220
            if getattr(bzrlib.plugins, plugin_name, None):
218
221
                delattr(bzrlib.plugins, plugin_name)
 
222
                del sys.modules['bzrlib.plugins.' + plugin_name]
 
223
            bzrlib.plugins.__path__ = old_path
219
224
 
220
225
    def test_load_module(self):
221
226
        self.make_zipped_plugin('./test.zip', 'ziplug.py')
250
255
        index = plugin.PluginsHelpIndex()
251
256
        self.assertEqual([], index.get_topics(None))
252
257
 
253
 
    def test_get_topics_launchpad(self):
254
 
        """Searching for 'launchpad' returns the launchpad plugin docstring."""
 
258
    def test_get_topics_for_plugin(self):
 
259
        """Searching for plugin name gets its docstring."""
255
260
        index = plugin.PluginsHelpIndex()
256
 
        # if bzr was run with '--no-plugins' we need to manually load the
257
 
        # reference plugin. Its shipped with bzr, and loading at this point
258
 
        # won't add additional tests to run.
259
 
        import bzrlib.plugins.launchpad
260
 
        topics = index.get_topics('launchpad')
261
 
        self.assertEqual(1, len(topics))
262
 
        self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
263
 
        self.assertEqual(bzrlib.plugins.launchpad, topics[0].module)
 
261
        # make a new plugin here for this test, even if we're run with
 
262
        # --no-plugins
 
263
        self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
 
264
        demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
 
265
        sys.modules['bzrlib.plugins.demo_module'] = demo_module
 
266
        try:
 
267
            topics = index.get_topics('demo_module')
 
268
            self.assertEqual(1, len(topics))
 
269
            self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
 
270
            self.assertEqual(demo_module, topics[0].module)
 
271
        finally:
 
272
            del sys.modules['bzrlib.plugins.demo_module']
264
273
 
265
274
    def test_get_topics_no_topic(self):
266
275
        """Searching for something that is not a plugin returns []."""
274
283
        index = plugin.PluginsHelpIndex()
275
284
        self.assertEqual('plugins/', index.prefix)
276
285
 
277
 
    def test_get_topic_with_prefix(self):
278
 
        """Searching for plugins/launchpad returns launchpad module help."""
 
286
    def test_get_plugin_topic_with_prefix(self):
 
287
        """Searching for plugins/demo_module returns help."""
279
288
        index = plugin.PluginsHelpIndex()
280
 
        # if bzr was run with '--no-plugins' we need to manually load the
281
 
        # reference plugin. Its shipped with bzr, and loading at this point
282
 
        # won't add additional tests to run.
283
 
        import bzrlib.plugins.launchpad
284
 
        topics = index.get_topics('plugins/launchpad')
285
 
        self.assertEqual(1, len(topics))
286
 
        self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
287
 
        self.assertEqual(bzrlib.plugins.launchpad, topics[0].module)
 
289
        self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
 
290
        demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
 
291
        sys.modules['bzrlib.plugins.demo_module'] = demo_module
 
292
        try:
 
293
            topics = index.get_topics('plugins/demo_module')
 
294
            self.assertEqual(1, len(topics))
 
295
            self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
 
296
            self.assertEqual(demo_module, topics[0].module)
 
297
        finally:
 
298
            del sys.modules['bzrlib.plugins.demo_module']
288
299
 
289
300
 
290
301
class FakeModule(object):