示例#1
0
def test_hooked_wrap_in_hooks_failure():
    from plumber.core import Hooked
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)

    def check_prehook_called():
        for executor in hooks.prehooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'prehook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "prehook"'
        for executor in hooks.posthooks:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 0
        raise ExecutionFailure('Just to test')

    def check_posthook_called(status):
        assert status == FAILURE
        for executor in hooks.posthooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'posthook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook"'
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(
                UTF8) == 'posthook-failure\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook-failure"'
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 0

    try:
        hooks.wrap_in_hooks(check_prehook_called, check_posthook_called)()
    except Exception as e:
        assert type(e) is ExecutionFailure
示例#2
0
def test_hooked_wrap_in_hooks_success():
    from plumber.core import Hooked
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)

    def check_prehook_called():
        for executor in hooks.prehooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'prehook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "prehook"'
        for executor in hooks.posthooks:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 0
        return 'success'

    def check_posthook_called(status):
        assert status == SUCCESS
        for executor in hooks.posthooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'posthook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook"'
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(
                UTF8) == 'posthook-success\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook-success"'
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 0

    assert hooks.wrap_in_hooks(check_prehook_called,
                               check_posthook_called)() == 'success'