Improve test coverage.

This commit is contained in:
Anthony Sottile 2014-04-13 22:21:42 -07:00
parent b80ca9e84a
commit 8270d81308
4 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,5 @@
def foo(obj):
import pdb; pdb.set_trace()
return 5

View File

@ -2,7 +2,9 @@ import ast
import pytest
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 testing.util import get_resource_path
@pytest.fixture
@ -53,3 +55,13 @@ def test_returns_one_form_2(ast_with_debug_import_form_2):
assert visitor.debug_import_statements == [
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

View 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

View File

@ -9,7 +9,7 @@ deps = -rrequirements_dev.txt
commands =
coverage erase
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
pylint {[tox]project} testing tests setup.py