Skip to content

Commit e67f10e

Browse files
Create a file for get_test_info
1 parent 54c4e1d commit e67f10e

File tree

3 files changed

+47
-48
lines changed

3 files changed

+47
-48
lines changed

pylint/testutils/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@
4444

4545
from pylint.testutils.constants import UPDATE_OPTION
4646
from pylint.testutils.functional_test_file import FunctionalTestFile
47+
from pylint.testutils.get_test_info import _get_tests_info
4748
from pylint.testutils.lint_module_test import LintModuleTest
4849
from pylint.testutils.output_line import Message
4950
from pylint.testutils.reporter_for_tests import GenericTestReporter, MinimalTestReporter
50-
from pylint.testutils.utils import (
51-
CheckerTestCase,
52-
_get_tests_info,
53-
_tokenize_str,
54-
linter,
55-
set_config,
56-
)
51+
from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter, set_config

pylint/testutils/get_test_info.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2+
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
3+
4+
from glob import glob
5+
from os.path import basename, join, splitext
6+
7+
from pylint.testutils.constants import SYS_VERS_STR
8+
9+
10+
def _get_tests_info(input_dir, msg_dir, prefix, suffix):
11+
"""get python input examples and output messages
12+
13+
We use following conventions for input files and messages:
14+
for different inputs:
15+
test for python >= x.y -> input = <name>_pyxy.py
16+
test for python < x.y -> input = <name>_py_xy.py
17+
for one input and different messages:
18+
message for python >= x.y -> message = <name>_pyxy.txt
19+
lower versions -> message with highest num
20+
"""
21+
result = []
22+
for fname in glob(join(input_dir, prefix + "*" + suffix)):
23+
infile = basename(fname)
24+
fbase = splitext(infile)[0]
25+
# filter input files :
26+
pyrestr = fbase.rsplit("_py", 1)[-1] # like _26 or 26
27+
if pyrestr.isdigit(): # '24', '25'...
28+
if SYS_VERS_STR < pyrestr:
29+
continue
30+
if pyrestr.startswith("_") and pyrestr[1:].isdigit():
31+
# skip test for higher python versions
32+
if SYS_VERS_STR >= pyrestr[1:]:
33+
continue
34+
messages = glob(join(msg_dir, fbase + "*.txt"))
35+
# the last one will be without ext, i.e. for all or upper versions:
36+
if messages:
37+
for outfile in sorted(messages, reverse=True):
38+
py_rest = outfile.rsplit("_py", 1)[-1][:-4]
39+
if py_rest.isdigit() and SYS_VERS_STR >= py_rest:
40+
break
41+
else:
42+
# This will provide an error message indicating the missing filename.
43+
outfile = join(msg_dir, fbase + ".txt")
44+
result.append((infile, outfile))
45+
return result

pylint/testutils/utils.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,13 @@
55
import contextlib
66
import functools
77
import tokenize
8-
from glob import glob
98
from io import StringIO
10-
from os.path import basename, join, splitext
119

12-
from pylint.testutils.constants import SYS_VERS_STR
1310
from pylint.testutils.global_test_linter import linter
1411
from pylint.testutils.output_line import Message
1512
from pylint.utils import ASTWalker
1613

1714

18-
def _get_tests_info(input_dir, msg_dir, prefix, suffix):
19-
"""get python input examples and output messages
20-
21-
We use following conventions for input files and messages:
22-
for different inputs:
23-
test for python >= x.y -> input = <name>_pyxy.py
24-
test for python < x.y -> input = <name>_py_xy.py
25-
for one input and different messages:
26-
message for python >= x.y -> message = <name>_pyxy.txt
27-
lower versions -> message with highest num
28-
"""
29-
result = []
30-
for fname in glob(join(input_dir, prefix + "*" + suffix)):
31-
infile = basename(fname)
32-
fbase = splitext(infile)[0]
33-
# filter input files :
34-
pyrestr = fbase.rsplit("_py", 1)[-1] # like _26 or 26
35-
if pyrestr.isdigit(): # '24', '25'...
36-
if SYS_VERS_STR < pyrestr:
37-
continue
38-
if pyrestr.startswith("_") and pyrestr[1:].isdigit():
39-
# skip test for higher python versions
40-
if SYS_VERS_STR >= pyrestr[1:]:
41-
continue
42-
messages = glob(join(msg_dir, fbase + "*.txt"))
43-
# the last one will be without ext, i.e. for all or upper versions:
44-
if messages:
45-
for outfile in sorted(messages, reverse=True):
46-
py_rest = outfile.rsplit("_py", 1)[-1][:-4]
47-
if py_rest.isdigit() and SYS_VERS_STR >= py_rest:
48-
break
49-
else:
50-
# This will provide an error message indicating the missing filename.
51-
outfile = join(msg_dir, fbase + ".txt")
52-
result.append((infile, outfile))
53-
return result
54-
55-
5615
class UnittestLinter:
5716
"""A fake linter class to capture checker messages."""
5817

0 commit comments

Comments
 (0)