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 :
@@ -96,15 +94,15 @@ def __str__(self) -> str:
96
94
return f"{ self ._test_file .base } ({ self .__class__ .__module__ } .{ self .__class__ .__name__ } )"
97
95
98
96
@staticmethod
99
- def get_expected_messages (stream : TextIO ) -> " MessageCounter" :
97
+ def get_expected_messages (stream : TextIO ) -> MessageCounter :
100
98
"""Parses a file and get expected messages.
101
99
102
100
:param stream: File-like input stream.
103
101
:type stream: enumerable
104
102
:returns: A dict mapping line,msg-symbol tuples to the count on this line.
105
103
:rtype: dict
106
104
"""
107
- messages : " MessageCounter" = Counter ()
105
+ messages : MessageCounter = Counter ()
108
106
for i , line in enumerate (stream ):
109
107
match = _EXPECTED_RE .search (line )
110
108
if match is None :
@@ -130,9 +128,9 @@ def get_expected_messages(stream: TextIO) -> "MessageCounter":
130
128
131
129
@staticmethod
132
130
def multiset_difference (
133
- expected_entries : " MessageCounter" ,
134
- actual_entries : " MessageCounter" ,
135
- ) -> Tuple [" MessageCounter" , Dict [Tuple [int , str ], int ]]:
131
+ expected_entries : MessageCounter ,
132
+ actual_entries : MessageCounter ,
133
+ ) -> Tuple [MessageCounter , Dict [Tuple [int , str ], int ]]:
136
134
"""Takes two multisets and compares them.
137
135
138
136
A multiset is a dict with the cardinality of the key as the value."""
@@ -161,7 +159,7 @@ def _open_source_file(self) -> TextIO:
161
159
return open (self ._test_file .source , encoding = "latin1" )
162
160
return open (self ._test_file .source , encoding = "utf8" )
163
161
164
- def _get_expected (self ) -> Tuple [" MessageCounter" , List [OutputLine ]]:
162
+ def _get_expected (self ) -> Tuple [MessageCounter , List [OutputLine ]]:
165
163
with self ._open_source_file () as f :
166
164
expected_msgs = self .get_expected_messages (f )
167
165
if not expected_msgs :
@@ -172,10 +170,10 @@ def _get_expected(self) -> Tuple["MessageCounter", List[OutputLine]]:
172
170
]
173
171
return expected_msgs , expected_output_lines
174
172
175
- def _get_actual (self ) -> Tuple [" MessageCounter" , List [OutputLine ]]:
173
+ def _get_actual (self ) -> Tuple [MessageCounter , List [OutputLine ]]:
176
174
messages : List [Message ] = self ._linter .reporter .messages
177
175
messages .sort (key = lambda m : (m .line , m .symbol , m .msg ))
178
- received_msgs : " MessageCounter" = Counter ()
176
+ received_msgs : MessageCounter = Counter ()
179
177
received_output_lines = []
180
178
for msg in messages :
181
179
assert (
@@ -200,8 +198,8 @@ def _runTest(self) -> None:
200
198
201
199
def error_msg_for_unequal_messages (
202
200
self ,
203
- actual_messages : " MessageCounter" ,
204
- expected_messages : " MessageCounter" ,
201
+ actual_messages : MessageCounter ,
202
+ expected_messages : MessageCounter ,
205
203
actual_output : List [OutputLine ],
206
204
) -> str :
207
205
msg = [f'Wrong results for file "{ self ._test_file .base } ":' ]
@@ -246,7 +244,7 @@ def error_msg_for_unequal_output(
246
244
247
245
def _check_output_text (
248
246
self ,
249
- _ : " MessageCounter" ,
247
+ _ : MessageCounter ,
250
248
expected_output : List [OutputLine ],
251
249
actual_output : List [OutputLine ],
252
250
) -> None :
0 commit comments