277
278
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
280
def hook_missing(self):
281
"""Hook get_missing_command for testing."""
283
283
class ACommand(commands.Command):
284
284
"""A sample command."""
285
285
def get_missing_cmd(cmd_name):
286
hook_calls.append(('called', cmd_name))
286
self.hook_calls.append(('called', cmd_name))
287
287
if cmd_name in ('foo', 'info'):
288
288
return ACommand()
289
289
commands.Command.hooks.install_named_hook(
290
290
"get_missing_command", get_missing_cmd, None)
291
self.ACommand = ACommand
293
def test_fires_on_get_cmd_object(self):
294
# The get_missing_command(cmd) hook fires when commands are delivered to the
291
297
# create a command directly, should not fire
293
self.assertEqual([], hook_calls)
298
self.cmd = self.ACommand()
299
self.assertEqual([], self.hook_calls)
294
300
# ask by name, should fire and give us our command
295
301
cmd = commands.get_cmd_object('foo')
296
self.assertEqual([('called', 'foo')], hook_calls)
297
self.assertIsInstance(cmd, ACommand)
302
self.assertEqual([('called', 'foo')], self.hook_calls)
303
self.assertIsInstance(cmd, self.ACommand)
304
del self.hook_calls[:]
299
305
# ask by a name that is supplied by a builtin - the hook should not
300
306
# fire and we still get our object.
301
307
commands.install_bzr_command_hooks()
302
308
cmd = commands.get_cmd_object('info')
303
309
self.assertNotEqual(None, cmd)
304
self.assertEqual(0, len(hook_calls))
310
self.assertEqual(0, len(self.hook_calls))
312
def test_skipped_on_HelpCommandIndex_get_topics(self):
313
# The get_missing_command(cmd_name) hook is not fired when
314
# looking up help topics.
316
topic = commands.HelpCommandIndex()
317
topics = topic.get_topics('foo')
318
self.assertEqual([], self.hook_calls)
307
321
class TestListCommandHook(tests.TestCase):
323
337
cmds = list(commands.all_command_names())
324
338
self.assertEqual(['called'], hook_calls)
325
339
self.assertSubset(['foo', 'bar'], cmds)
341
class TestDeprecations(tests.TestCase):
343
def test_shlex_split_unicode_deprecation(self):
344
res = self.applyDeprecated(
345
symbol_versioning.deprecated_in((2, 2, 0)),
346
commands.shlex_split_unicode, 'whatever')