From 5fa021058d68dea7d5ea1e409d1ebfc5db2d24d7 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 31 Jul 2017 13:20:01 -0700 Subject: [PATCH] Simplify crlf tests --- tests/staged_files_only_test.py | 43 +++++++++------------------------ 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/tests/staged_files_only_test.py b/tests/staged_files_only_test.py index a00841aa..e066c27c 100644 --- a/tests/staged_files_only_test.py +++ b/tests/staged_files_only_test.py @@ -3,6 +3,7 @@ from __future__ import absolute_import from __future__ import unicode_literals import io +import itertools import logging import os.path import shutil @@ -321,50 +322,30 @@ def in_git_dir(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): with open('foo', 'wb') as f: f.write(b) -def git_add(): - cmd_output('git', 'add', 'foo') - - def assert_no_diff(): tree = cmd_output('git', 'write-tree')[1].strip() cmd_output('git', 'diff-index', tree, '--exit-code') -BEFORE_AFTER = pytest.mark.parametrize( - ('before', 'after'), - ( - (BEFORE, AFTER), - (_crlf(BEFORE), _crlf(AFTER)), - (_crlf(BEFORE), AFTER), - (BEFORE, _crlf(AFTER)), - ), -) +bool_product = tuple(itertools.product((True, False), repeat=2)) -@BEFORE_AFTER -def test_default(in_git_dir, cmd_runner, before, after): +@pytest.mark.parametrize(('crlf_before', 'crlf_after'), bool_product) +@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) - git_add() + cmd_output('git', 'add', 'foo') _write(after) with staged_files_only(cmd_runner): 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)