mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 05:44:16 +00:00
Improve test coverage.
This commit is contained in:
parent
b80ca9e84a
commit
8270d81308
4 changed files with 44 additions and 1 deletions
26
tests/trailing_whitespace_fixer_test.py
Normal file
26
tests/trailing_whitespace_fixer_test.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from plumbum import local
|
||||
|
||||
from pre_commit_hooks.trailing_whitespace_fixer import fix_trailing_whitespace
|
||||
|
||||
|
||||
def test_fixes_trailing_whitespace(tmpdir):
|
||||
with local.cwd(tmpdir.strpath):
|
||||
for filename, contents in (
|
||||
('foo.py', 'foo \nbar \n'),
|
||||
('bar.py', 'bar\t\nbaz\t\n'),
|
||||
):
|
||||
with open(filename, 'w') as file_obj:
|
||||
file_obj.write(contents)
|
||||
|
||||
ret = fix_trailing_whitespace(['foo.py', 'bar.py'])
|
||||
assert ret == 1
|
||||
|
||||
for filename, after_contents in (
|
||||
('foo.py', 'foo\nbar\n'),
|
||||
('bar.py', 'bar\nbaz\n'),
|
||||
):
|
||||
assert open(filename).read() == after_contents
|
||||
|
||||
|
||||
def test_returns_zero_for_no_changes():
|
||||
assert fix_trailing_whitespace([__file__]) == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue