@@ -55,35 +55,66 @@ def test_output_line() -> None:
55
55
def test_output_line_from_message (message : Callable ) -> None :
56
56
"""Test that the OutputLine NamedTuple is instantiated correctly with from_msg."""
57
57
expected_column = 2 if PY38_PLUS else 0
58
- expected_end_lineno = 1 if PY38_PLUS else None
59
- expected_end_column = 3 if PY38_PLUS else None
58
+
60
59
output_line = OutputLine .from_msg (message ())
61
60
assert output_line .symbol == "missing-docstring"
62
61
assert output_line .lineno == 1
63
62
assert output_line .column == expected_column
64
- assert output_line .end_lineno == expected_end_lineno
65
- assert output_line .end_column == expected_end_column
63
+ assert output_line .end_lineno == 1
64
+ assert output_line .end_column == 3
66
65
assert output_line .object == "obj"
67
66
assert output_line .msg == "msg"
68
67
assert output_line .confidence == "HIGH"
69
68
69
+ output_line_with_end = OutputLine .from_msg (message (), True )
70
+ assert output_line_with_end .symbol == "missing-docstring"
71
+ assert output_line_with_end .lineno == 1
72
+ assert output_line_with_end .column == expected_column
73
+ assert output_line_with_end .end_lineno == 1
74
+ assert output_line_with_end .end_column == 3
75
+ assert output_line_with_end .object == "obj"
76
+ assert output_line_with_end .msg == "msg"
77
+ assert output_line_with_end .confidence == "HIGH"
78
+
79
+ output_line_without_end = OutputLine .from_msg (message (), False )
80
+ assert output_line_without_end .symbol == "missing-docstring"
81
+ assert output_line_without_end .lineno == 1
82
+ assert output_line_without_end .column == expected_column
83
+ assert output_line_without_end .end_lineno is None
84
+ assert output_line_without_end .end_column is None
85
+ assert output_line_without_end .object == "obj"
86
+ assert output_line_without_end .msg == "msg"
87
+ assert output_line_without_end .confidence == "HIGH"
88
+
70
89
71
90
@pytest .mark .parametrize ("confidence" , [HIGH , INFERENCE ])
72
91
def test_output_line_to_csv (confidence : Confidence , message : Callable ) -> None :
73
92
"""Test that the OutputLine NamedTuple is instantiated correctly with from_msg
74
93
and then converted to csv.
75
94
"""
76
- output_line = OutputLine .from_msg (message (confidence ))
95
+ output_line = OutputLine .from_msg (message (confidence ), True )
77
96
csv = output_line .to_csv ()
78
97
expected_column = "2" if PY38_PLUS else "0"
79
- expected_end_lineno = "1" if PY38_PLUS else "None"
80
- expected_end_column = "3" if PY38_PLUS else "None"
81
98
assert csv == (
82
99
"missing-docstring" ,
83
100
"1" ,
84
101
expected_column ,
85
- expected_end_lineno ,
86
- expected_end_column ,
102
+ "1" ,
103
+ "3" ,
104
+ "obj" ,
105
+ "msg" ,
106
+ confidence .name ,
107
+ )
108
+
109
+ output_line_without_end = OutputLine .from_msg (message (confidence ), False )
110
+ csv = output_line_without_end .to_csv ()
111
+ expected_column = "2" if PY38_PLUS else "0"
112
+ assert csv == (
113
+ "missing-docstring" ,
114
+ "1" ,
115
+ expected_column ,
116
+ "None" ,
117
+ "None" ,
87
118
"obj" ,
88
119
"msg" ,
89
120
confidence .name ,
@@ -96,12 +127,12 @@ def test_output_line_from_csv_error() -> None:
96
127
MalformedOutputLineException ,
97
128
match = "msg-symbolic-name:42:27:MyClass.my_function:The message" ,
98
129
):
99
- OutputLine .from_csv ("'missing-docstring', 'line', 'column', 'obj', 'msg'" )
130
+ OutputLine .from_csv ("'missing-docstring', 'line', 'column', 'obj', 'msg'" , True )
100
131
with pytest .raises (
101
132
MalformedOutputLineException , match = "symbol='missing-docstring' ?"
102
133
):
103
134
csv = ("missing-docstring" , "line" , "column" , "obj" , "msg" )
104
- OutputLine .from_csv (csv )
135
+ OutputLine .from_csv (csv , True )
105
136
106
137
107
138
@pytest .mark .parametrize (
@@ -125,7 +156,7 @@ def test_output_line_from_csv_deprecated(
125
156
else :
126
157
proper_csv = ["missing-docstring" , "1" , "2" , "obj" , "msg" ]
127
158
with pytest .warns (DeprecationWarning ) as records :
128
- output_line = OutputLine .from_csv (proper_csv )
159
+ output_line = OutputLine .from_csv (proper_csv , True )
129
160
assert len (records ) == 1
130
161
131
162
expected_column = 2 if PY38_PLUS else 0
@@ -155,14 +186,36 @@ def test_output_line_from_csv() -> None:
155
186
"msg" ,
156
187
"HIGH" ,
157
188
]
158
- output_line = OutputLine .from_csv (proper_csv )
159
189
expected_column = 2 if PY38_PLUS else 0
160
- expected_end_lineno = 1 if PY38_PLUS else None
190
+
191
+ output_line = OutputLine .from_csv (proper_csv )
161
192
assert output_line == OutputLine (
162
193
symbol = "missing-docstring" ,
163
194
lineno = 1 ,
164
195
column = expected_column ,
165
- end_lineno = expected_end_lineno ,
196
+ end_lineno = 1 ,
197
+ end_column = None ,
198
+ object = "obj" ,
199
+ msg = "msg" ,
200
+ confidence = "HIGH" ,
201
+ )
202
+ output_line_with_end = OutputLine .from_csv (proper_csv , True )
203
+ assert output_line_with_end == OutputLine (
204
+ symbol = "missing-docstring" ,
205
+ lineno = 1 ,
206
+ column = expected_column ,
207
+ end_lineno = 1 ,
208
+ end_column = None ,
209
+ object = "obj" ,
210
+ msg = "msg" ,
211
+ confidence = "HIGH" ,
212
+ )
213
+ output_line_without_end = OutputLine .from_csv (proper_csv , False )
214
+ assert output_line_without_end == OutputLine (
215
+ symbol = "missing-docstring" ,
216
+ lineno = 1 ,
217
+ column = expected_column ,
218
+ end_lineno = None ,
166
219
end_column = None ,
167
220
object = "obj" ,
168
221
msg = "msg" ,
0 commit comments