112
113
def test_unicode(self):
113
114
my_config = self._get_config("[ALIASES]\n"
114
u"iam=whoami 'Erik B\u00e5gfors <erik@bagfors.nu>'\n")
115
u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
115
116
self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
116
117
commands.get_alias("iam", config=my_config))
210
211
commands.Command.hooks.install_named_hook(
211
212
"extend_command", hook_calls.append, None)
212
213
# create a command, should not fire
213
class ACommand(commands.Command):
214
class cmd_test_extend_command_hook(commands.Command):
214
215
"""A sample command."""
216
216
self.assertEqual([], hook_calls)
217
217
# -- as a builtin
218
218
# register the command class, should not fire
220
builtins.cmd_test_extend_command_hook = ACommand
220
commands.builtin_command_registry.register(cmd_test_extend_command_hook)
221
221
self.assertEqual([], hook_calls)
222
222
# and ask for the object, should fire
223
223
cmd = commands.get_cmd_object('test-extend-command-hook')
227
227
self.assertSubset([cmd], hook_calls)
228
228
del hook_calls[:]
230
del builtins.cmd_test_extend_command_hook
230
commands.builtin_command_registry.remove('test-extend-command-hook')
231
231
# -- as a plugin lazy registration
233
233
# register the command class, should not fire
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):
323
336
cmds = list(commands.all_command_names())
324
337
self.assertEqual(['called'], hook_calls)
325
338
self.assertSubset(['foo', 'bar'], cmds)
340
class TestDeprecations(tests.TestCase):
342
def test_shlex_split_unicode_deprecation(self):
343
res = self.applyDeprecated(
344
symbol_versioning.deprecated_in((2, 2, 0)),
345
commands.shlex_split_unicode, 'whatever')