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. 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 entry: file-contents-sorter
language: python language: python
files: '' files: '^$'
- id: fix-encoding-pragma - id: fix-encoding-pragma
name: Fix python encoding pragma name: Fix python encoding pragma
language: python language: python

View file

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

View file

@ -2,7 +2,6 @@
coverage coverage
flake8 flake8
ipdb
mock mock
pre-commit pre-commit
pytest 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 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 # Input, expected return value, expected output
TESTS = ( TESTS = (
(b'', PASS, b''), (b'', PASS, b''),
(_n(b'lonesome'), PASS, _n(b'lonesome')), (b'lonesome\n', PASS, b'lonesome\n'),
(b'missing_newline', PASS, b'missing_newline'), (b'missing_newline', PASS, b'missing_newline'),
(_n(b'alpha', b'beta'), PASS, _n(b'alpha', b'beta')), (b'alpha\nbeta\n', PASS, b'alpha\nbeta\n'),
(_n(b'beta', b'alpha'), FAIL, _n(b'alpha', b'beta')), (b'beta\nalpha\n', FAIL, b'alpha\nbeta\n'),
(_n(b'C', b'c'), PASS, _n(b'C', b'c')), (b'C\nc\n', PASS, b'C\nc\n'),
(_n(b'c', b'C'), FAIL, _n(b'C', b'c')), (b'c\nC\n', FAIL, b'C\nc\n'),
(_n(b'mag ical ', b' tre vor'), FAIL, _n(b' tre vor', b'mag ical ')), (b'mag ical \n tre vor\n', FAIL, b' tre vor\nmag ical \n'),
(_n(b'@', b'-', b'_', b'#'), FAIL, _n(b'#', b'-', b'@', b'_')), (b'@\n-\n_\n#\n', FAIL, b'#\n-\n@\n_\n'),
) )