175
176
self.addCleanup(self.remove_fake)
176
177
fake_instance = commands.get_cmd_object('fake_alias')
177
178
self.assertIsFakeCommand(fake_instance)
181
class TestExtendCommandHook(tests.TestCase):
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.
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."""
195
self.assertEqual([], hook_calls)
197
# register the command class, should not fire
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)
209
del builtins.cmd_test_extend_command_hook
210
# -- as a plugin lazy registration
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)
220
commands.plugin_cmds.remove('fake')