mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make verbose output less special
This commit is contained in:
parent
74fd04c67e
commit
01a628d96d
8 changed files with 99 additions and 108 deletions
|
|
@ -288,7 +288,8 @@ def test_environment_not_sourced(tempdir_factory, store):
|
|||
FAILING_PRE_COMMIT_RUN = re.compile(
|
||||
r'^\[INFO\] Initializing environment for .+\.\r?\n'
|
||||
r'Failing hook\.+Failed\r?\n'
|
||||
r'hookid: failing_hook\r?\n'
|
||||
r'- hook id: failing_hook\r?\n'
|
||||
r'- exit code: 1\r?\n'
|
||||
r'\r?\n'
|
||||
r'Fail\r?\n'
|
||||
r'foo\r?\n'
|
||||
|
|
@ -548,7 +549,7 @@ def test_pre_push_integration_failing(tempdir_factory, store):
|
|||
assert 'Failing hook' in output
|
||||
assert 'Failed' in output
|
||||
assert 'foo zzz' in output # both filenames should be printed
|
||||
assert 'hookid: failing_hook' in output
|
||||
assert 'hook id: failing_hook' in output
|
||||
|
||||
|
||||
def test_pre_push_integration_accepted(tempdir_factory, store):
|
||||
|
|
@ -647,8 +648,11 @@ def test_commit_msg_integration_failing(
|
|||
install(C.CONFIG_FILE, store, hook_types=['commit-msg'])
|
||||
retc, out = _get_commit_output(tempdir_factory)
|
||||
assert retc == 1
|
||||
assert out.startswith('Must have "Signed off by:"...')
|
||||
assert out.strip().endswith('...Failed')
|
||||
assert out.replace('\r', '') == '''\
|
||||
Must have "Signed off by:"...............................................Failed
|
||||
- hook id: must-have-signoff
|
||||
- exit code: 1
|
||||
'''
|
||||
|
||||
|
||||
def test_commit_msg_integration_passing(
|
||||
|
|
@ -691,16 +695,18 @@ def test_prepare_commit_msg_integration_failing(
|
|||
install(C.CONFIG_FILE, store, hook_types=['prepare-commit-msg'])
|
||||
retc, out = _get_commit_output(tempdir_factory)
|
||||
assert retc == 1
|
||||
assert out.startswith('Add "Signed off by:"...')
|
||||
assert out.strip().endswith('...Failed')
|
||||
assert out.replace('\r', '') == '''\
|
||||
Add "Signed off by:".....................................................Failed
|
||||
- hook id: add-signoff
|
||||
- exit code: 1
|
||||
'''
|
||||
|
||||
|
||||
def test_prepare_commit_msg_integration_passing(
|
||||
prepare_commit_msg_repo, tempdir_factory, store,
|
||||
):
|
||||
install(C.CONFIG_FILE, store, hook_types=['prepare-commit-msg'])
|
||||
msg = 'Hi'
|
||||
retc, out = _get_commit_output(tempdir_factory, msg=msg)
|
||||
retc, out = _get_commit_output(tempdir_factory, msg='Hi')
|
||||
assert retc == 0
|
||||
first_line = out.splitlines()[0]
|
||||
assert first_line.startswith('Add "Signed off by:"...')
|
||||
|
|
@ -730,8 +736,7 @@ def test_prepare_commit_msg_legacy(
|
|||
|
||||
install(C.CONFIG_FILE, store, hook_types=['prepare-commit-msg'])
|
||||
|
||||
msg = 'Hi'
|
||||
retc, out = _get_commit_output(tempdir_factory, msg=msg)
|
||||
retc, out = _get_commit_output(tempdir_factory, msg='Hi')
|
||||
assert retc == 0
|
||||
first_line, second_line = out.splitlines()[:2]
|
||||
assert first_line == 'legacy'
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ def test_run_all_hooks_failing(cap_out, store, repo_with_failing_hook):
|
|||
(
|
||||
b'Failing hook',
|
||||
b'Failed',
|
||||
b'hookid: failing_hook',
|
||||
b'hook id: failing_hook',
|
||||
b'Fail\nfoo.py\n',
|
||||
),
|
||||
expected_ret=1,
|
||||
|
|
@ -125,14 +125,14 @@ def test_hook_that_modifies_but_returns_zero(cap_out, store, tempdir_factory):
|
|||
# The first should fail
|
||||
b'Failed',
|
||||
# With a modified file (default message + the hook's output)
|
||||
b'Files were modified by this hook. Additional output:\n\n'
|
||||
b'- files were modified by this hook\n\n'
|
||||
b'Modified: foo.py',
|
||||
# The next hook should pass despite the first modifying
|
||||
b'Passed',
|
||||
# The next hook should fail
|
||||
b'Failed',
|
||||
# bar.py was modified, but provides no additional output
|
||||
b'Files were modified by this hook.\n',
|
||||
b'- files were modified by this hook\n',
|
||||
),
|
||||
1,
|
||||
True,
|
||||
|
|
@ -176,7 +176,7 @@ def test_global_exclude(cap_out, store, tempdir_factory):
|
|||
ret, printed = _do_run(cap_out, store, git_path, opts)
|
||||
assert ret == 0
|
||||
# Does not contain foo.py since it was excluded
|
||||
expected = b'hookid: bash_hook\n\nbar.py\nHello World\n\n'
|
||||
expected = b'- hook id: bash_hook\n\nbar.py\nHello World\n\n'
|
||||
assert printed.endswith(expected)
|
||||
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ def test_global_files(cap_out, store, tempdir_factory):
|
|||
ret, printed = _do_run(cap_out, store, git_path, opts)
|
||||
assert ret == 0
|
||||
# Does not contain foo.py since it was not included
|
||||
expected = b'hookid: bash_hook\n\nbar.py\nHello World\n\n'
|
||||
expected = b'- hook id: bash_hook\n\nbar.py\nHello World\n\n'
|
||||
assert printed.endswith(expected)
|
||||
|
||||
|
||||
|
|
@ -422,23 +422,21 @@ def test_merge_conflict_resolved(cap_out, store, in_merge_conflict):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('hooks', 'verbose', 'expected'),
|
||||
('hooks', 'expected'),
|
||||
(
|
||||
([], True, 80),
|
||||
([auto_namedtuple(id='a', name='a' * 51)], False, 81),
|
||||
([auto_namedtuple(id='a', name='a' * 51)], True, 85),
|
||||
([], 80),
|
||||
([auto_namedtuple(id='a', name='a' * 51)], 81),
|
||||
(
|
||||
[
|
||||
auto_namedtuple(id='a', name='a' * 51),
|
||||
auto_namedtuple(id='b', name='b' * 52),
|
||||
],
|
||||
False,
|
||||
82,
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_compute_cols(hooks, verbose, expected):
|
||||
assert _compute_cols(hooks, verbose) == expected
|
||||
def test_compute_cols(hooks, expected):
|
||||
assert _compute_cols(hooks) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -492,7 +490,7 @@ def test_hook_id_in_verbose_output(cap_out, store, repo_with_passing_hook):
|
|||
ret, printed = _do_run(
|
||||
cap_out, store, repo_with_passing_hook, run_opts(verbose=True),
|
||||
)
|
||||
assert b'[bash_hook] Bash hook' in printed
|
||||
assert b'- hook id: bash_hook' in printed
|
||||
|
||||
|
||||
def test_multiple_hooks_same_id(cap_out, store, repo_with_passing_hook):
|
||||
|
|
|
|||
|
|
@ -54,15 +54,17 @@ def test_try_repo_repo_only(cap_out, tempdir_factory):
|
|||
' - id: bash_hook3\n$',
|
||||
config,
|
||||
)
|
||||
assert rest == (
|
||||
'[bash_hook] Bash hook................................(no files to check)Skipped\n' # noqa: E501
|
||||
'[bash_hook2] Bash hook...................................................Passed\n' # noqa: E501
|
||||
'hookid: bash_hook2\n'
|
||||
'\n'
|
||||
'test-file\n'
|
||||
'\n'
|
||||
'[bash_hook3] Bash hook...............................(no files to check)Skipped\n' # noqa: E501
|
||||
)
|
||||
assert rest == '''\
|
||||
Bash hook............................................(no files to check)Skipped
|
||||
- hook id: bash_hook
|
||||
Bash hook................................................................Passed
|
||||
- hook id: bash_hook2
|
||||
|
||||
test-file
|
||||
|
||||
Bash hook............................................(no files to check)Skipped
|
||||
- hook id: bash_hook3
|
||||
'''
|
||||
|
||||
|
||||
def test_try_repo_with_specific_hook(cap_out, tempdir_factory):
|
||||
|
|
@ -77,7 +79,10 @@ def test_try_repo_with_specific_hook(cap_out, tempdir_factory):
|
|||
' - id: bash_hook\n$',
|
||||
config,
|
||||
)
|
||||
assert rest == '[bash_hook] Bash hook................................(no files to check)Skipped\n' # noqa: E501
|
||||
assert rest == '''\
|
||||
Bash hook............................................(no files to check)Skipped
|
||||
- hook id: bash_hook
|
||||
'''
|
||||
|
||||
|
||||
def test_try_repo_relative_path(cap_out, tempdir_factory):
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ def test_run_a_failing_docker_hook(tempdir_factory, store):
|
|||
'docker-hook-failing',
|
||||
['Hello World from docker'],
|
||||
mock.ANY, # an error message about `bork` not existing
|
||||
expected_return_code=1,
|
||||
expected_return_code=127,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,10 @@ def test_xargs_retcode_normal():
|
|||
ret, _ = xargs.xargs(exit_cmd, ('0', '1'), _max_length=max_length)
|
||||
assert ret == 1
|
||||
|
||||
# takes the maximum return code
|
||||
ret, _ = xargs.xargs(exit_cmd, ('0', '5', '1'), _max_length=max_length)
|
||||
assert ret == 5
|
||||
|
||||
|
||||
def test_xargs_concurrency():
|
||||
bash_cmd = parse_shebang.normalize_cmd(('bash', '-c'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue