6
6
7
7
import sys
8
8
9
+ from pylint .exceptions import UnknownMessageError
10
+
9
11
if sys .version_info [:2 ] > (3 , 9 ):
10
12
from collections import Counter
11
13
else :
@@ -71,7 +73,6 @@ def get_functional_test_files_from_directory(input_dir: Path) -> List[Tuple[str,
71
73
class LintModuleTest :
72
74
def __init__ (self , test_file : Tuple [str , Path ]) -> None :
73
75
self ._test_file = test_file
74
-
75
76
_test_reporter = FunctionalTestReporter ()
76
77
77
78
self ._linter = PyLinter ()
@@ -81,22 +82,36 @@ def __init__(self, test_file: Tuple[str, Path]) -> None:
81
82
# Check if this message has a custom configuration file (e.g. for enabling optional checkers).
82
83
# If not, use the default configuration.
83
84
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
86
89
else :
87
90
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:\n pylint { ' ' .join (args )} " )
89
97
_config_initialization (
90
98
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 ,
96
100
reporter = _test_reporter ,
97
101
config_file = config_file ,
98
102
)
99
103
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
+
100
115
def runTest (self ) -> None :
101
116
self ._runTest ()
102
117
0 commit comments