Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7141f3

Browse files
committed
Add integration test demonstrating hooks
1 parent 931c69b commit b7141f3

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/commands/install_uninstall_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,46 @@ def test_installed_from_venv(tmpdir_factory):
406406
)
407407
assert ret == 0
408408
assert NORMAL_PRE_COMMIT_RUN.match(output)
409+
410+
411+
def _get_push_output(tmpdir_factory):
412+
# Don't want to write to home directory
413+
home = tmpdir_factory.get()
414+
env = dict(os.environ, **{'PRE_COMMIT_HOME': home})
415+
return cmd_output(
416+
'git', 'push', 'origin', 'HEAD:new_branch',
417+
# git commit puts pre-commit to stderr
418+
stderr=subprocess.STDOUT,
419+
env=env,
420+
retcode=None,
421+
)[:2]
422+
423+
424+
def test_pre_push_integration_failing(tmpdir_factory):
425+
upstream = make_consuming_repo(tmpdir_factory, 'failing_hook_repo')
426+
path = tmpdir_factory.get()
427+
cmd_output('git', 'clone', upstream, path)
428+
with cwd(path):
429+
install(Runner(path), hook_type='pre-push')
430+
# commit succeeds because pre-commit is only installed for pre-push
431+
assert _get_commit_output(tmpdir_factory)[0] == 0
432+
433+
retc, output = _get_push_output(tmpdir_factory)
434+
assert retc == 1
435+
assert 'Failing hook' in output
436+
assert 'Failed' in output
437+
assert 'hookid: failing_hook' in output
438+
439+
440+
def test_pre_push_integration_accepted(tmpdir_factory):
441+
upstream = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
442+
path = tmpdir_factory.get()
443+
cmd_output('git', 'clone', upstream, path)
444+
with cwd(path):
445+
install(Runner(path), hook_type='pre-push')
446+
assert _get_commit_output(tmpdir_factory)[0] == 0
447+
448+
retc, output = _get_push_output(tmpdir_factory)
449+
assert retc == 0
450+
assert 'Bash hook' in output
451+
assert 'Passed' in output

0 commit comments

Comments
 (0)