~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
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
24
24
    config,
25
25
    errors,
26
26
    option,
 
27
    symbol_versioning,
27
28
    tests,
28
29
    )
29
30
from bzrlib.commands import display_command
111
112
 
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))
117
118
 
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."""
215
 
        cmd = ACommand()
216
216
        self.assertEqual([], hook_calls)
217
217
        # -- as a builtin
218
218
        # register the command class, should not fire
219
219
        try:
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[:]
229
229
        finally:
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
232
232
        try:
233
233
            # register the command class, should not fire
276
276
 
277
277
class TestGetMissingCommandHook(tests.TestCase):
278
278
 
279
 
    def test_fires_on_get_cmd_object(self):
280
 
        # The get_missing_command(cmd) hook fires when commands are delivered to the
281
 
        # ui.
282
 
        hook_calls = []
 
279
    def hook_missing(self):
 
280
        """Hook get_missing_command for testing."""
 
281
        self.hook_calls = []
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
 
291
 
 
292
    def test_fires_on_get_cmd_object(self):
 
293
        # The get_missing_command(cmd) hook fires when commands are delivered to the
 
294
        # ui.
 
295
        self.hook_missing()
291
296
        # create a command directly, should not fire
292
 
        cmd = ACommand()
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)
298
 
        del hook_calls[:]
 
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))
 
310
 
 
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.
 
314
        self.hook_missing()
 
315
        topic = commands.HelpCommandIndex()
 
316
        topics = topic.get_topics('foo')
 
317
        self.assertEqual([], self.hook_calls)
305
318
 
306
319
 
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)
 
339
 
 
340
class TestDeprecations(tests.TestCase):
 
341
 
 
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')