From 8270d8130803699b02ec3baff8292de0a9df78dc Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 13 Apr 2014 22:21:42 -0700 Subject: [PATCH] Improve test coverage. --- testing/resources/file_with_debug.notpy | 5 +++++ tests/debug_statement_hook_test.py | 12 ++++++++++++ tests/trailing_whitespace_fixer_test.py | 26 +++++++++++++++++++++++++ tox.ini | 2 +- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 testing/resources/file_with_debug.notpy create mode 100644 tests/trailing_whitespace_fixer_test.py 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 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 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 @@ 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