|
| 1 | +import pytest |
| 2 | + |
| 3 | +from pre_commit_hooks.file_contents_sorter import FAIL |
| 4 | +from pre_commit_hooks.file_contents_sorter import main |
| 5 | +from pre_commit_hooks.file_contents_sorter import PASS |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize( |
| 9 | + ('input_s', 'expected_retval', 'output'), |
| 10 | + ( |
| 11 | + (b'', PASS, b''), |
| 12 | + (b'lonesome\n', PASS, b'lonesome\n'), |
| 13 | + (b'missing_newline', PASS, b'missing_newline'), |
| 14 | + (b'alpha\nbeta\n', PASS, b'alpha\nbeta\n'), |
| 15 | + (b'beta\nalpha\n', FAIL, b'alpha\nbeta\n'), |
| 16 | + (b'C\nc\n', PASS, b'C\nc\n'), |
| 17 | + (b'c\nC\n', FAIL, b'C\nc\n'), |
| 18 | + (b'mag ical \n tre vor\n', FAIL, b' tre vor\nmag ical \n'), |
| 19 | + (b'@\n-\n_\n#\n', FAIL, b'#\n-\n@\n_\n'), |
| 20 | + ) |
| 21 | +) |
| 22 | +def test_integration(input_s, expected_retval, output, tmpdir): |
| 23 | + path = tmpdir.join('file.txt') |
| 24 | + path.write_binary(input_s) |
| 25 | + |
| 26 | + output_retval = main([path.strpath]) |
| 27 | + |
| 28 | + assert path.read_binary() == output |
| 29 | + assert output_retval == expected_retval |
0 commit comments