diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-11-29 10:31:01 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-11-29 11:59:49 +0100 |
commit | 4ff93428b2370e6829282a9f2f76b2ec1e7d0f1b (patch) | |
tree | f397a8542944507da41f97bb660ffe94b3abbe9e | |
parent | 9446e7dc82ceeb40c1a1b92888a2005d79a159f1 (diff) | |
download | pylint-git-4ff93428b2370e6829282a9f2f76b2ec1e7d0f1b.tar.gz |
Create a file for Message/OutputLine
-rw-r--r-- | pylint/testutils/__init__.py | 2 | ||||
-rw-r--r-- | pylint/testutils/output_line.py | 50 | ||||
-rw-r--r-- | pylint/testutils/utils.py | 48 |
3 files changed, 53 insertions, 47 deletions
diff --git a/pylint/testutils/__init__.py b/pylint/testutils/__init__.py index 348d2bf36..080fd6942 100644 --- a/pylint/testutils/__init__.py +++ b/pylint/testutils/__init__.py @@ -42,13 +42,13 @@ __all__ = [ "UPDATE_OPTION", ] +from pylint.testutils.output_line import Message from pylint.testutils.reporter_for_tests import GenericTestReporter, MinimalTestReporter from pylint.testutils.utils import ( UPDATE_OPTION, CheckerTestCase, FunctionalTestFile, LintModuleTest, - Message, _get_tests_info, _tokenize_str, linter, diff --git a/pylint/testutils/output_line.py b/pylint/testutils/output_line.py new file mode 100644 index 000000000..8bf5b7124 --- /dev/null +++ b/pylint/testutils/output_line.py @@ -0,0 +1,50 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/master/COPYING + +import collections + +from pylint import interfaces + + +class Message( + collections.namedtuple("Message", ["msg_id", "line", "node", "args", "confidence"]) +): + def __new__(cls, msg_id, line=None, node=None, args=None, confidence=None): + return tuple.__new__(cls, (msg_id, line, node, args, confidence)) + + def __eq__(self, other): + if isinstance(other, Message): + if self.confidence and other.confidence: + return super().__eq__(other) + return self[:-1] == other[:-1] + return NotImplemented # pragma: no cover + + __hash__ = None + + +class OutputLine( + collections.namedtuple( + "OutputLine", ["symbol", "lineno", "object", "msg", "confidence"] + ) +): + @classmethod + def from_msg(cls, msg): + return cls( + msg.symbol, + msg.line, + msg.obj or "", + msg.msg.replace("\r\n", "\n"), + msg.confidence.name + if msg.confidence != interfaces.UNDEFINED + else interfaces.HIGH.name, + ) + + @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) + + def to_csv(self): + if self.confidence == interfaces.HIGH.name: + return self[:-1] + return self diff --git a/pylint/testutils/utils.py b/pylint/testutils/utils.py index f1a48c248..964ae9c90 100644 --- a/pylint/testutils/utils.py +++ b/pylint/testutils/utils.py @@ -20,7 +20,7 @@ from typing import Tuple import astroid import pytest -from pylint import checkers, interfaces +from pylint import checkers from pylint.lint import PyLinter from pylint.testutils.constants import ( _EXPECTED_RE, @@ -33,6 +33,7 @@ from pylint.testutils.functional_test_file import ( NoFileError, parse_python_version, ) +from pylint.testutils.output_line import Message, OutputLine from pylint.testutils.reporter_for_tests import ( FunctionalTestReporter, GenericTestReporter, @@ -78,22 +79,6 @@ def _get_tests_info(input_dir, msg_dir, prefix, suffix): return result -class Message( - collections.namedtuple("Message", ["msg_id", "line", "node", "args", "confidence"]) -): - def __new__(cls, msg_id, line=None, node=None, args=None, confidence=None): - return tuple.__new__(cls, (msg_id, line, node, args, confidence)) - - def __eq__(self, other): - if isinstance(other, Message): - if self.confidence and other.confidence: - return super().__eq__(other) - return self[:-1] == other[:-1] - return NotImplemented # pragma: no cover - - __hash__ = None - - class UnittestLinter: """A fake linter class to capture checker messages.""" @@ -231,35 +216,6 @@ def _create_file_backed_module(code): yield module -class OutputLine( - collections.namedtuple( - "OutputLine", ["symbol", "lineno", "object", "msg", "confidence"] - ) -): - @classmethod - def from_msg(cls, msg): - return cls( - msg.symbol, - msg.line, - msg.obj or "", - msg.msg.replace("\r\n", "\n"), - msg.confidence.name - if msg.confidence != interfaces.UNDEFINED - else interfaces.HIGH.name, - ) - - @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) - - def to_csv(self): - if self.confidence == interfaces.HIGH.name: - return self[:-1] - - return self - - def parse_expected_output(stream): return [OutputLine.from_csv(row) for row in csv.reader(stream, "test")] |