mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
Add update_commit_msg
Update hooks file Update description Simplify approach Remove redundant statement Add test Add more tests Updates lints Use io.open instead Update setup.py Remove unused import Rename update-commit-msg to prepend-ticket-number-to-commit-msg
This commit is contained in:
parent
c65fcd3fc5
commit
ed5a523745
5 changed files with 124 additions and 0 deletions
53
tests/prepend_ticket_number_to_commit_msg_test.py
Normal file
53
tests/prepend_ticket_number_to_commit_msg_test.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit_hooks.prepend_ticket_number_to_commit_msg import get_branch_name
|
||||
from pre_commit_hooks.prepend_ticket_number_to_commit_msg import main
|
||||
from pre_commit_hooks.prepend_ticket_number_to_commit_msg import update_commit_message
|
||||
|
||||
|
||||
TESTING_MODULE = 'pre_commit_hooks.prepend_ticket_number_to_commit_msg'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('msg'),
|
||||
(
|
||||
'Test',
|
||||
'JIRA-1234_Test',
|
||||
),
|
||||
)
|
||||
@mock.patch(TESTING_MODULE + '.get_branch_name')
|
||||
def test_update_commit_message(mock_branch_name, msg, tmpdir):
|
||||
mock_branch_name.return_value = 'JIRA-1234_new_feature'
|
||||
path = tmpdir.join('file.txt')
|
||||
path.write(msg)
|
||||
update_commit_message(six.text_type(path), '[A-Z]+-\d+') # noqa
|
||||
assert 'JIRA-1234' in path.read()
|
||||
|
||||
|
||||
@mock.patch(TESTING_MODULE + '.subprocess')
|
||||
def test_get_branch_name(mock_subprocess):
|
||||
get_branch_name()
|
||||
mock_subprocess.check_output.assert_called_once_with(
|
||||
[
|
||||
'git',
|
||||
'rev-parse',
|
||||
'--abbrev-ref',
|
||||
'HEAD',
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@mock.patch(TESTING_MODULE + '.argparse')
|
||||
@mock.patch(TESTING_MODULE + '.update_commit_message')
|
||||
def test_main(mock_update_commit_message, mock_argparse):
|
||||
mock_args = mock.Mock()
|
||||
mock_args.filenames = ['foo.txt']
|
||||
mock_args.regex = None
|
||||
mock_argparse.ArgumentParser.return_value.parse_args.return_value = mock_args
|
||||
main()
|
||||
mock_update_commit_message.assert_called_once_with('foo.txt', '[A-Z]+-\d+') # noqa
|
||||
Loading…
Add table
Add a link
Reference in a new issue