Skip to content

Commit 833ed55

Browse files
Deprecate some file in pylint/testutils and update changelog
1 parent 3f1588c commit 833ed55

File tree

7 files changed

+113
-75
lines changed

7 files changed

+113
-75
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Release date: TBA
1111
..
1212
Put new features here and also in 'doc/whatsnew/2.13.rst'
1313

14+
* Some file in ``pylint.testutils`` were deprecated, imports should be done from the
15+
``pylint.testutils`` API directly
1416

1517
..
1618
Insert your changelog randomly, it will reduce merge conflicts

pylint/testutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from pylint.testutils.checker_test_case import CheckerTestCase
5050
from pylint.testutils.constants import UPDATE_FILE, UPDATE_OPTION
5151
from pylint.testutils.decorator import set_config
52-
from pylint.testutils.functional_test_file import FunctionalTestFile
52+
from pylint.testutils.functional.test_file import FunctionalTestFile
5353
from pylint.testutils.get_test_info import _get_tests_info
5454
from pylint.testutils.global_test_linter import linter
5555
from pylint.testutils.lint_module_test import LintModuleTest
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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/main/LICENSE
3+
4+
__all__ = [
5+
"FunctionalTestFile",
6+
"NoFileError",
7+
"parse_python_version",
8+
]
9+
10+
from pylint.testutils.functional.test_file import (
11+
FunctionalTestFile,
12+
NoFileError,
13+
parse_python_version,
14+
)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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/main/LICENSE
3+
4+
import configparser
5+
from os.path import basename, exists, join
6+
7+
8+
def parse_python_version(ver_str):
9+
return tuple(int(digit) for digit in ver_str.split("."))
10+
11+
12+
class NoFileError(Exception):
13+
pass
14+
15+
16+
class FunctionalTestFile:
17+
"""A single functional test case file with options."""
18+
19+
_CONVERTERS = {
20+
"min_pyver": parse_python_version,
21+
"max_pyver": parse_python_version,
22+
"min_pyver_end_position": parse_python_version,
23+
"requires": lambda s: s.split(","),
24+
}
25+
26+
def __init__(self, directory, filename):
27+
self._directory = directory
28+
self.base = filename.replace(".py", "")
29+
self.options = {
30+
"min_pyver": (2, 5),
31+
"max_pyver": (4, 0),
32+
"min_pyver_end_position": (3, 8),
33+
"requires": [],
34+
"except_implementations": [],
35+
"exclude_platforms": [],
36+
}
37+
self._parse_options()
38+
39+
def __repr__(self):
40+
return f"FunctionalTest:{self.base}"
41+
42+
def _parse_options(self):
43+
cp = configparser.ConfigParser()
44+
cp.add_section("testoptions")
45+
try:
46+
cp.read(self.option_file)
47+
except NoFileError:
48+
pass
49+
50+
for name, value in cp.items("testoptions"):
51+
conv = self._CONVERTERS.get(name, lambda v: v)
52+
self.options[name] = conv(value)
53+
54+
@property
55+
def option_file(self):
56+
return self._file_type(".rc")
57+
58+
@property
59+
def module(self):
60+
package = basename(self._directory)
61+
return ".".join([package, self.base])
62+
63+
@property
64+
def expected_output(self):
65+
return self._file_type(".txt", check_exists=False)
66+
67+
@property
68+
def source(self):
69+
return self._file_type(".py")
70+
71+
def _file_type(self, ext, check_exists=True):
72+
name = join(self._directory, self.base + ext)
73+
if not check_exists or exists(name):
74+
return name
75+
raise NoFileError(f"Cannot find '{name}'.")
Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,22 @@
11
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33

4-
import configparser
5-
from os.path import basename, exists, join
6-
7-
8-
def parse_python_version(ver_str):
9-
return tuple(int(digit) for digit in ver_str.split("."))
10-
11-
12-
class NoFileError(Exception):
13-
pass
14-
15-
16-
class FunctionalTestFile:
17-
"""A single functional test case file with options."""
18-
19-
_CONVERTERS = {
20-
"min_pyver": parse_python_version,
21-
"max_pyver": parse_python_version,
22-
"min_pyver_end_position": parse_python_version,
23-
"requires": lambda s: s.split(","),
24-
}
25-
26-
def __init__(self, directory, filename):
27-
self._directory = directory
28-
self.base = filename.replace(".py", "")
29-
self.options = {
30-
"min_pyver": (2, 5),
31-
"max_pyver": (4, 0),
32-
"min_pyver_end_position": (3, 8),
33-
"requires": [],
34-
"except_implementations": [],
35-
"exclude_platforms": [],
36-
}
37-
self._parse_options()
38-
39-
def __repr__(self):
40-
return f"FunctionalTest:{self.base}"
41-
42-
def _parse_options(self):
43-
cp = configparser.ConfigParser()
44-
cp.add_section("testoptions")
45-
try:
46-
cp.read(self.option_file)
47-
except NoFileError:
48-
pass
49-
50-
for name, value in cp.items("testoptions"):
51-
conv = self._CONVERTERS.get(name, lambda v: v)
52-
self.options[name] = conv(value)
53-
54-
@property
55-
def option_file(self):
56-
return self._file_type(".rc")
57-
58-
@property
59-
def module(self):
60-
package = basename(self._directory)
61-
return ".".join([package, self.base])
62-
63-
@property
64-
def expected_output(self):
65-
return self._file_type(".txt", check_exists=False)
66-
67-
@property
68-
def source(self):
69-
return self._file_type(".py")
70-
71-
def _file_type(self, ext, check_exists=True):
72-
name = join(self._directory, self.base + ext)
73-
if not check_exists or exists(name):
74-
return name
75-
raise NoFileError(f"Cannot find '{name}'.")
4+
__all__ = [
5+
"FunctionalTestFile",
6+
"NoFileError",
7+
"parse_python_version",
8+
]
9+
10+
import warnings
11+
12+
from pylint.testutils.functional import (
13+
FunctionalTestFile,
14+
NoFileError,
15+
parse_python_version,
16+
)
17+
18+
warnings.warn(
19+
"'pylint.testutils.functional_test_file' will be accessible by"
20+
" the 'pylint.testutils.functional' API in pylint 3.0",
21+
DeprecationWarning,
22+
)

pylint/testutils/lint_module_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pylint.lint import PyLinter
1818
from pylint.message.message import Message
1919
from pylint.testutils.constants import _EXPECTED_RE, _OPERATORS, UPDATE_OPTION
20-
from pylint.testutils.functional_test_file import (
20+
from pylint.testutils.functional.test_file import (
2121
FunctionalTestFile,
2222
NoFileError,
2323
parse_python_version,

tests/test_functional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from pylint import testutils
3636
from pylint.testutils import UPDATE_FILE, UPDATE_OPTION
37-
from pylint.testutils.functional_test_file import FunctionalTestFile
37+
from pylint.testutils.functional.test_file import FunctionalTestFile
3838
from pylint.utils import HAS_ISORT_5
3939

4040
# TODOs

0 commit comments

Comments
 (0)