summaryrefslogtreecommitdiffstats
path: root/tests/file_contents_sorter_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-01-30 11:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:41:55 +0000
commitd4583dcad7d68d3c1503b04ec0d3364809304807 (patch)
tree82456c5d0bc77961759812ddd85414435ba89127 /tests/file_contents_sorter_test.py
parentInitial commit. (diff)
downloadpre-commit-hooks-upstream/4.5.0+dfsg.tar.xz
pre-commit-hooks-upstream/4.5.0+dfsg.zip
Adding upstream version 4.5.0+dfsg.upstream/4.5.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/file_contents_sorter_test.py')
-rw-r--r--tests/file_contents_sorter_test.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/file_contents_sorter_test.py b/tests/file_contents_sorter_test.py
new file mode 100644
index 0000000..49b3b79
--- /dev/null
+++ b/tests/file_contents_sorter_test.py
@@ -0,0 +1,91 @@
+from __future__ import annotations
+
+import pytest
+
+from pre_commit_hooks.file_contents_sorter import FAIL
+from pre_commit_hooks.file_contents_sorter import main
+from pre_commit_hooks.file_contents_sorter import PASS
+
+
+@pytest.mark.parametrize(
+ ('input_s', 'argv', 'expected_retval', 'output'),
+ (
+ (b'', [], PASS, b''),
+ (b'\n', [], FAIL, b''),
+ (b'\n\n', [], FAIL, b''),
+ (b'lonesome\n', [], PASS, b'lonesome\n'),
+ (b'missing_newline', [], FAIL, b'missing_newline\n'),
+ (b'newline\nmissing', [], FAIL, b'missing\nnewline\n'),
+ (b'missing\nnewline', [], FAIL, b'missing\nnewline\n'),
+ (b'alpha\nbeta\n', [], PASS, b'alpha\nbeta\n'),
+ (b'beta\nalpha\n', [], FAIL, b'alpha\nbeta\n'),
+ (b'C\nc\n', [], PASS, b'C\nc\n'),
+ (b'c\nC\n', [], FAIL, b'C\nc\n'),
+ (b'mag ical \n tre vor\n', [], FAIL, b' tre vor\nmag ical \n'),
+ (b'@\n-\n_\n#\n', [], FAIL, b'#\n-\n@\n_\n'),
+ (b'extra\n\n\nwhitespace\n', [], FAIL, b'extra\nwhitespace\n'),
+ (b'whitespace\n\n\nextra\n', [], FAIL, b'extra\nwhitespace\n'),
+ (
+ b'fee\nFie\nFoe\nfum\n',
+ [],
+ FAIL,
+ b'Fie\nFoe\nfee\nfum\n',
+ ),
+ (
+ b'Fie\nFoe\nfee\nfum\n',
+ [],
+ PASS,
+ b'Fie\nFoe\nfee\nfum\n',
+ ),
+ (
+ b'fee\nFie\nFoe\nfum\n',
+ ['--ignore-case'],
+ PASS,
+ b'fee\nFie\nFoe\nfum\n',
+ ),
+ (
+ b'Fie\nFoe\nfee\nfum\n',
+ ['--ignore-case'],
+ FAIL,
+ b'fee\nFie\nFoe\nfum\n',
+ ),
+ (
+ b'Fie\nFoe\nfee\nfee\nfum\n',
+ ['--ignore-case'],
+ FAIL,
+ b'fee\nfee\nFie\nFoe\nfum\n',
+ ),
+ (
+ b'Fie\nFoe\nfee\nfum\n',
+ ['--unique'],
+ PASS,
+ b'Fie\nFoe\nfee\nfum\n',
+ ),
+ (
+ b'Fie\nFie\nFoe\nfee\nfum\n',
+ ['--unique'],
+ FAIL,
+ b'Fie\nFoe\nfee\nfum\n',
+ ),
+ (
+ b'fee\nFie\nFoe\nfum\n',
+ ['--unique', '--ignore-case'],
+ PASS,
+ b'fee\nFie\nFoe\nfum\n',
+ ),
+ (
+ b'fee\nfee\nFie\nFoe\nfum\n',
+ ['--unique', '--ignore-case'],
+ FAIL,
+ b'fee\nFie\nFoe\nfum\n',
+ ),
+ ),
+)
+def test_integration(input_s, argv, expected_retval, output, tmpdir):
+ path = tmpdir.join('file.txt')
+ path.write_binary(input_s)
+
+ output_retval = main([str(path)] + argv)
+
+ assert path.read_binary() == output
+ assert output_retval == expected_retval