Skip to content

Commit 12794c1

Browse files
committed
Add some tests for tests_should_end_in_test hook
1 parent d2e45f3 commit 12794c1

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

pre_commit_hooks/tests_should_end_in_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
from __future__ import print_function
3+
24
import sys
35

46

@@ -11,14 +13,14 @@ def validate_files(argv):
1113
not filename.endswith('/conftest.py')
1214
):
1315
retcode = 1
14-
print '{0} does not end in _test.py'.format(filename)
16+
print('{0} does not end in _test.py'.format(filename))
1517

1618
return retcode
1719

1820

1921
def entry():
20-
validate_files(sys.argv[1:])
22+
return validate_files(sys.argv[1:])
2123

2224

2325
if __name__ == '__main__':
24-
sys.exit(entry())
26+
sys.exit(entry())

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import __builtin__
3+
4+
import mock
5+
import pytest
6+
7+
8+
@pytest.yield_fixture
9+
def print_mock():
10+
with mock.patch.object(__builtin__, 'print', autospec=True) as mock_print:
11+
yield mock_print
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
from pre_commit_hooks.tests_should_end_in_test import validate_files
3+
4+
5+
def test_validate_files_all_pass(print_mock):
6+
ret = validate_files(['foo_test.py', 'bar_test.py'])
7+
assert ret == 0
8+
assert print_mock.call_count == 0
9+
10+
11+
def test_validate_files_one_fails(print_mock):
12+
ret = validate_files(['not_test_ending.py', 'foo_test.py'])
13+
assert ret == 1
14+
assert print_mock.call_count == 1

0 commit comments

Comments
 (0)