1
# Copyright (C) 2005 Canonical Ltd
1
# Copyright (C) 2005, 2007 Canonical Ltd
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
250
250
index = plugin.PluginsHelpIndex()
251
251
self.assertEqual([], index.get_topics(None))
253
def test_get_topics_launchpad(self):
254
"""Searching for 'launchpad' returns the launchpad plugin docstring."""
253
def test_get_topics_for_plugin(self):
254
"""Searching for plugin name gets its docstring."""
255
255
index = plugin.PluginsHelpIndex()
256
self.assertFalse(sys.modules.has_key('bzrlib.plugins.get_topics'))
257
demo_module = FakeModule('', 'bzrlib.plugins.get_topics')
258
sys.modules['bzrlib.plugins.get_topics'] = demo_module
256
# make a new plugin here for this test, even if we're run with
258
self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
259
demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
260
sys.modules['bzrlib.plugins.demo_module'] = demo_module
260
topics = index.get_topics('get_topics')
262
topics = index.get_topics('demo_module')
261
263
self.assertEqual(1, len(topics))
262
264
self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
263
265
self.assertEqual(demo_module, topics[0].module)
265
del sys.modules['bzrlib.plugins.get_topics']
267
del sys.modules['bzrlib.plugins.demo_module']
267
269
def test_get_topics_no_topic(self):
268
270
"""Searching for something that is not a plugin returns []."""
276
278
index = plugin.PluginsHelpIndex()
277
279
self.assertEqual('plugins/', index.prefix)
279
def test_get_topic_with_prefix(self):
280
"""Searching for plugins/launchpad returns launchpad module help."""
281
def test_get_plugin_topic_with_prefix(self):
282
"""Searching for plugins/demo_module returns help."""
281
283
index = plugin.PluginsHelpIndex()
282
self.assertFalse(sys.modules.has_key('bzrlib.plugins.get_topics'))
283
demo_module = FakeModule('', 'bzrlib.plugins.get_topics')
284
sys.modules['bzrlib.plugins.get_topics'] = demo_module
284
self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
285
demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
286
sys.modules['bzrlib.plugins.demo_module'] = demo_module
286
topics = index.get_topics('plugins/get_topics')
288
topics = index.get_topics('plugins/demo_module')
287
289
self.assertEqual(1, len(topics))
288
290
self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
289
291
self.assertEqual(demo_module, topics[0].module)
291
del sys.modules['bzrlib.plugins.get_topics']
293
del sys.modules['bzrlib.plugins.demo_module']
294
296
class FakeModule(object):