2
2
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3
3
4
4
import contextlib
5
- from typing import Dict , Optional , Type
5
+ from typing import Dict , Iterator , Type
6
+
7
+ from astroid .nodes import Module
6
8
7
9
from pylint .testutils .global_test_linter import linter
10
+ from pylint .testutils .output_line import Message
8
11
from pylint .testutils .unittest_linter import UnittestLinter
9
12
from pylint .utils import ASTWalker
10
13
11
14
12
15
class CheckerTestCase :
13
16
"""A base testcase class for unit testing individual checker classes."""
14
17
15
- CHECKER_CLASS : Optional [ Type ] = None
18
+ CHECKER_CLASS : Type
16
19
CONFIG : Dict = {}
17
20
18
- def setup_method (self ):
21
+ def setup_method (self ) -> None :
19
22
self .linter = UnittestLinter ()
20
23
self .checker = self .CHECKER_CLASS (self .linter ) # pylint: disable=not-callable
21
24
for key , value in self .CONFIG .items ():
22
25
setattr (self .checker .config , key , value )
23
26
self .checker .open ()
24
27
25
28
@contextlib .contextmanager
26
- def assertNoMessages (self ):
29
+ def assertNoMessages (self ) -> Iterator [ None ] :
27
30
"""Assert that no messages are added by the given method."""
28
31
with self .assertAddsMessages ():
29
32
yield
30
33
31
34
@contextlib .contextmanager
32
- def assertAddsMessages (self , * messages ) :
35
+ def assertAddsMessages (self , * messages : Message ) -> Iterator [ None ] :
33
36
"""Assert that exactly the given method adds the given messages.
34
37
35
38
The list of messages must exactly match *all* the messages added by the
@@ -47,7 +50,7 @@ def assertAddsMessages(self, *messages):
47
50
)
48
51
assert got == list (messages ), msg
49
52
50
- def walk (self , node ) :
53
+ def walk (self , node : Module ) -> None :
51
54
"""recursive walk on the given node"""
52
55
walker = ASTWalker (linter )
53
56
walker .add_checker (self .checker )
0 commit comments