1
1
# SPDX-FileCopyrightText: David Fritzsche
2
2
# SPDX-License-Identifier: CC0-1.0
3
3
4
+ from typing import Optional
5
+
4
6
import pytest
5
7
6
8
from pytest_mypy_testing .message import Message , Severity
@@ -14,26 +16,35 @@ def test_init_severity(string: str, expected: Severity):
14
16
15
17
16
18
@pytest .mark .parametrize (
17
- "filename,comment,severity,message" ,
19
+ "filename,comment,severity,message,error_code " ,
18
20
[
19
- ("z.py" , "# E: bar" , Severity .ERROR , "bar" ),
20
- ("z.py" , "#type:ignore# W: bar" , Severity .WARNING , "bar" ),
21
- ("z.py" , "# type: ignore # W: bar" , Severity .WARNING , "bar" ),
22
- ("z.py" , "# R: bar" , Severity .NOTE , "Revealed type is 'bar'" ),
21
+ ("z.py" , "# E: bar" , Severity .ERROR , "bar" , None ),
22
+ ("z.py" , "# E: bar" , Severity .ERROR , "bar" , "foo" ),
23
+ ("z.py" , "# E: bar [foo]" , Severity .ERROR , "bar" , "foo" ),
24
+ ("z.py" , "# E: bar [foo]" , Severity .ERROR , "bar" , "" ),
25
+ ("z.py" , "#type:ignore# W: bar" , Severity .WARNING , "bar" , None ),
26
+ ("z.py" , "# type: ignore # W: bar" , Severity .WARNING , "bar" , None ),
27
+ ("z.py" , "# R: bar" , Severity .NOTE , "Revealed type is 'bar'" , None ),
23
28
],
24
29
)
25
30
def test_message_from_comment (
26
- filename : str , comment : str , severity : Severity , message : str
31
+ filename : str ,
32
+ comment : str ,
33
+ severity : Severity ,
34
+ message : str ,
35
+ error_code : Optional [str ],
27
36
):
28
37
lineno = 123
38
+ actual = Message .from_comment (filename , lineno , comment )
29
39
expected = Message (
30
40
filename = filename ,
31
41
lineno = lineno ,
32
42
colno = None ,
33
43
severity = severity ,
34
44
message = message ,
45
+ error_code = error_code ,
35
46
)
36
- assert Message . from_comment ( filename , lineno , comment ) == expected
47
+ assert actual == expected
37
48
38
49
39
50
def test_message_from_invalid_comment ():
0 commit comments