Improve test coverage.
diff --git a/testing/resources/file_with_debug.notpy b/testing/resources/file_with_debug.notpy
new file mode 100644
index 0000000..faa23a2
--- /dev/null
+++ b/testing/resources/file_with_debug.notpy
@@ -0,0 +1,5 @@
+
+def foo(obj):
+ import pdb; pdb.set_trace()
+
+ return 5
diff --git a/tests/debug_statement_hook_test.py b/tests/debug_statement_hook_test.py
index a054426..44c462f 100644
--- a/tests/debug_statement_hook_test.py
+++ b/tests/debug_statement_hook_test.py
@@ -2,7 +2,9 @@
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 @@
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
diff --git a/tests/trailing_whitespace_fixer_test.py b/tests/trailing_whitespace_fixer_test.py
new file mode 100644
index 0000000..9a6cd03
--- /dev/null
+++ b/tests/trailing_whitespace_fixer_test.py
@@ -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
diff --git a/tox.ini b/tox.ini
index 7dccc5a..f99bbc5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,7 +9,7 @@
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