|
3 | 3 | from __future__ import unicode_literals |
4 | 4 |
|
5 | 5 | import io |
| 6 | +import itertools |
6 | 7 | import logging |
7 | 8 | import os.path |
8 | 9 | import shutil |
@@ -321,50 +322,30 @@ def in_git_dir(tmpdir): |
321 | 322 | yield tmpdir |
322 | 323 |
|
323 | 324 |
|
324 | | -BEFORE = b'1\n2\n' |
325 | | -AFTER = b'3\n4\n' |
326 | | - |
327 | | - |
328 | | -def _crlf(b): |
329 | | - return b.replace(b'\n', b'\r\n') |
330 | | - |
331 | | - |
332 | 325 | def _write(b): |
333 | 326 | with open('foo', 'wb') as f: |
334 | 327 | f.write(b) |
335 | 328 |
|
336 | 329 |
|
337 | | -def git_add(): |
338 | | - cmd_output('git', 'add', 'foo') |
339 | | - |
340 | | - |
341 | 330 | def assert_no_diff(): |
342 | 331 | tree = cmd_output('git', 'write-tree')[1].strip() |
343 | 332 | cmd_output('git', 'diff-index', tree, '--exit-code') |
344 | 333 |
|
345 | 334 |
|
346 | | -BEFORE_AFTER = pytest.mark.parametrize( |
347 | | - ('before', 'after'), |
348 | | - ( |
349 | | - (BEFORE, AFTER), |
350 | | - (_crlf(BEFORE), _crlf(AFTER)), |
351 | | - (_crlf(BEFORE), AFTER), |
352 | | - (BEFORE, _crlf(AFTER)), |
353 | | - ), |
354 | | -) |
| 335 | +bool_product = tuple(itertools.product((True, False), repeat=2)) |
| 336 | + |
355 | 337 |
|
| 338 | +@pytest.mark.parametrize(('crlf_before', 'crlf_after'), bool_product) |
| 339 | +@pytest.mark.parametrize('autocrlf', ('true', 'false', 'input')) |
| 340 | +def test_crlf(in_git_dir, cmd_runner, crlf_before, crlf_after, autocrlf): |
| 341 | + cmd_output('git', 'config', '--local', 'core.autocrlf', autocrlf) |
| 342 | + |
| 343 | + before, after = b'1\n2\n', b'3\n4\n' |
| 344 | + before = before.replace(b'\n', b'\r\n') if crlf_before else before |
| 345 | + after = after.replace(b'\n', b'\r\n') if crlf_after else after |
356 | 346 |
|
357 | | -@BEFORE_AFTER |
358 | | -def test_default(in_git_dir, cmd_runner, before, after): |
359 | 347 | _write(before) |
360 | | - git_add() |
| 348 | + cmd_output('git', 'add', 'foo') |
361 | 349 | _write(after) |
362 | 350 | with staged_files_only(cmd_runner): |
363 | 351 | assert_no_diff() |
364 | | - |
365 | | - |
366 | | -@BEFORE_AFTER |
367 | | -@pytest.mark.parametrize('autocrlf', ('true', 'false', 'input')) |
368 | | -def test_autocrlf_true(in_git_dir, cmd_runner, before, after, autocrlf): |
369 | | - cmd_output('git', 'config', '--local', 'core.autocrlf', autocrlf) |
370 | | - test_default(in_git_dir, cmd_runner, before, after) |
0 commit comments