2020-10-30 22:15:01 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2021-04-11 13:29:34 +00:00
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE
|
2020-10-30 22:15:01 +00:00
|
|
|
|
|
|
|
from io import StringIO
|
|
|
|
from os import getcwd, linesep, sep
|
2021-06-14 18:27:23 +00:00
|
|
|
from typing import Dict, List
|
2020-10-30 22:15:01 +00:00
|
|
|
|
|
|
|
from pylint import interfaces
|
2021-06-14 18:27:23 +00:00
|
|
|
from pylint.message import Message
|
2020-10-30 22:15:01 +00:00
|
|
|
from pylint.reporters import BaseReporter
|
|
|
|
|
|
|
|
|
2020-11-14 15:03:54 +00:00
|
|
|
class GenericTestReporter(BaseReporter):
|
2020-10-30 22:15:01 +00:00
|
|
|
"""reporter storing plain text messages"""
|
|
|
|
|
|
|
|
__implements__ = interfaces.IReporter
|
|
|
|
|
|
|
|
def __init__(self): # pylint: disable=super-init-not-called
|
|
|
|
self.reset()
|
|
|
|
|
|
|
|
def reset(self):
|
2021-06-14 18:27:23 +00:00
|
|
|
self.message_ids: Dict = {}
|
2020-10-30 22:15:01 +00:00
|
|
|
self.out = StringIO()
|
2021-06-14 18:27:23 +00:00
|
|
|
self.path_strip_prefix: str = getcwd() + sep
|
|
|
|
self.messages: List[str] = []
|
2020-10-30 22:15:01 +00:00
|
|
|
|
2021-06-14 18:27:23 +00:00
|
|
|
def handle_message(self, msg: Message) -> None:
|
2021-04-26 11:59:44 +00:00
|
|
|
"""manage message of different type and in the context of path"""
|
2020-10-30 22:15:01 +00:00
|
|
|
obj = msg.obj
|
|
|
|
line = msg.line
|
|
|
|
msg_id = msg.msg_id
|
2021-06-14 18:27:23 +00:00
|
|
|
str_message: str = msg.msg
|
2020-10-30 22:15:01 +00:00
|
|
|
self.message_ids[msg_id] = 1
|
|
|
|
if obj:
|
|
|
|
obj = ":%s" % obj
|
|
|
|
sigle = msg_id[0]
|
|
|
|
if linesep != "\n":
|
|
|
|
# 2to3 writes os.linesep instead of using
|
|
|
|
# the previously used line separators
|
2021-06-14 18:27:23 +00:00
|
|
|
str_message = str_message.replace("\r\n", "\n")
|
|
|
|
self.messages.append(f"{sigle}:{line:>3}{obj}: {str_message}")
|
2020-10-30 22:15:01 +00:00
|
|
|
|
|
|
|
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): # pylint: disable=abstract-method
|
|
|
|
def on_set_current_module(self, module, filepath):
|
|
|
|
self.messages = []
|
|
|
|
|
|
|
|
def display_reports(self, layout):
|
|
|
|
"""Ignore layouts and don't call self._display()."""
|