|
10 | 10 |
|
11 | 11 | # Input, expected return value, expected output |
12 | 12 | TESTS = ( |
13 | | - (b'foo\n', 0, b'foo\n'), |
14 | | - (b'', 0, b''), |
15 | | - (b'\n\n', 1, b''), |
16 | | - (b'\n\n\n\n', 1, b''), |
17 | | - (b'foo', 1, b'foo\n'), |
18 | | - (b'foo\n\n\n', 1, b'foo\n'), |
19 | | - (b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n'), |
20 | | - (b'foo\r\n', 0, b'foo\r\n'), |
21 | | - (b'foo\r\n\r\n\r\n', 1, b'foo\r\n'), |
22 | | - (b'foo\r', 0, b'foo\r'), |
23 | | - (b'foo\r\r\r\r', 1, b'foo\r'), |
| 13 | + (b'foo\n', 0, b'foo\n', None), |
| 14 | + (b'', 0, b'', None), |
| 15 | + (b'\n\n', 1, b'', None), |
| 16 | + (b'\n\n\n\n', 1, b'', None), |
| 17 | + (b'foo', 1, b'foo\n', None), |
| 18 | + (b'foo\n\n\n', 1, b'foo\n', None), |
| 19 | + (b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n', None), |
| 20 | + (b'foo\r\n', 0, b'foo\r\n', None), |
| 21 | + (b'foo\r\n\r\n\r\n', 1, b'foo\r\n', None), |
| 22 | + (b'foo\r', 0, b'foo\r', None), |
| 23 | + (b'foo\r\r\r\r', 1, b'foo\r', None), |
| 24 | + |
| 25 | + (b'foo\n', 0, b'foo\n', '--check'), |
| 26 | + (b'', 0, b'', '--check'), |
| 27 | + (b'\n\n', 1, b'\n\n', '--check'), |
| 28 | + (b'\n\n\n\n', 1, b'\n\n\n\n', '--check'), |
| 29 | + (b'foo', 1, b'foo', '--check'), |
| 30 | + (b'foo\n\n\n', 1, b'foo\n\n\n', '--check'), |
| 31 | + (b'\xe2\x98\x83', 1, b'\xe2\x98\x83', '--check'), |
| 32 | + (b'foo\r\n', 0, b'foo\r\n', '--check'), |
| 33 | + (b'foo\r\n\r\n\r\n', 1, b'foo\r\n\r\n\r\n', '--check'), |
| 34 | + (b'foo\r', 0, b'foo\r', '--check'), |
| 35 | + (b'foo\r\r\r\r', 1, b'foo\r\r\r\r', '--check'), |
24 | 36 | ) |
25 | 37 |
|
26 | 38 |
|
27 | | -@pytest.mark.parametrize(('input_s', 'expected_retval', 'output'), TESTS) |
28 | | -def test_fix_file(input_s, expected_retval, output): |
| 39 | +@pytest.mark.parametrize(('input_s', 'expected_retval', 'output', 'options'), TESTS) |
| 40 | +def test_fix_file(input_s, expected_retval, output, options): |
| 41 | + if options is None: |
| 42 | + options = [] |
| 43 | + elif isinstance(options, str): |
| 44 | + options = [options] |
| 45 | + |
29 | 46 | file_obj = io.BytesIO(input_s) |
30 | | - ret = fix_file(file_obj) |
| 47 | + ret = fix_file(file_obj, "--check" in [*options]) |
31 | 48 | assert file_obj.getvalue() == output |
32 | 49 | assert ret == expected_retval |
33 | 50 |
|
34 | 51 |
|
35 | | -@pytest.mark.parametrize(('input_s', 'expected_retval', 'output'), TESTS) |
36 | | -def test_integration(input_s, expected_retval, output, tmpdir): |
| 52 | +@pytest.mark.parametrize(('input_s', 'expected_retval', 'output', 'options'), TESTS) |
| 53 | +def test_integration(input_s, expected_retval, output, options, tmpdir): |
37 | 54 | path = tmpdir.join('file.txt') |
38 | 55 | path.write_binary(input_s) |
39 | 56 |
|
40 | | - ret = main([str(path)]) |
| 57 | + if options is None: |
| 58 | + options = [] |
| 59 | + elif isinstance(options, str): |
| 60 | + options = [options] |
| 61 | + |
| 62 | + ret = main([*options, str(path)]) |
41 | 63 | file_output = path.read_binary() |
42 | 64 |
|
43 | 65 | assert file_output == output |
|
0 commit comments