blob: 2b5a0deaaf6512ca82a00265a34c9fc917edfc1e [file] [log] [blame]
Anthony Sottile8f615292022-01-15 19:24:05 -05001from __future__ import annotations
2
Anthony Sottile030bfac2019-01-31 19:19:10 -08003from pre_commit_hooks.tests_should_end_in_test import main
Anthony Sottile12794c12014-03-18 21:25:36 -07004
5
Anthony Sottile030bfac2019-01-31 19:19:10 -08006def test_main_all_pass():
7 ret = main(['foo_test.py', 'bar_test.py'])
Anthony Sottile12794c12014-03-18 21:25:36 -07008 assert ret == 0
Anthony Sottile12794c12014-03-18 21:25:36 -07009
10
Anthony Sottile030bfac2019-01-31 19:19:10 -080011def test_main_one_fails():
12 ret = main(['not_test_ending.py', 'foo_test.py'])
Anthony Sottile12794c12014-03-18 21:25:36 -070013 assert ret == 1
Guy Kiseldb4b8f02015-03-11 17:44:59 -070014
15
Rich Rauenzahn3724c8f2019-12-04 15:06:32 -080016def test_regex():
17 assert main(('foo_test_py',)) == 1
18
19
Anthony Sottile030bfac2019-01-31 19:19:10 -080020def test_main_django_all_pass():
Anthony Sottile45756522019-02-11 19:56:15 -080021 ret = main((
22 '--django', 'tests.py', 'test_foo.py', 'test_bar.py',
23 'tests/test_baz.py',
24 ))
Guy Kiseldb4b8f02015-03-11 17:44:59 -070025 assert ret == 0
26
27
Anthony Sottile030bfac2019-01-31 19:19:10 -080028def test_main_django_one_fails():
29 ret = main(['--django', 'not_test_ending.py', 'test_foo.py'])
Guy Kiseldb4b8f02015-03-11 17:44:59 -070030 assert ret == 1
31
32
phoxelua58edfc82015-11-19 00:18:38 -080033def test_validate_nested_files_django_one_fails():
Anthony Sottile030bfac2019-01-31 19:19:10 -080034 ret = main(['--django', 'tests/not_test_ending.py', 'test_foo.py'])
phoxelua58edfc82015-11-19 00:18:38 -080035 assert ret == 1
36
37
Anthony Sottile030bfac2019-01-31 19:19:10 -080038def test_main_not_django_fails():
39 ret = main(['foo_test.py', 'bar_test.py', 'test_baz.py'])
Guy Kiseldb4b8f02015-03-11 17:44:59 -070040 assert ret == 1
41
42
Anthony Sottile030bfac2019-01-31 19:19:10 -080043def test_main_django_fails():
44 ret = main(['--django', 'foo_test.py', 'test_bar.py', 'test_baz.py'])
Guy Kiseldb4b8f02015-03-11 17:44:59 -070045 assert ret == 1
Anthony Sottile412564f2022-06-07 09:10:42 -070046
47
48def test_main_pytest_test_first():
49 assert main(['--pytest-test-first', 'test_foo.py']) == 0
50 assert main(['--pytest-test-first', 'foo_test.py']) == 1