Skip to content

Commit b142c9d

Browse files
[doc testing] Add a mechanism to be able to test example for old names
1 parent 2ee0ef8 commit b142c9d

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

doc/test_messages_documentation.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import sys
88

9+
from pylint.exceptions import UnknownMessageError
10+
911
if sys.version_info[:2] > (3, 9):
1012
from collections import Counter
1113
else:
@@ -71,7 +73,6 @@ def get_functional_test_files_from_directory(input_dir: Path) -> List[Tuple[str,
7173
class LintModuleTest:
7274
def __init__(self, test_file: Tuple[str, Path]) -> None:
7375
self._test_file = test_file
74-
7576
_test_reporter = FunctionalTestReporter()
7677

7778
self._linter = PyLinter()
@@ -81,22 +82,36 @@ def __init__(self, test_file: Tuple[str, Path]) -> None:
8182
# Check if this message has a custom configuration file (e.g. for enabling optional checkers).
8283
# If not, use the default configuration.
8384
config_file: Optional[Path]
84-
if (test_file[1].parent / "pylintrc").exists():
85-
config_file = test_file[1].parent / "pylintrc"
85+
msgid, full_path = test_file
86+
pylintrc = full_path.parent / "pylintrc"
87+
if pylintrc.exists():
88+
config_file = pylintrc
8689
else:
8790
config_file = next(config.find_default_config_files(), None)
88-
91+
args = [
92+
str(full_path),
93+
"--disable=all",
94+
self._get_actives_message_to_enable(msgid),
95+
]
96+
print(f"Command used:\npylint {' '.join(args)}")
8997
_config_initialization(
9098
self._linter,
91-
args_list=[
92-
str(test_file[1]),
93-
"--disable=all",
94-
f"--enable={test_file[0]},astroid-error,fatal,syntax-error",
95-
],
99+
args_list=args,
96100
reporter=_test_reporter,
97101
config_file=config_file,
98102
)
99103

104+
def _get_actives_message_to_enable(self, msgid):
105+
"""We need to do that in order to be able to handle examples for old names if
106+
their new names are not activated the example won't work."""
107+
try:
108+
msg_definitions = self._linter.msgs_store.get_message_definitions(msgid)
109+
msgids = ",".join(m.symbol for m in msg_definitions)
110+
except UnknownMessageError:
111+
# We're testing an extension, the messages are not registered (TODO?)
112+
msgids = msgid
113+
return f"--enable={msgids},astroid-error,fatal,syntax-error"
114+
100115
def runTest(self) -> None:
101116
self._runTest()
102117

0 commit comments

Comments
 (0)