third_party.pylibs.pylint.src/pylint/testutils/reporter_for_tests.py
Daniël van Noord baaa81a299
Refactor various typing related issues (#4940)
* Add type annotations to ``visit`` & ``leave`` calls
This adds typing to most calls that visit nodes. All other changes are
due to mypy errors resulting from introduction of typing.

* Fix outstanding mypy issues
This removes some of the `type: ignore` comments in favour of
solving the mypy issues these comments were surpressing.

* Fix remaining references to node_classes
Except for two references to node_classes in the changelog this should be the last of them

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
2021-09-03 13:47:23 +02:00

81 lines
2.2 KiB
Python

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
from io import StringIO
from os import getcwd, linesep, sep
from typing import Dict, List
from pylint import interfaces
from pylint.message import Message
from pylint.reporters import BaseReporter
class GenericTestReporter(BaseReporter):
"""reporter storing plain text messages"""
__implements__ = interfaces.IReporter
def __init__(
self,
): # pylint: disable=super-init-not-called # See https://github.com/PyCQA/pylint/issues/4941
self.reset()
def reset(self):
self.message_ids: Dict = {}
self.out = StringIO()
self.path_strip_prefix: str = getcwd() + sep
self.messages: List[str] = []
def handle_message(self, msg: Message) -> None:
"""manage message of different type and in the context of path"""
obj = msg.obj
line = msg.line
msg_id = msg.msg_id
str_message: str = msg.msg
self.message_ids[msg_id] = 1
if obj:
obj = f":{obj}"
sigle = msg_id[0]
if linesep != "\n":
# 2to3 writes os.linesep instead of using
# the previously used line separators
str_message = str_message.replace("\r\n", "\n")
self.messages.append(f"{sigle}:{line:>3}{obj}: {str_message}")
def finalize(self):
self.messages.sort()
for msg in self.messages:
print(msg, file=self.out)
result = self.out.getvalue()
self.reset()
return result
# pylint: disable=unused-argument
def on_set_current_module(self, module, filepath):
pass
# pylint: enable=unused-argument
def display_reports(self, layout):
"""ignore layouts"""
_display = None
class MinimalTestReporter(BaseReporter):
def on_set_current_module(self, module, filepath):
self.messages = []
_display = None
class FunctionalTestReporter(BaseReporter):
def on_set_current_module(self, module, filepath):
self.messages = []
def display_reports(self, layout):
"""Ignore layouts and don't call self._display()."""
def _display(self, layout):
pass