277
277
class TestGetMissingCommandHook(tests.TestCase):
279
def test_fires_on_get_cmd_object(self):
280
# The get_missing_command(cmd) hook fires when commands are delivered to the
279
def hook_missing(self):
280
"""Hook get_missing_command for testing."""
283
282
class ACommand(commands.Command):
284
283
"""A sample command."""
285
284
def get_missing_cmd(cmd_name):
286
hook_calls.append(('called', cmd_name))
285
self.hook_calls.append(('called', cmd_name))
287
286
if cmd_name in ('foo', 'info'):
288
287
return ACommand()
289
288
commands.Command.hooks.install_named_hook(
290
289
"get_missing_command", get_missing_cmd, None)
290
self.ACommand = ACommand
292
def test_fires_on_get_cmd_object(self):
293
# The get_missing_command(cmd) hook fires when commands are delivered to the
291
296
# create a command directly, should not fire
293
self.assertEqual([], hook_calls)
297
self.cmd = self.ACommand()
298
self.assertEqual([], self.hook_calls)
294
299
# ask by name, should fire and give us our command
295
300
cmd = commands.get_cmd_object('foo')
296
self.assertEqual([('called', 'foo')], hook_calls)
297
self.assertIsInstance(cmd, ACommand)
301
self.assertEqual([('called', 'foo')], self.hook_calls)
302
self.assertIsInstance(cmd, self.ACommand)
303
del self.hook_calls[:]
299
304
# ask by a name that is supplied by a builtin - the hook should not
300
305
# fire and we still get our object.
301
306
commands.install_bzr_command_hooks()
302
307
cmd = commands.get_cmd_object('info')
303
308
self.assertNotEqual(None, cmd)
304
self.assertEqual(0, len(hook_calls))
309
self.assertEqual(0, len(self.hook_calls))
311
def test_skipped_on_HelpCommandIndex_get_topics(self):
312
# The get_missing_command(cmd_name) hook is not fired when
313
# looking up help topics.
315
topic = commands.HelpCommandIndex()
316
topics = topic.get_topics('foo')
317
self.assertEqual([], self.hook_calls)
307
320
class TestListCommandHook(tests.TestCase):