Include hook id in output with --verbose. Closes #88.

This commit is contained in:
Anthony Sottile 2014-04-19 17:12:51 -07:00
parent edb04422b8
commit cce97ccba9
4 changed files with 177 additions and 36 deletions

View file

@ -330,3 +330,13 @@ def test_skip_hook(repo_with_passing_hook):
)
for msg in ('Bash hook', 'Skipped'):
assert msg in printed
def test_hook_id_not_in_non_verbose_output(repo_with_passing_hook):
ret, printed = _do_run(repo_with_passing_hook, _get_opts(verbose=False))
assert '[bash_hook]' not in printed
def test_hook_id_in_verbose_output(repo_with_passing_hook):
ret, printed = _do_run(repo_with_passing_hook, _get_opts(verbose=True))
assert '[bash_hook] Bash hook' in printed

77
tests/output_test.py Normal file
View file

@ -0,0 +1,77 @@
import pytest
from pre_commit import color
from pre_commit.output import get_hook_message
@pytest.mark.parametrize(
'kwargs',
(
# both end_msg and end_len
{'end_msg': 'end', 'end_len': 1, 'end_color': '', 'use_color': True},
# Neither end_msg nor end_len
{},
# Neither color option for end_msg
{'end_msg': 'end'},
# No use_color for end_msg
{'end_msg': 'end', 'end_color': ''},
# No end_color for end_msg
{'end_msg': 'end', 'use_color': ''},
),
)
def test_get_hook_message_raises(kwargs):
with pytest.raises(ValueError):
get_hook_message('start', **kwargs)
def test_case_with_end_len():
ret = get_hook_message('start', end_len=5, cols=15)
assert ret == 'start' + '.' * 4
def test_case_with_end_msg():
ret = get_hook_message(
'start',
end_msg='end',
end_color='',
use_color=False,
cols=15,
)
assert ret == 'start' + '.' * 6 + 'end' + '\n'
def test_case_with_end_msg_using_color():
ret = get_hook_message(
'start',
end_msg='end',
end_color=color.RED,
use_color=True,
cols=15,
)
assert ret == 'start' + '.' * 6 + color.RED + 'end' + color.NORMAL + '\n'
def test_case_with_postfix_message():
ret = get_hook_message(
'start',
postfix='post ',
end_msg='end',
end_color='',
use_color=False,
cols=20,
)
assert ret == 'start' + '.' * 6 + 'post ' + 'end' + '\n'
def test_make_sure_postfix_is_not_colored():
ret = get_hook_message(
'start',
postfix='post ',
end_msg='end',
end_color=color.RED,
use_color=True,
cols=20,
)
assert ret == (
'start' + '.' * 6 + 'post ' + color.RED + 'end' + color.NORMAL + '\n'
)