mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-01 02:56:52 +00:00
Update README.md about file-contents-sorter
This commit is contained in:
parent
8b41c575db
commit
4af7451154
2 changed files with 13 additions and 14 deletions
|
|
@ -51,6 +51,7 @@ Add this to your `.pre-commit-config.yaml`
|
|||
with single quoted strings.
|
||||
- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
|
||||
- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
|
||||
- `file-contents-sorter` - Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input to it.
|
||||
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
|
||||
- `flake8` - Run flake8 on your python files.
|
||||
- `forbid-new-submodules` - Prevent addition of new git submodules.
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
from argparse import ArgumentError
|
||||
|
||||
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 parse_commandline_input
|
||||
from pre_commit_hooks.file_contents_sorter import PASS
|
||||
from pre_commit_hooks.file_contents_sorter import sort_file_contents
|
||||
|
||||
|
||||
def _n(*strs):
|
||||
return b'\n'.join(strs) + '\n'
|
||||
return b'\n'.join(strs) + b'\n'
|
||||
|
||||
|
||||
# Input, expected return value, expected output
|
||||
TESTS = (
|
||||
(b'', PASS, b''),
|
||||
(_n('lonesome'), PASS, _n('lonesome')),
|
||||
(_n(b'lonesome'), PASS, _n(b'lonesome')),
|
||||
(b'missing_newline', PASS, b'missing_newline'),
|
||||
(_n('alpha', 'beta'), PASS, _n('alpha', 'beta')),
|
||||
(_n('beta', 'alpha'), FAIL, _n('alpha', 'beta')),
|
||||
(_n('C', 'c'), PASS, _n('C', 'c')),
|
||||
(_n('c', 'C'), FAIL, _n('C', 'c')),
|
||||
(_n('mag ical ', ' tre vor'), FAIL, _n(' tre vor', 'mag ical ')),
|
||||
(_n('@', '-', '_', '#'), FAIL, _n('#', '-', '@', '_')),
|
||||
(_n(b'alpha', b'beta'), PASS, _n(b'alpha', b'beta')),
|
||||
(_n(b'beta', b'alpha'), FAIL, _n(b'alpha', b'beta')),
|
||||
(_n(b'C', b'c'), PASS, _n(b'C', b'c')),
|
||||
(_n(b'c', b'C'), FAIL, _n(b'C', b'c')),
|
||||
(_n(b'mag ical ', b' tre vor'), FAIL, _n(b' tre vor', b'mag ical ')),
|
||||
(_n(b'@', b'-', b'_', b'#'), FAIL, _n(b'#', b'-', b'@', b'_')),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -42,13 +39,14 @@ def test_parse_commandline_input_errors_without_args():
|
|||
with pytest.raises(SystemExit):
|
||||
parse_commandline_input([])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('filename_list'),
|
||||
('filename_list'),
|
||||
(
|
||||
['filename1'],
|
||||
['filename1'],
|
||||
['filename1', 'filename2'],
|
||||
)
|
||||
)
|
||||
def test_parse_commandline_input_success(filename_list):
|
||||
args = parse_commandline_input(filename_list)
|
||||
assert args.filenames == filename_list
|
||||
assert args.filenames == filename_list
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue