Skip to content

Commit 4af7451

Browse files
author
Daniel Gallagher
committed
Update README.md about file-contents-sorter
1 parent 8b41c57 commit 4af7451

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Add this to your `.pre-commit-config.yaml`
5151
with single quoted strings.
5252
- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
5353
- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
54+
- `file-contents-sorter` - Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input to it.
5455
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
5556
- `flake8` - Run flake8 on your python files.
5657
- `forbid-new-submodules` - Prevent addition of new git submodules.

tests/file_contents_sorter_test.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
from argparse import ArgumentError
2-
31
import pytest
42

53
from pre_commit_hooks.file_contents_sorter import FAIL
64
from pre_commit_hooks.file_contents_sorter import main
75
from pre_commit_hooks.file_contents_sorter import parse_commandline_input
86
from pre_commit_hooks.file_contents_sorter import PASS
9-
from pre_commit_hooks.file_contents_sorter import sort_file_contents
107

118

129
def _n(*strs):
13-
return b'\n'.join(strs) + '\n'
10+
return b'\n'.join(strs) + b'\n'
1411

1512

1613
# Input, expected return value, expected output
1714
TESTS = (
1815
(b'', PASS, b''),
19-
(_n('lonesome'), PASS, _n('lonesome')),
16+
(_n(b'lonesome'), PASS, _n(b'lonesome')),
2017
(b'missing_newline', PASS, b'missing_newline'),
21-
(_n('alpha', 'beta'), PASS, _n('alpha', 'beta')),
22-
(_n('beta', 'alpha'), FAIL, _n('alpha', 'beta')),
23-
(_n('C', 'c'), PASS, _n('C', 'c')),
24-
(_n('c', 'C'), FAIL, _n('C', 'c')),
25-
(_n('mag ical ', ' tre vor'), FAIL, _n(' tre vor', 'mag ical ')),
26-
(_n('@', '-', '_', '#'), FAIL, _n('#', '-', '@', '_')),
18+
(_n(b'alpha', b'beta'), PASS, _n(b'alpha', b'beta')),
19+
(_n(b'beta', b'alpha'), FAIL, _n(b'alpha', b'beta')),
20+
(_n(b'C', b'c'), PASS, _n(b'C', b'c')),
21+
(_n(b'c', b'C'), FAIL, _n(b'C', b'c')),
22+
(_n(b'mag ical ', b' tre vor'), FAIL, _n(b' tre vor', b'mag ical ')),
23+
(_n(b'@', b'-', b'_', b'#'), FAIL, _n(b'#', b'-', b'@', b'_')),
2724
)
2825

2926

@@ -42,13 +39,14 @@ def test_parse_commandline_input_errors_without_args():
4239
with pytest.raises(SystemExit):
4340
parse_commandline_input([])
4441

42+
4543
@pytest.mark.parametrize(
46-
('filename_list'),
44+
('filename_list'),
4745
(
48-
['filename1'],
46+
['filename1'],
4947
['filename1', 'filename2'],
5048
)
5149
)
5250
def test_parse_commandline_input_success(filename_list):
5351
args = parse_commandline_input(filename_list)
54-
assert args.filenames == filename_list
52+
assert args.filenames == filename_list

0 commit comments

Comments
 (0)