summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-29 11:10:11 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-29 11:59:49 +0100
commite67f10e9303ba6a73da4ef0b24331cec37a91c78 (patch)
treec920f8de1e76ef7cff5f1e39c1abacbe873aa572
parent54c4e1dc404456e1dc33540a24eed8ce68b234e0 (diff)
downloadpylint-git-e67f10e9303ba6a73da4ef0b24331cec37a91c78.tar.gz
Create a file for get_test_info
-rw-r--r--pylint/testutils/__init__.py9
-rw-r--r--pylint/testutils/get_test_info.py45
-rw-r--r--pylint/testutils/utils.py41
3 files changed, 47 insertions, 48 deletions
diff --git a/pylint/testutils/__init__.py b/pylint/testutils/__init__.py
index 60550340c..5050b631c 100644
--- a/pylint/testutils/__init__.py
+++ b/pylint/testutils/__init__.py
@@ -44,13 +44,8 @@ __all__ = [
from pylint.testutils.constants import UPDATE_OPTION
from pylint.testutils.functional_test_file import FunctionalTestFile
+from pylint.testutils.get_test_info import _get_tests_info
from pylint.testutils.lint_module_test import LintModuleTest
from pylint.testutils.output_line import Message
from pylint.testutils.reporter_for_tests import GenericTestReporter, MinimalTestReporter
-from pylint.testutils.utils import (
- CheckerTestCase,
- _get_tests_info,
- _tokenize_str,
- linter,
- set_config,
-)
+from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter, set_config
diff --git a/pylint/testutils/get_test_info.py b/pylint/testutils/get_test_info.py
new file mode 100644
index 000000000..ea2caea1e
--- /dev/null
+++ b/pylint/testutils/get_test_info.py
@@ -0,0 +1,45 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
+
+from glob import glob
+from os.path import basename, join, splitext
+
+from pylint.testutils.constants import SYS_VERS_STR
+
+
+def _get_tests_info(input_dir, msg_dir, prefix, suffix):
+ """get python input examples and output messages
+
+ We use following conventions for input files and messages:
+ for different inputs:
+ test for python >= x.y -> input = <name>_pyxy.py
+ test for python < x.y -> input = <name>_py_xy.py
+ for one input and different messages:
+ message for python >= x.y -> message = <name>_pyxy.txt
+ lower versions -> message with highest num
+ """
+ result = []
+ for fname in glob(join(input_dir, prefix + "*" + suffix)):
+ infile = basename(fname)
+ fbase = splitext(infile)[0]
+ # filter input files :
+ pyrestr = fbase.rsplit("_py", 1)[-1] # like _26 or 26
+ if pyrestr.isdigit(): # '24', '25'...
+ if SYS_VERS_STR < pyrestr:
+ continue
+ if pyrestr.startswith("_") and pyrestr[1:].isdigit():
+ # skip test for higher python versions
+ if SYS_VERS_STR >= pyrestr[1:]:
+ continue
+ messages = glob(join(msg_dir, fbase + "*.txt"))
+ # the last one will be without ext, i.e. for all or upper versions:
+ if messages:
+ for outfile in sorted(messages, reverse=True):
+ py_rest = outfile.rsplit("_py", 1)[-1][:-4]
+ if py_rest.isdigit() and SYS_VERS_STR >= py_rest:
+ break
+ else:
+ # This will provide an error message indicating the missing filename.
+ outfile = join(msg_dir, fbase + ".txt")
+ result.append((infile, outfile))
+ return result
diff --git a/pylint/testutils/utils.py b/pylint/testutils/utils.py
index 3576f5977..893bb3e2d 100644
--- a/pylint/testutils/utils.py
+++ b/pylint/testutils/utils.py
@@ -5,54 +5,13 @@
import contextlib
import functools
import tokenize
-from glob import glob
from io import StringIO
-from os.path import basename, join, splitext
-from pylint.testutils.constants import SYS_VERS_STR
from pylint.testutils.global_test_linter import linter
from pylint.testutils.output_line import Message
from pylint.utils import ASTWalker
-def _get_tests_info(input_dir, msg_dir, prefix, suffix):
- """get python input examples and output messages
-
- We use following conventions for input files and messages:
- for different inputs:
- test for python >= x.y -> input = <name>_pyxy.py
- test for python < x.y -> input = <name>_py_xy.py
- for one input and different messages:
- message for python >= x.y -> message = <name>_pyxy.txt
- lower versions -> message with highest num
- """
- result = []
- for fname in glob(join(input_dir, prefix + "*" + suffix)):
- infile = basename(fname)
- fbase = splitext(infile)[0]
- # filter input files :
- pyrestr = fbase.rsplit("_py", 1)[-1] # like _26 or 26
- if pyrestr.isdigit(): # '24', '25'...
- if SYS_VERS_STR < pyrestr:
- continue
- if pyrestr.startswith("_") and pyrestr[1:].isdigit():
- # skip test for higher python versions
- if SYS_VERS_STR >= pyrestr[1:]:
- continue
- messages = glob(join(msg_dir, fbase + "*.txt"))
- # the last one will be without ext, i.e. for all or upper versions:
- if messages:
- for outfile in sorted(messages, reverse=True):
- py_rest = outfile.rsplit("_py", 1)[-1][:-4]
- if py_rest.isdigit() and SYS_VERS_STR >= py_rest:
- break
- else:
- # This will provide an error message indicating the missing filename.
- outfile = join(msg_dir, fbase + ".txt")
- result.append((infile, outfile))
- return result
-
-
class UnittestLinter:
"""A fake linter class to capture checker messages."""