|
8 | 8 |
|
9 | 9 | """functional/non regression tests for pylint"""
|
10 | 10 |
|
11 |
| -import unittest |
12 | 11 | import sys
|
13 | 12 | import re
|
14 | 13 |
|
15 |
| -from os import getcwd |
| 14 | +import pytest |
16 | 15 | from os.path import abspath, dirname, join
|
17 | 16 |
|
18 |
| -from pylint.testutils import (make_tests, LintTestUsingModule, LintTestUsingFile, |
19 |
| - LintTestUpdate, cb_test_gen, linter) |
| 17 | +from pylint.testutils import get_tests_info, LintTestUsingModule, LintTestUpdate |
20 | 18 |
|
21 | 19 | PY3K = sys.version_info >= (3, 0)
|
| 20 | +SYS_VERS_STR = '%d%d%d' % sys.version_info[:3] |
22 | 21 |
|
23 | 22 | # Configure paths
|
24 | 23 | INPUT_DIR = join(dirname(abspath(__file__)), 'input')
|
25 | 24 | MSG_DIR = join(dirname(abspath(__file__)), 'messages')
|
26 | 25 |
|
| 26 | +FILTER_RGX = None |
| 27 | +UPDATE = False |
| 28 | + |
27 | 29 | # Classes
|
28 | 30 |
|
29 | 31 | quote = "'" if sys.version_info >= (3, 3) else ''
|
30 | 32 |
|
31 |
| -def gen_tests(filter_rgx): |
32 |
| - if UPDATE: |
33 |
| - callbacks = [cb_test_gen(LintTestUpdate)] |
34 |
| - else: |
35 |
| - callbacks = [cb_test_gen(LintTestUsingModule)] |
36 |
| - tests = make_tests(INPUT_DIR, MSG_DIR, filter_rgx, callbacks) |
37 |
| - if UPDATE: |
38 |
| - return tests |
39 | 33 |
|
| 34 | +def gen_tests(filter_rgx): |
40 | 35 | if filter_rgx:
|
41 | 36 | is_to_run = re.compile(filter_rgx).search
|
42 | 37 | else:
|
43 | 38 | is_to_run = lambda x: 1
|
| 39 | + tests = [] |
| 40 | + for module_file, messages_file in ( |
| 41 | + get_tests_info(INPUT_DIR, MSG_DIR, 'func_', '') |
| 42 | + ): |
| 43 | + if not is_to_run(module_file) or module_file.endswith(('.pyc', "$py.class")): |
| 44 | + continue |
| 45 | + base = module_file.replace('func_', '').replace('.py', '') |
| 46 | + dependencies = get_tests_info(INPUT_DIR, MSG_DIR, base, '.py') |
| 47 | + tests.append((module_file, messages_file, dependencies)) |
| 48 | + |
| 49 | + if UPDATE: |
| 50 | + return tests |
44 | 51 |
|
45 | 52 | assert len(tests) < 196, "Please do not add new test cases here."
|
46 | 53 | return tests
|
47 | 54 |
|
48 |
| -# Create suite |
49 |
| - |
50 |
| -FILTER_RGX = None |
51 |
| -UPDATE = False |
52 |
| - |
53 |
| -def suite(): |
54 |
| - return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite) |
55 |
| - for test in gen_tests(FILTER_RGX)]) |
56 | 55 |
|
| 56 | +@pytest.mark.parametrize("module_file,messages_file,dependencies", gen_tests(FILTER_RGX)) |
| 57 | +def test_functionality(module_file, messages_file, dependencies): |
57 | 58 |
|
58 |
| -def load_tests(loader, tests, pattern): |
59 |
| - return suite() |
| 59 | + LT = LintTestUpdate() if UPDATE else LintTestUsingModule() |
60 | 60 |
|
| 61 | + LT.module = module_file.replace('.py', '') |
| 62 | + LT.output = messages_file |
| 63 | + LT.depends = dependencies or None |
| 64 | + LT.INPUT_DIR = INPUT_DIR |
| 65 | + LT._test_functionality() |
61 | 66 |
|
62 |
| -if __name__=='__main__': |
| 67 | +if __name__ == '__main__': |
63 | 68 | if '-u' in sys.argv:
|
64 | 69 | UPDATE = True
|
65 | 70 | sys.argv.remove('-u')
|
66 | 71 |
|
67 | 72 | if len(sys.argv) > 1:
|
68 | 73 | FILTER_RGX = sys.argv[1]
|
69 | 74 | del sys.argv[1]
|
70 |
| - unittest.main(defaultTest='suite') |
| 75 | + pytest.main(sys.argv) |
0 commit comments