2020-10-30 22:15:01 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2021-07-01 10:47:58 +00:00
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
|
2022-03-01 15:04:49 +00:00
|
|
|
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
|
2020-10-30 22:15:01 +00:00
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-10-30 22:15:01 +00:00
|
|
|
from io import StringIO
|
2021-10-02 21:13:23 +00:00
|
|
|
from os import getcwd, sep
|
2022-04-14 07:47:58 +00:00
|
|
|
from typing import TYPE_CHECKING
|
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
|
|
|
|
|
2021-09-16 20:12:19 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from pylint.reporters.ureports.nodes import Section
|
|
|
|
|
2020-10-30 22:15:01 +00:00
|
|
|
|
2020-11-14 15:03:54 +00:00
|
|
|
class GenericTestReporter(BaseReporter):
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Reporter storing plain text messages."""
|
2020-10-30 22:15:01 +00:00
|
|
|
|
|
|
|
__implements__ = interfaces.IReporter
|
2021-10-02 21:13:23 +00:00
|
|
|
out: StringIO
|
2020-10-30 22:15:01 +00:00
|
|
|
|
2021-10-02 21:13:23 +00:00
|
|
|
def __init__( # pylint: disable=super-init-not-called # See https://github.com/PyCQA/pylint/issues/4941
|
2021-09-03 11:47:23 +00:00
|
|
|
self,
|
2021-10-02 21:13:23 +00:00
|
|
|
) -> None:
|
|
|
|
self.path_strip_prefix: str = getcwd() + sep
|
2020-10-30 22:15:01 +00:00
|
|
|
self.reset()
|
|
|
|
|
2021-10-02 21:13:23 +00:00
|
|
|
def reset(self) -> None:
|
2020-10-30 22:15:01 +00:00
|
|
|
self.out = StringIO()
|
2022-04-14 07:47:58 +00:00
|
|
|
self.messages: list[Message] = []
|
2020-10-30 22:15:01 +00:00
|
|
|
|
2021-06-14 18:27:23 +00:00
|
|
|
def handle_message(self, msg: Message) -> None:
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Append messages to the list of messages of the reporter."""
|
2021-10-02 21:13:23 +00:00
|
|
|
self.messages.append(msg)
|
|
|
|
|
|
|
|
def finalize(self) -> str:
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Format and print messages in the context of the path."""
|
2022-04-14 07:47:58 +00:00
|
|
|
messages: list[str] = []
|
2020-10-30 22:15:01 +00:00
|
|
|
for msg in self.messages:
|
2021-10-02 21:13:23 +00:00
|
|
|
obj = ""
|
|
|
|
if msg.obj:
|
|
|
|
obj = f":{msg.obj}"
|
|
|
|
messages.append(f"{msg.msg_id[0]}:{msg.line:>3}{obj}: {msg.msg}")
|
|
|
|
|
|
|
|
messages.sort()
|
|
|
|
for message in messages:
|
|
|
|
print(message, file=self.out)
|
|
|
|
|
2020-10-30 22:15:01 +00:00
|
|
|
result = self.out.getvalue()
|
|
|
|
self.reset()
|
|
|
|
return result
|
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
def on_set_current_module(self, module: str, filepath: str | None) -> None:
|
2020-10-30 22:15:01 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
# pylint: enable=unused-argument
|
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
def display_reports(self, layout: Section) -> None:
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Ignore layouts."""
|
2020-10-30 22:15:01 +00:00
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
def _display(self, layout: Section) -> None:
|
2021-09-16 20:12:19 +00:00
|
|
|
pass
|
2020-10-30 22:15:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MinimalTestReporter(BaseReporter):
|
2022-04-14 07:47:58 +00:00
|
|
|
def on_set_current_module(self, module: str, filepath: str | None) -> None:
|
2020-10-30 22:15:01 +00:00
|
|
|
self.messages = []
|
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
def _display(self, layout: Section) -> None:
|
2021-09-16 20:12:19 +00:00
|
|
|
pass
|
2020-10-30 22:15:01 +00:00
|
|
|
|
|
|
|
|
2021-07-06 05:33:06 +00:00
|
|
|
class FunctionalTestReporter(BaseReporter):
|
2022-04-14 07:47:58 +00:00
|
|
|
def on_set_current_module(self, module: str, filepath: str | None) -> None:
|
2020-10-30 22:15:01 +00:00
|
|
|
self.messages = []
|
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
def display_reports(self, layout: Section) -> None:
|
2020-10-30 22:15:01 +00:00
|
|
|
"""Ignore layouts and don't call self._display()."""
|
2021-07-06 05:33:06 +00:00
|
|
|
|
2022-04-14 07:47:58 +00:00
|
|
|
def _display(self, layout: Section) -> None:
|
2021-07-06 05:33:06 +00:00
|
|
|
pass
|