From b7141f32c00c40e0b2b481f9f3715bf2eea837fa Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 14 Jan 2015 20:19:49 -0800 Subject: [PATCH] Add integration test demonstrating hooks --- tests/commands/install_uninstall_test.py | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 658e8966..d83d6ec3 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -406,3 +406,46 @@ def test_installed_from_venv(tmpdir_factory): ) assert ret == 0 assert NORMAL_PRE_COMMIT_RUN.match(output) + + +def _get_push_output(tmpdir_factory): + # Don't want to write to home directory + home = tmpdir_factory.get() + env = dict(os.environ, **{'PRE_COMMIT_HOME': home}) + return cmd_output( + 'git', 'push', 'origin', 'HEAD:new_branch', + # git commit puts pre-commit to stderr + stderr=subprocess.STDOUT, + env=env, + retcode=None, + )[:2] + + +def test_pre_push_integration_failing(tmpdir_factory): + upstream = make_consuming_repo(tmpdir_factory, 'failing_hook_repo') + path = tmpdir_factory.get() + cmd_output('git', 'clone', upstream, path) + with cwd(path): + install(Runner(path), hook_type='pre-push') + # commit succeeds because pre-commit is only installed for pre-push + assert _get_commit_output(tmpdir_factory)[0] == 0 + + retc, output = _get_push_output(tmpdir_factory) + assert retc == 1 + assert 'Failing hook' in output + assert 'Failed' in output + assert 'hookid: failing_hook' in output + + +def test_pre_push_integration_accepted(tmpdir_factory): + upstream = make_consuming_repo(tmpdir_factory, 'script_hooks_repo') + path = tmpdir_factory.get() + cmd_output('git', 'clone', upstream, path) + with cwd(path): + install(Runner(path), hook_type='pre-push') + assert _get_commit_output(tmpdir_factory)[0] == 0 + + retc, output = _get_push_output(tmpdir_factory) + assert retc == 0 + assert 'Bash hook' in output + assert 'Passed' in output