7
7
import sys
8
8
from collections import Counter
9
9
from io import StringIO
10
- from typing import TYPE_CHECKING , Dict , List , Optional , TextIO , Tuple
10
+ from typing import Counter as CounterType
11
+ from typing import Dict , List , Optional , TextIO , Tuple
11
12
12
13
import pytest
13
14
from _pytest .config import Config
25
26
from pylint .testutils .reporter_for_tests import FunctionalTestReporter
26
27
from pylint .utils import utils
27
28
28
- if TYPE_CHECKING :
29
- from typing import Counter as CounterType # typing.Counter added in Python 3.6.1
30
-
31
- MessageCounter = CounterType [Tuple [int , str ]]
29
+ MessageCounter = CounterType [Tuple [int , str ]]
32
30
33
31
34
32
class LintModuleTest :
@@ -99,15 +97,15 @@ def __str__(self) -> str:
99
97
return f"{ self ._test_file .base } ({ self .__class__ .__module__ } .{ self .__class__ .__name__ } )"
100
98
101
99
@staticmethod
102
- def get_expected_messages (stream : TextIO ) -> " MessageCounter" :
100
+ def get_expected_messages (stream : TextIO ) -> MessageCounter :
103
101
"""Parses a file and get expected messages.
104
102
105
103
:param stream: File-like input stream.
106
104
:type stream: enumerable
107
105
:returns: A dict mapping line,msg-symbol tuples to the count on this line.
108
106
:rtype: dict
109
107
"""
110
- messages : " MessageCounter" = Counter ()
108
+ messages : MessageCounter = Counter ()
111
109
for i , line in enumerate (stream ):
112
110
match = _EXPECTED_RE .search (line )
113
111
if match is None :
@@ -133,9 +131,9 @@ def get_expected_messages(stream: TextIO) -> "MessageCounter":
133
131
134
132
@staticmethod
135
133
def multiset_difference (
136
- expected_entries : " MessageCounter" ,
137
- actual_entries : " MessageCounter" ,
138
- ) -> Tuple [" MessageCounter" , Dict [Tuple [int , str ], int ]]:
134
+ expected_entries : MessageCounter ,
135
+ actual_entries : MessageCounter ,
136
+ ) -> Tuple [MessageCounter , Dict [Tuple [int , str ], int ]]:
139
137
"""Takes two multisets and compares them.
140
138
141
139
A multiset is a dict with the cardinality of the key as the value."""
@@ -162,7 +160,7 @@ def _open_source_file(self) -> TextIO:
162
160
return open (self ._test_file .source , encoding = "latin1" )
163
161
return open (self ._test_file .source , encoding = "utf8" )
164
162
165
- def _get_expected (self ) -> Tuple [" MessageCounter" , List [OutputLine ]]:
163
+ def _get_expected (self ) -> Tuple [MessageCounter , List [OutputLine ]]:
166
164
with self ._open_source_file () as f :
167
165
expected_msgs = self .get_expected_messages (f )
168
166
if not expected_msgs :
@@ -174,10 +172,10 @@ def _get_expected(self) -> Tuple["MessageCounter", List[OutputLine]]:
174
172
]
175
173
return expected_msgs , expected_output_lines
176
174
177
- def _get_actual (self ) -> Tuple [" MessageCounter" , List [OutputLine ]]:
175
+ def _get_actual (self ) -> Tuple [MessageCounter , List [OutputLine ]]:
178
176
messages : List [Message ] = self ._linter .reporter .messages
179
177
messages .sort (key = lambda m : (m .line , m .symbol , m .msg ))
180
- received_msgs : " MessageCounter" = Counter ()
178
+ received_msgs : MessageCounter = Counter ()
181
179
received_output_lines = []
182
180
for msg in messages :
183
181
assert (
@@ -204,8 +202,8 @@ def _runTest(self) -> None:
204
202
205
203
def error_msg_for_unequal_messages (
206
204
self ,
207
- actual_messages : " MessageCounter" ,
208
- expected_messages : " MessageCounter" ,
205
+ actual_messages : MessageCounter ,
206
+ expected_messages : MessageCounter ,
209
207
actual_output : List [OutputLine ],
210
208
) -> str :
211
209
msg = [f'Wrong results for file "{ self ._test_file .base } ":' ]
@@ -250,7 +248,7 @@ def error_msg_for_unequal_output(
250
248
251
249
def _check_output_text (
252
250
self ,
253
- _ : " MessageCounter" ,
251
+ _ : MessageCounter ,
254
252
expected_output : List [OutputLine ],
255
253
actual_output : List [OutputLine ],
256
254
) -> None :
0 commit comments