def test_hook_error(self):
with ExitStack() as resources:
hooksdir = resources.enter_context(TemporaryDirectory())
hookfile = os.path.join(hooksdir, 'test-hook')
with open(hookfile, 'w') as fp:
fp.write(dedent("""\
#!/bin/sh
echo -n "error" 1>&2
exit 1
"""))
os.chmod(hookfile, 0o744)
manager = HookManager([hooksdir])
# Check if hook script failures are properly reported
with self.assertRaises(HookError) as cm:
manager.fire('test-hook')
self.assertEqual(cm.exception.hook_name, 'test-hook')
self.assertEqual(cm.exception.hook_path, hookfile)
self.assertEqual(cm.exception.hook_retcode, 1)
self.assertEqual(cm.exception.hook_stderr, 'error')
评论列表
文章目录