提交 4af74511 编辑于 作者: Daniel Gallagher's avatar Daniel Gallagher
浏览文件

Update README.md about file-contents-sorter

显示 13 个添加14 个删除
+13 -14
......@@ -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.
......
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
\ No newline at end of file
assert args.filenames == filename_list
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册