Add some tests for tests_should_end_in_test hook
diff --git a/pre_commit_hooks/tests_should_end_in_test.py b/pre_commit_hooks/tests_should_end_in_test.py index 86991f0..92f2031 100644 --- a/pre_commit_hooks/tests_should_end_in_test.py +++ b/pre_commit_hooks/tests_should_end_in_test.py
@@ -1,4 +1,6 @@ +from __future__ import print_function + import sys @@ -11,14 +13,14 @@ not filename.endswith('/conftest.py') ): retcode = 1 - print '{0} does not end in _test.py'.format(filename) + print('{0} does not end in _test.py'.format(filename)) return retcode def entry(): - validate_files(sys.argv[1:]) + return validate_files(sys.argv[1:]) if __name__ == '__main__': - sys.exit(entry()) \ No newline at end of file + sys.exit(entry())
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..762b31d --- /dev/null +++ b/tests/conftest.py
@@ -0,0 +1,11 @@ + +import __builtin__ + +import mock +import pytest + + +@pytest.yield_fixture +def print_mock(): + with mock.patch.object(__builtin__, 'print', autospec=True) as mock_print: + yield mock_print
diff --git a/tests/tests_should_end_in_test_test.py b/tests/tests_should_end_in_test_test.py new file mode 100644 index 0000000..e56b84e --- /dev/null +++ b/tests/tests_should_end_in_test_test.py
@@ -0,0 +1,14 @@ + +from pre_commit_hooks.tests_should_end_in_test import validate_files + + +def test_validate_files_all_pass(print_mock): + ret = validate_files(['foo_test.py', 'bar_test.py']) + assert ret == 0 + assert print_mock.call_count == 0 + + +def test_validate_files_one_fails(print_mock): + ret = validate_files(['not_test_ending.py', 'foo_test.py']) + assert ret == 1 + assert print_mock.call_count == 1