1
1
import collections
2
2
import os
3
3
import subprocess
4
+ import sys
4
5
from pathlib import Path
5
6
from typing import Dict
6
7
from unittest .mock import Mock
16
17
DOC_URI = f"file:/{ Path (__file__ )} "
17
18
DOC_TYPE_ERR = """{}.append(3)
18
19
"""
19
- TYPE_ERR_MSG = '"Dict[<nothing>, <nothing>]" has no attribute "append" [attr-defined] '
20
+ TYPE_ERR_MSG = '"Dict[<nothing>, <nothing>]" has no attribute "append"'
20
21
21
- TEST_LINE = 'test_plugin.py:279:8:279:19: error: "Request" has no attribute "id"'
22
- TEST_LINE_WITHOUT_END = 'test_plugin.py:279:8: error: "Request" has no attribute "id"'
23
- TEST_LINE_WITHOUT_COL = "test_plugin.py:279: " 'error: "Request" has no attribute "id"'
24
- TEST_LINE_WITHOUT_LINE = "test_plugin.py: " 'error: "Request" has no attribute "id"'
22
+ TEST_LINE = 'test_plugin.py:279:8:279:16: error: "Request" has no attribute "id" [attr-defined]'
25
23
26
24
windows_flag : Dict [str , int ] = (
27
25
{"creationflags" : subprocess .CREATE_NO_WINDOW } if os .name == "nt" else {} # type: ignore
@@ -66,48 +64,22 @@ def test_plugin(workspace, last_diagnostics_monkeypatch):
66
64
diag = diags [0 ]
67
65
assert diag ["message" ] == TYPE_ERR_MSG
68
66
assert diag ["range" ]["start" ] == {"line" : 0 , "character" : 0 }
69
- assert diag ["range" ]["end" ] == {"line" : 0 , "character" : 9 }
67
+ # Running mypy in 3.7 produces wrong error ends this can be removed when 3.7 reaches EOL
68
+ if sys .version_info < (3 , 8 ):
69
+ assert diag ["range" ]["end" ] == {"line" : 0 , "character" : 1 }
70
+ else :
71
+ assert diag ["range" ]["end" ] == {"line" : 0 , "character" : 9 }
72
+ assert diag ["severity" ] == 1
73
+ assert diag ["code" ] == "attr-defined"
70
74
71
75
72
76
def test_parse_full_line (workspace ):
73
77
diag = plugin .parse_line (TEST_LINE ) # TODO parse a document here
74
78
assert diag ["message" ] == '"Request" has no attribute "id"'
75
79
assert diag ["range" ]["start" ] == {"line" : 278 , "character" : 7 }
76
- assert diag ["range" ]["end" ] == {"line" : 278 , "character" : 19 }
77
-
78
-
79
- def test_parse_line_without_end (workspace ):
80
- doc = Document (DOC_URI , workspace )
81
- diag = plugin .parse_line (TEST_LINE_WITHOUT_END , doc )
82
- assert diag ["message" ] == '"Request" has no attribute "id"'
83
- assert diag ["range" ]["start" ] == {"line" : 278 , "character" : 7 }
84
- assert diag ["range" ]["end" ] == {"line" : 278 , "character" : 13 }
85
-
86
-
87
- def test_parse_line_without_col (workspace ):
88
- doc = Document (DOC_URI , workspace )
89
- diag = plugin .parse_line (TEST_LINE_WITHOUT_COL , doc )
90
- assert diag ["message" ] == '"Request" has no attribute "id"'
91
- assert diag ["range" ]["start" ] == {"line" : 278 , "character" : 0 }
92
- assert diag ["range" ]["end" ] == {"line" : 278 , "character" : 1 }
93
-
94
-
95
- def test_parse_line_without_line (workspace ):
96
- doc = Document (DOC_URI , workspace )
97
- diag = plugin .parse_line (TEST_LINE_WITHOUT_LINE , doc )
98
- assert diag ["message" ] == '"Request" has no attribute "id"'
99
- assert diag ["range" ]["start" ] == {"line" : 0 , "character" : 0 }
100
- assert diag ["range" ]["end" ] == {"line" : 0 , "character" : 6 }
101
-
102
-
103
- @pytest .mark .parametrize ("word,bounds" , [("" , (7 , 8 )), ("my_var" , (7 , 13 ))])
104
- def test_parse_line_with_context (monkeypatch , word , bounds , workspace ):
105
- doc = Document (DOC_URI , workspace )
106
- monkeypatch .setattr (Document , "word_at_position" , lambda * args : word )
107
- diag = plugin .parse_line (TEST_LINE_WITHOUT_END , doc )
108
- assert diag ["message" ] == '"Request" has no attribute "id"'
109
- assert diag ["range" ]["start" ] == {"line" : 278 , "character" : bounds [0 ]}
110
- assert diag ["range" ]["end" ] == {"line" : 278 , "character" : bounds [1 ]}
80
+ assert diag ["range" ]["end" ] == {"line" : 278 , "character" : 16 }
81
+ assert diag ["severity" ] == 1
82
+ assert diag ["code" ] == "attr-defined"
111
83
112
84
113
85
def test_multiple_workspaces (tmpdir , last_diagnostics_monkeypatch ):
@@ -116,7 +88,7 @@ def foo():
116
88
return
117
89
unreachable = 1
118
90
"""
119
- DOC_ERR_MSG = "Statement is unreachable [unreachable] "
91
+ DOC_ERR_MSG = "Statement is unreachable"
120
92
121
93
# Initialize two workspace folders.
122
94
folder1 = tmpdir .mkdir ("folder1" )
@@ -141,6 +113,7 @@ def foo():
141
113
assert len (diags ) == 1
142
114
diag = diags [0 ]
143
115
assert diag ["message" ] == DOC_ERR_MSG
116
+ assert diag ["code" ] == "unreachable"
144
117
145
118
# Test document in workspace 2 (without mypy.ini configuration)
146
119
doc2 = Document (DOC_URI , ws2 , DOC_SOURCE )
@@ -236,6 +209,7 @@ def test_option_overrides_dmypy(last_diagnostics_monkeypatch, workspace):
236
209
"--python-executable" ,
237
210
"/tmp/fake" ,
238
211
"--show-error-end" ,
212
+ "--no-error-summary" ,
239
213
document .path ,
240
214
]
241
215
m .assert_called_with (expected , capture_output = True , ** windows_flag , encoding = "utf-8" )
@@ -279,7 +253,7 @@ def foo():
279
253
return
280
254
unreachable = 1
281
255
"""
282
- DOC_ERR_MSG = "Statement is unreachable [unreachable] "
256
+ DOC_ERR_MSG = "Statement is unreachable"
283
257
284
258
config_sub_paths = [".config" ]
285
259
@@ -305,6 +279,7 @@ def foo():
305
279
assert len (diags ) == 1
306
280
diag = diags [0 ]
307
281
assert diag ["message" ] == DOC_ERR_MSG
282
+ assert diag ["code" ] == "unreachable"
308
283
309
284
310
285
def test_config_sub_paths_config_changed (tmpdir , last_diagnostics_monkeypatch ):
@@ -313,7 +288,7 @@ def foo():
313
288
return
314
289
unreachable = 1
315
290
"""
316
- DOC_ERR_MSG = "Statement is unreachable [unreachable] "
291
+ DOC_ERR_MSG = "Statement is unreachable"
317
292
318
293
# Create configuration file for workspace.
319
294
config_dir = tmpdir .mkdir (".config" )
@@ -336,3 +311,4 @@ def foo():
336
311
assert len (diags ) == 1
337
312
diag = diags [0 ]
338
313
assert diag ["message" ] == DOC_ERR_MSG
314
+ assert diag ["code" ] == "unreachable"
0 commit comments