mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 20:40:08 -06:00
80 lines
1.9 KiB
Python
80 lines
1.9 KiB
Python
from __future__ import unicode_literals
|
|
|
|
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'
|
|
)
|