~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-23 20:55:58 UTC
  • mfrom: (4034 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4053.
  • Revision ID: jelmer@samba.org-20090223205558-1cx2k4w1zgs8r5qa
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import sys
20
20
 
21
21
from bzrlib import (
 
22
    builtins,
22
23
    commands,
23
24
    config,
24
25
    errors,
175
176
        self.addCleanup(self.remove_fake)
176
177
        fake_instance = commands.get_cmd_object('fake_alias')
177
178
        self.assertIsFakeCommand(fake_instance)
 
179
 
 
180
 
 
181
class TestExtendCommandHook(tests.TestCase):
 
182
 
 
183
    def test_fires_on_get_cmd_object(self):
 
184
        # The extend_command(cmd) hook fires when commands are delivered to the
 
185
        # ui, not simply at registration (because lazy registered plugin
 
186
        # commands are registered).
 
187
        # when they are simply created.
 
188
        hook_calls = []
 
189
        commands.Command.hooks.install_named_hook(
 
190
            "extend_command", hook_calls.append, None)
 
191
        # create a command, should not fire
 
192
        class ACommand(commands.Command):
 
193
            """A sample command."""
 
194
        cmd = ACommand()
 
195
        self.assertEqual([], hook_calls)
 
196
        # -- as a builtin
 
197
        # register the command class, should not fire
 
198
        try:
 
199
            builtins.cmd_test_extend_command_hook = ACommand
 
200
            self.assertEqual([], hook_calls)
 
201
            # and ask for the object, should fire
 
202
            cmd = commands.get_cmd_object('test-extend-command-hook')
 
203
            # For resilience - to ensure all code paths hit it - we
 
204
            # fire on everything returned in the 'cmd_dict', which is currently
 
205
            # all known commands, so assert that cmd is in hook_calls
 
206
            self.assertSubset([cmd], hook_calls)
 
207
            del hook_calls[:]
 
208
        finally:
 
209
            del builtins.cmd_test_extend_command_hook
 
210
        # -- as a plugin lazy registration
 
211
        try:
 
212
            # register the command class, should not fire
 
213
            commands.plugin_cmds.register_lazy('cmd_fake', [],
 
214
                                               'bzrlib.tests.fake_command')
 
215
            self.assertEqual([], hook_calls)
 
216
            # and ask for the object, should fire
 
217
            cmd = commands.get_cmd_object('fake')
 
218
            self.assertEqual([cmd], hook_calls)
 
219
        finally:
 
220
            commands.plugin_cmds.remove('fake')