Skip to content

Commit 7b7cc54

Browse files
authored
Make sure to split non-separated csv OuputLine's (pylint-dev#5665)
* Make sure to split non-separated csv ``OuputLine's`` * Add test for too long output lines
1 parent 642268f commit 7b7cc54

File tree

2 files changed

+54
-42
lines changed

2 files changed

+54
-42
lines changed

pylint/testutils/output_line.py

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -117,49 +117,50 @@ def from_csv(
117117
"""Create an OutputLine from a comma separated list (the functional tests expected
118118
output .txt files).
119119
"""
120+
if isinstance(row, str):
121+
row = row.split(",")
120122
try:
121-
if isinstance(row, Sequence):
122-
column = cls._get_column(row[2])
123-
if len(row) == 5:
124-
warnings.warn(
125-
"In pylint 3.0 functional tests expected output should always include the "
126-
"expected confidence level, expected end_line and expected end_column. "
127-
"An OutputLine should thus have a length of 8.",
128-
DeprecationWarning,
129-
)
130-
return cls(
131-
row[0],
132-
int(row[1]),
133-
column,
134-
None,
135-
None,
136-
row[3],
137-
row[4],
138-
UNDEFINED.name,
139-
)
140-
if len(row) == 6:
141-
warnings.warn(
142-
"In pylint 3.0 functional tests expected output should always include the "
143-
"expected end_line and expected end_column. An OutputLine should thus have "
144-
"a length of 8.",
145-
DeprecationWarning,
146-
)
147-
return cls(
148-
row[0], int(row[1]), column, None, None, row[3], row[4], row[5]
149-
)
150-
if len(row) == 8:
151-
end_line = cls._get_py38_none_value(row[3], check_endline)
152-
end_column = cls._get_py38_none_value(row[4], check_endline)
153-
return cls(
154-
row[0],
155-
int(row[1]),
156-
column,
157-
cls._value_to_optional_int(end_line),
158-
cls._value_to_optional_int(end_column),
159-
row[5],
160-
row[6],
161-
row[7],
162-
)
123+
column = cls._get_column(row[2])
124+
if len(row) == 5:
125+
warnings.warn(
126+
"In pylint 3.0 functional tests expected output should always include the "
127+
"expected confidence level, expected end_line and expected end_column. "
128+
"An OutputLine should thus have a length of 8.",
129+
DeprecationWarning,
130+
)
131+
return cls(
132+
row[0],
133+
int(row[1]),
134+
column,
135+
None,
136+
None,
137+
row[3],
138+
row[4],
139+
UNDEFINED.name,
140+
)
141+
if len(row) == 6:
142+
warnings.warn(
143+
"In pylint 3.0 functional tests expected output should always include the "
144+
"expected end_line and expected end_column. An OutputLine should thus have "
145+
"a length of 8.",
146+
DeprecationWarning,
147+
)
148+
return cls(
149+
row[0], int(row[1]), column, None, None, row[3], row[4], row[5]
150+
)
151+
if len(row) == 8:
152+
end_line = cls._get_py38_none_value(row[3], check_endline)
153+
end_column = cls._get_py38_none_value(row[4], check_endline)
154+
return cls(
155+
row[0],
156+
int(row[1]),
157+
column,
158+
cls._value_to_optional_int(end_line),
159+
cls._value_to_optional_int(end_column),
160+
row[5],
161+
row[6],
162+
row[7],
163+
)
163164
raise IndexError
164165
except Exception as e:
165166
raise MalformedOutputLineException(row, e) from e

tests/testutils/test_output_line.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,27 @@ def test_output_line_to_csv(confidence: Confidence, message: Callable) -> None:
123123

124124
def test_output_line_from_csv_error() -> None:
125125
"""Test that errors are correctly raised for incorrect OutputLine's."""
126+
# Test a csv-string which does not have a number for line and column
126127
with pytest.raises(
127128
MalformedOutputLineException,
128129
match="msg-symbolic-name:42:27:MyClass.my_function:The message",
129130
):
130131
OutputLine.from_csv("'missing-docstring', 'line', 'column', 'obj', 'msg'", True)
132+
# Test a tuple which does not have a number for line and column
131133
with pytest.raises(
132134
MalformedOutputLineException, match="symbol='missing-docstring' ?"
133135
):
134136
csv = ("missing-docstring", "line", "column", "obj", "msg")
135137
OutputLine.from_csv(csv, True)
138+
# Test a csv-string that is too long
139+
with pytest.raises(
140+
MalformedOutputLineException,
141+
match="msg-symbolic-name:42:27:MyClass.my_function:The message",
142+
):
143+
OutputLine.from_csv(
144+
"'missing-docstring', 1, 2, 'obj', 'msg', 'func', 'message', 'conf', 'too_long'",
145+
True,
146+
)
136147

137148

138149
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)