mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-10 21:34:18 +00:00
Improve test coverage.
This commit is contained in:
parent
b80ca9e84a
commit
8270d81308
4 changed files with 44 additions and 1 deletions
5
testing/resources/file_with_debug.notpy
Normal file
5
testing/resources/file_with_debug.notpy
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
def foo(obj):
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
|
|
||||||
|
return 5
|
||||||
|
|
@ -2,7 +2,9 @@ import ast
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pre_commit_hooks.debug_statement_hook import DebugStatement
|
from pre_commit_hooks.debug_statement_hook import DebugStatement
|
||||||
|
from pre_commit_hooks.debug_statement_hook import debug_statement_hook
|
||||||
from pre_commit_hooks.debug_statement_hook import ImportStatementParser
|
from pre_commit_hooks.debug_statement_hook import ImportStatementParser
|
||||||
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -53,3 +55,13 @@ def test_returns_one_form_2(ast_with_debug_import_form_2):
|
||||||
assert visitor.debug_import_statements == [
|
assert visitor.debug_import_statements == [
|
||||||
DebugStatement('pudb', 3, 0)
|
DebugStatement('pudb', 3, 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_returns_one_for_failing_file():
|
||||||
|
ret = debug_statement_hook([get_resource_path('file_with_debug.notpy')])
|
||||||
|
assert ret == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_returns_zero_for_passing_file():
|
||||||
|
ret = debug_statement_hook([__file__])
|
||||||
|
assert ret == 0
|
||||||
|
|
|
||||||
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
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -9,7 +9,7 @@ deps = -rrequirements_dev.txt
|
||||||
commands =
|
commands =
|
||||||
coverage erase
|
coverage erase
|
||||||
coverage run -m pytest {posargs:tests}
|
coverage run -m pytest {posargs:tests}
|
||||||
coverage report --show-missing --fail-under 82
|
coverage report --show-missing --fail-under 100
|
||||||
flake8 {[tox]project} testing tests setup.py
|
flake8 {[tox]project} testing tests setup.py
|
||||||
pylint {[tox]project} testing tests setup.py
|
pylint {[tox]project} testing tests setup.py
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue