Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes functional tests auto-update works even if the current output is wrong #6891

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/whatsnew/2/2.15/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ Internal changes
* ``pylint.testutils.primer`` is now a private API.

Refs #6905

* Fixed an issue where it was impossible to update functional tests output when the existing
output was impossible to parse. Instead of raising an error we raise a warning message and
let the functional test fail with a default value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

This is the PR right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no issue.

Refs #6891
49 changes: 9 additions & 40 deletions pylint/testutils/output_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,6 @@ class MessageTest(NamedTuple):
"""


class MalformedOutputLineException(Exception):
def __init__(
self,
row: Sequence[str] | str,
exception: Exception,
) -> None:
example = "msg-symbolic-name:42:27:MyClass.my_function:The message"
other_example = "msg-symbolic-name:7:42::The message"
expected = [
"symbol",
"line",
"column",
"end_line",
"end_column",
"MyClass.myFunction, (or '')",
"Message",
"confidence",
]
reconstructed_row = ""
i = 0
try:
for i, column in enumerate(row):
reconstructed_row += f"\t{expected[i]}='{column}' ?\n"
for missing in expected[i + 1 :]:
reconstructed_row += f"\t{missing}= Nothing provided !\n"
except IndexError:
pass
raw = ":".join(row)
msg = f"""\
{exception}

Expected '{example}' or '{other_example}' but we got '{raw}':
{reconstructed_row}

Try updating it with: 'python tests/test_functional.py {UPDATE_OPTION}'"""
super().__init__(msg)


class OutputLine(NamedTuple):
symbol: str
lineno: int
Expand Down Expand Up @@ -127,6 +89,7 @@ def from_csv(
"""
if isinstance(row, str):
row = row.split(",")
# noinspection PyBroadException
try:
column = cls._get_column(row[2])
if len(row) == 5:
Expand Down Expand Up @@ -170,8 +133,14 @@ def from_csv(
row[7],
)
raise IndexError
except Exception as e:
raise MalformedOutputLineException(row, e) from e
except Exception: # pylint: disable=broad-except
warnings.warn(
"Expected 'msg-symbolic-name:42:27:MyClass.my_function:The message:"
f"CONFIDENCE' but we got '{':'.join(row)}'. Try updating the expected"
f" output with:\npython tests/test_functional.py {UPDATE_OPTION}",
UserWarning,
)
return cls("", 0, 0, None, None, "", "", "")

def to_csv(self) -> tuple[str, str, str, str, str, str, str, str]:
"""Convert an OutputLine to a tuple of string to be written by a
Expand Down
14 changes: 7 additions & 7 deletions tests/testutils/test_output_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pylint.constants import PY38_PLUS
from pylint.interfaces import HIGH, INFERENCE, Confidence
from pylint.message import Message
from pylint.testutils.output_line import MalformedOutputLineException, OutputLine
from pylint.testutils.output_line import OutputLine
from pylint.typing import MessageLocationTuple


Expand Down Expand Up @@ -127,20 +127,20 @@ def test_output_line_to_csv(confidence: Confidence, message: Callable) -> None:
def test_output_line_from_csv_error() -> None:
"""Test that errors are correctly raised for incorrect OutputLine's."""
# Test a csv-string which does not have a number for line and column
with pytest.raises(
MalformedOutputLineException,
with pytest.warns(
UserWarning,
match="msg-symbolic-name:42:27:MyClass.my_function:The message",
):
OutputLine.from_csv("'missing-docstring', 'line', 'column', 'obj', 'msg'", True)
# Test a tuple which does not have a number for line and column
with pytest.raises(
MalformedOutputLineException, match="symbol='missing-docstring' ?"
with pytest.warns(
UserWarning, match="we got 'missing-docstring:line:column:obj:msg'"
):
csv = ("missing-docstring", "line", "column", "obj", "msg")
OutputLine.from_csv(csv, True)
# Test a csv-string that is too long
with pytest.raises(
MalformedOutputLineException,
with pytest.warns(
UserWarning,
match="msg-symbolic-name:42:27:MyClass.my_function:The message",
):
OutputLine.from_csv(
Expand Down