383
383
self.assertEqual([], hook_calls)
384
384
hook_calls.append('pre')
386
def post_command(cmd, e):
386
def post_command(cmd):
387
387
self.assertEqual(['pre', 'run'], hook_calls)
388
388
hook_calls.append('post')
405
405
def test_post_hook_provided_exception(self):
408
def post_command(cmd, e):
409
self.assertTrue(isinstance(e, self.TestError))
408
def post_command(cmd):
410
409
hook_calls.append('post')
419
418
"post_command", post_command, None)
421
420
self.assertEqual([], hook_calls)
422
self.assertRaises(self.TestError,
423
commands.run_bzr, [u'rocks'])
421
self.assertRaises(self.TestError, commands.run_bzr, [u'rocks'])
424
422
self.assertEqual(['run', 'post'], hook_calls)
426
def test_pre_exception(self):
427
"""Ensure an exception in pre_command does not abort the command"""
431
def pre_command(cmd):
432
hook_calls.append('pre')
433
raise self.TestError()
435
def post_command(cmd, e):
436
hook_calls.append('post')
439
hook_calls.append('run')
441
self.overrideAttr(builtins.cmd_rocks, 'run', run)
442
commands.install_bzr_command_hooks()
443
commands.Command.hooks.install_named_hook(
444
"pre_command", pre_command, None)
445
commands.Command.hooks.install_named_hook(
446
"post_command", post_command, None)
448
self.assertEqual([], hook_calls)
449
self.run_bzr(['rocks', '-Oxx=12', '-Oyy=foo'])
450
self.assertEqual(['pre', 'run', 'post'], hook_calls)
453
424
def test_pre_command_error(self):
454
425
"""Ensure an BzrCommandError in pre_command aborts the command"""