113
112
def test_unicode(self):
114
113
my_config = self._get_config("[ALIASES]\n"
115
u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
114
u"iam=whoami 'Erik B\u00e5gfors <erik@bagfors.nu>'\n")
116
115
self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
117
116
commands.get_alias("iam", config=my_config))
278
277
class TestGetMissingCommandHook(tests.TestCase):
280
def hook_missing(self):
281
"""Hook get_missing_command for testing."""
279
def test_fires_on_get_cmd_object(self):
280
# The get_missing_command(cmd) hook fires when commands are delivered to the
283
283
class ACommand(commands.Command):
284
284
"""A sample command."""
285
285
def get_missing_cmd(cmd_name):
286
self.hook_calls.append(('called', cmd_name))
286
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
297
291
# create a command directly, should not fire
298
self.cmd = self.ACommand()
299
self.assertEqual([], self.hook_calls)
293
self.assertEqual([], hook_calls)
300
294
# ask by name, should fire and give us our command
301
295
cmd = commands.get_cmd_object('foo')
302
self.assertEqual([('called', 'foo')], self.hook_calls)
303
self.assertIsInstance(cmd, self.ACommand)
304
del self.hook_calls[:]
296
self.assertEqual([('called', 'foo')], hook_calls)
297
self.assertIsInstance(cmd, ACommand)
305
299
# ask by a name that is supplied by a builtin - the hook should not
306
300
# fire and we still get our object.
307
301
commands.install_bzr_command_hooks()
308
302
cmd = commands.get_cmd_object('info')
309
303
self.assertNotEqual(None, cmd)
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)
304
self.assertEqual(0, len(hook_calls))
321
307
class TestListCommandHook(tests.TestCase):
337
323
cmds = list(commands.all_command_names())
338
324
self.assertEqual(['called'], hook_calls)
339
325
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')