238
237
self.assertEqual(expected_path, bzrlib.plugins.__path__)
240
239
bzrlib.plugins.__path__ = old_path
242
class TestHelpIndex(tests.TestCase):
243
"""Tests for the PluginsHelpIndex class."""
245
def test_default_constructable(self):
246
index = plugin.PluginsHelpIndex()
248
def test_get_topics_None(self):
249
"""Searching for None returns an empty list."""
250
index = plugin.PluginsHelpIndex()
251
self.assertEqual([], index.get_topics(None))
253
def test_get_topics_launchpad(self):
254
"""Searching for 'launchpad' returns the launchpad plugin docstring."""
255
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)
265
def test_get_topics_no_topic(self):
266
"""Searching for something that is not a plugin returns []."""
267
# test this by using a name that cannot be a plugin - its not
268
# a valid python identifier.
269
index = plugin.PluginsHelpIndex()
270
self.assertEqual([], index.get_topics('nothing by this name'))
272
def test_prefix(self):
273
"""PluginsHelpIndex has a prefix of 'plugins/'."""
274
index = plugin.PluginsHelpIndex()
275
self.assertEqual('plugins/', index.prefix)
277
def test_get_topic_with_prefix(self):
278
"""Searching for plugins/launchpad returns launchpad module help."""
279
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)
290
class FakeModule(object):
291
"""A fake module to test with."""
293
def __init__(self, doc, name):
298
class TestModuleHelpTopic(tests.TestCase):
299
"""Tests for the ModuleHelpTopic class."""
301
def test_contruct(self):
302
"""Construction takes the module to document."""
303
mod = FakeModule('foo', 'foo')
304
topic = plugin.ModuleHelpTopic(mod)
305
self.assertEqual(mod, topic.module)
307
def test_get_help_text_None(self):
308
"""A ModuleHelpTopic returns the docstring for get_help_text."""
309
mod = FakeModule(None, 'demo')
310
topic = plugin.ModuleHelpTopic(mod)
311
self.assertEqual("Plugin 'demo' has no docstring.\n",
312
topic.get_help_text())
314
def test_get_help_text_no_carriage_return(self):
315
"""ModuleHelpTopic.get_help_text adds a \n if needed."""
316
mod = FakeModule('one line of help', 'demo')
317
topic = plugin.ModuleHelpTopic(mod)
318
self.assertEqual("one line of help\n",
319
topic.get_help_text())
321
def test_get_help_text_carriage_return(self):
322
"""ModuleHelpTopic.get_help_text adds a \n if needed."""
323
mod = FakeModule('two lines of help\nand more\n', 'demo')
324
topic = plugin.ModuleHelpTopic(mod)
325
self.assertEqual("two lines of help\nand more\n",
326
topic.get_help_text())
328
def test_get_help_text_with_additional_see_also(self):
329
mod = FakeModule('two lines of help\nand more', 'demo')
330
topic = plugin.ModuleHelpTopic(mod)
331
self.assertEqual("two lines of help\nand more\nSee also: bar, foo\n",
332
topic.get_help_text(['foo', 'bar']))
334
def test_get_help_topic(self):
335
"""The help topic for a plugin is its module name."""
336
mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.demo')
337
topic = plugin.ModuleHelpTopic(mod)
338
self.assertEqual('demo', topic.get_help_topic())
339
mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.foo_bar')
340
topic = plugin.ModuleHelpTopic(mod)
341
self.assertEqual('foo_bar', topic.get_help_topic())