Add check-merge-conflict hook

This commit is contained in:
Guy Kisel 2015-03-13 16:30:14 -07:00
parent 70a319aea3
commit 779a42919a
5 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,26 @@
import os.path
import pytest
from pre_commit_hooks.check_merge_conflict import detect_merge_conflict
# Input, expected return value
TESTS = (
(b'<<<<<<< HEAD', 1),
(b'=======', 1),
(b'>>>>>>> master', 1),
(b'# <<<<<<< HEAD', 0),
(b'# =======', 0),
(b'import my_module', 0),
(b'', 0),
)
@pytest.mark.parametrize(('input_s', 'expected_retval'), TESTS)
def test_detect_merge_conflict(input_s, expected_retval, tmpdir):
path = os.path.join(tmpdir.strpath, 'file.txt')
with open(path, 'wb') as file_obj:
file_obj.write(input_s)
assert detect_merge_conflict([path]) == expected_retval