~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-26 14:14:36 UTC
  • mfrom: (5058.2.1 commandlookup)
  • Revision ID: pqm@pqm.ubuntu.com-20100226141436-t8s3uqt5w9ktt04g
(robertc) Do not call Commands.hooks[get_missing_command] when
        looking up help topics. (Robert Collins, bug 396261)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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):