Respond to review feedback

This commit is contained in:
Daniel Gallagher 2017-06-23 14:58:24 -07:00
parent 4af7451154
commit b941d0e6df
4 changed files with 9 additions and 14 deletions

View file

@ -110,7 +110,7 @@
description: Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input in your .pre-commit-config.yaml file.
entry: file-contents-sorter
language: python
files: ''
files: '^$'
- id: fix-encoding-pragma
name: Fix python encoding pragma
language: python

View file

@ -18,7 +18,7 @@ FAIL = 1
def sort_file_contents(f):
before = [line for line in f]
before = list(f)
after = sorted(before)
before_string = b''.join(before)

View file

@ -2,7 +2,6 @@
coverage
flake8
ipdb
mock
pre-commit
pytest

View file

@ -6,21 +6,17 @@ from pre_commit_hooks.file_contents_sorter import parse_commandline_input
from pre_commit_hooks.file_contents_sorter import PASS
def _n(*strs):
return b'\n'.join(strs) + b'\n'
# Input, expected return value, expected output
TESTS = (
(b'', PASS, b''),
(_n(b'lonesome'), PASS, _n(b'lonesome')),
(b'lonesome\n', PASS, b'lonesome\n'),
(b'missing_newline', PASS, b'missing_newline'),
(_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'_')),
(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'),
)