Anthony Sottile | 8f61529 | 2022-01-15 19:24:05 -0500 | [diff] [blame] | 1 | from __future__ import annotations |
| 2 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 3 | from pre_commit_hooks.tests_should_end_in_test import main |
Anthony Sottile | 12794c1 | 2014-03-18 21:25:36 -0700 | [diff] [blame] | 4 | |
| 5 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 6 | def test_main_all_pass(): |
| 7 | ret = main(['foo_test.py', 'bar_test.py']) |
Anthony Sottile | 12794c1 | 2014-03-18 21:25:36 -0700 | [diff] [blame] | 8 | assert ret == 0 |
Anthony Sottile | 12794c1 | 2014-03-18 21:25:36 -0700 | [diff] [blame] | 9 | |
| 10 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 11 | def test_main_one_fails(): |
| 12 | ret = main(['not_test_ending.py', 'foo_test.py']) |
Anthony Sottile | 12794c1 | 2014-03-18 21:25:36 -0700 | [diff] [blame] | 13 | assert ret == 1 |
Guy Kisel | db4b8f0 | 2015-03-11 17:44:59 -0700 | [diff] [blame] | 14 | |
| 15 | |
Rich Rauenzahn | 3724c8f | 2019-12-04 15:06:32 -0800 | [diff] [blame] | 16 | def test_regex(): |
| 17 | assert main(('foo_test_py',)) == 1 |
| 18 | |
| 19 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 20 | def test_main_django_all_pass(): |
Anthony Sottile | 4575652 | 2019-02-11 19:56:15 -0800 | [diff] [blame] | 21 | ret = main(( |
| 22 | '--django', 'tests.py', 'test_foo.py', 'test_bar.py', |
| 23 | 'tests/test_baz.py', |
| 24 | )) |
Guy Kisel | db4b8f0 | 2015-03-11 17:44:59 -0700 | [diff] [blame] | 25 | assert ret == 0 |
| 26 | |
| 27 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 28 | def test_main_django_one_fails(): |
| 29 | ret = main(['--django', 'not_test_ending.py', 'test_foo.py']) |
Guy Kisel | db4b8f0 | 2015-03-11 17:44:59 -0700 | [diff] [blame] | 30 | assert ret == 1 |
| 31 | |
| 32 | |
phoxelua | 58edfc8 | 2015-11-19 00:18:38 -0800 | [diff] [blame] | 33 | def test_validate_nested_files_django_one_fails(): |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 34 | ret = main(['--django', 'tests/not_test_ending.py', 'test_foo.py']) |
phoxelua | 58edfc8 | 2015-11-19 00:18:38 -0800 | [diff] [blame] | 35 | assert ret == 1 |
| 36 | |
| 37 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 38 | def test_main_not_django_fails(): |
| 39 | ret = main(['foo_test.py', 'bar_test.py', 'test_baz.py']) |
Guy Kisel | db4b8f0 | 2015-03-11 17:44:59 -0700 | [diff] [blame] | 40 | assert ret == 1 |
| 41 | |
| 42 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 43 | def test_main_django_fails(): |
| 44 | ret = main(['--django', 'foo_test.py', 'test_bar.py', 'test_baz.py']) |
Guy Kisel | db4b8f0 | 2015-03-11 17:44:59 -0700 | [diff] [blame] | 45 | assert ret == 1 |
Anthony Sottile | 412564f | 2022-06-07 09:10:42 -0700 | [diff] [blame] | 46 | |
| 47 | |
| 48 | def 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 |