diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-11-29 15:20:20 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-11-29 16:16:08 +0100 |
commit | b1f2204b178c9193455731e8a229c3af57128145 (patch) | |
tree | a651e4b9a52758f5973f99d6b97e9d7f23f12b03 | |
parent | a6ccd38a36dafca7d0ea48cbe9d9c35d0c4dad43 (diff) | |
download | pylint-git-b1f2204b178c9193455731e8a229c3af57128145.tar.gz |
Add an exception for malformed expected output in functional tests
-rw-r--r-- | pylint/testutils/output_line.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/pylint/testutils/output_line.py b/pylint/testutils/output_line.py index 8bf5b7124..17507e2d3 100644 --- a/pylint/testutils/output_line.py +++ b/pylint/testutils/output_line.py @@ -22,6 +22,21 @@ class Message( __hash__ = None +class MalformedOutputLineException(Exception): + def __init__(self, row, exception): + example = "msg-symbolic-name:42:MyClass.my_function:The message" + other_example = "msg-symbolic-name:7::The message" + reconstructed_row = ":".join(row) + msg = "Expected '{example}' or '{other_example}' but we got '{reconstructed_row}'".format( + example=example, + other_example=other_example, + reconstructed_row=reconstructed_row, + ) + Exception.__init__( + self, "{msg}: {exception}".format(msg=msg, exception=exception) + ) + + class OutputLine( collections.namedtuple( "OutputLine", ["symbol", "lineno", "object", "msg", "confidence"] @@ -41,8 +56,11 @@ class OutputLine( @classmethod def from_csv(cls, row): - confidence = row[4] if len(row) == 5 else interfaces.HIGH.name - return cls(row[0], int(row[1]), row[2], row[3], confidence) + try: + confidence = row[4] if len(row) == 5 else interfaces.HIGH.name + return cls(row[0], int(row[1]), row[2], row[3], confidence) + except Exception as e: + raise MalformedOutputLineException(row, e) from e def to_csv(self): if self.confidence == interfaces.HIGH.name: |