mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 16:44:42 +04:00
Simplify crlf tests
This commit is contained in:
parent
cc3f2978bc
commit
5fa021058d
1 changed files with 12 additions and 31 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -321,50 +322,30 @@ def in_git_dir(tmpdir):
|
||||||
yield tmpdir
|
yield tmpdir
|
||||||
|
|
||||||
|
|
||||||
BEFORE = b'1\n2\n'
|
|
||||||
AFTER = b'3\n4\n'
|
|
||||||
|
|
||||||
|
|
||||||
def _crlf(b):
|
|
||||||
return b.replace(b'\n', b'\r\n')
|
|
||||||
|
|
||||||
|
|
||||||
def _write(b):
|
def _write(b):
|
||||||
with open('foo', 'wb') as f:
|
with open('foo', 'wb') as f:
|
||||||
f.write(b)
|
f.write(b)
|
||||||
|
|
||||||
|
|
||||||
def git_add():
|
|
||||||
cmd_output('git', 'add', 'foo')
|
|
||||||
|
|
||||||
|
|
||||||
def assert_no_diff():
|
def assert_no_diff():
|
||||||
tree = cmd_output('git', 'write-tree')[1].strip()
|
tree = cmd_output('git', 'write-tree')[1].strip()
|
||||||
cmd_output('git', 'diff-index', tree, '--exit-code')
|
cmd_output('git', 'diff-index', tree, '--exit-code')
|
||||||
|
|
||||||
|
|
||||||
BEFORE_AFTER = pytest.mark.parametrize(
|
bool_product = tuple(itertools.product((True, False), repeat=2))
|
||||||
('before', 'after'),
|
|
||||||
(
|
|
||||||
(BEFORE, AFTER),
|
|
||||||
(_crlf(BEFORE), _crlf(AFTER)),
|
|
||||||
(_crlf(BEFORE), AFTER),
|
|
||||||
(BEFORE, _crlf(AFTER)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@BEFORE_AFTER
|
@pytest.mark.parametrize(('crlf_before', 'crlf_after'), bool_product)
|
||||||
def test_default(in_git_dir, cmd_runner, before, after):
|
@pytest.mark.parametrize('autocrlf', ('true', 'false', 'input'))
|
||||||
|
def test_crlf(in_git_dir, cmd_runner, crlf_before, crlf_after, autocrlf):
|
||||||
|
cmd_output('git', 'config', '--local', 'core.autocrlf', autocrlf)
|
||||||
|
|
||||||
|
before, after = b'1\n2\n', b'3\n4\n'
|
||||||
|
before = before.replace(b'\n', b'\r\n') if crlf_before else before
|
||||||
|
after = after.replace(b'\n', b'\r\n') if crlf_after else after
|
||||||
|
|
||||||
_write(before)
|
_write(before)
|
||||||
git_add()
|
cmd_output('git', 'add', 'foo')
|
||||||
_write(after)
|
_write(after)
|
||||||
with staged_files_only(cmd_runner):
|
with staged_files_only(cmd_runner):
|
||||||
assert_no_diff()
|
assert_no_diff()
|
||||||
|
|
||||||
|
|
||||||
@BEFORE_AFTER
|
|
||||||
@pytest.mark.parametrize('autocrlf', ('true', 'false', 'input'))
|
|
||||||
def test_autocrlf_true(in_git_dir, cmd_runner, before, after, autocrlf):
|
|
||||||
cmd_output('git', 'config', '--local', 'core.autocrlf', autocrlf)
|
|
||||||
test_default(in_git_dir, cmd_runner, before, after)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue