summaryrefslogtreecommitdiff
path: root/tests/reporters
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-06-27 16:04:09 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-06-29 10:19:55 +0200
commit1b7965a028fecabfd1488f4c5c50b8172fcec217 (patch)
treee960514f1cfc20007f5895f2ca871994777f360c /tests/reporters
parent32985f75fa912823d08710db78ced5387c7c08a6 (diff)
downloadpylint-git-1b7965a028fecabfd1488f4c5c50b8172fcec217.tar.gz
[JsonReporter] Add serialization functions to JsonReporter
Diffstat (limited to 'tests/reporters')
-rw-r--r--tests/reporters/unittest_json_reporter.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/reporters/unittest_json_reporter.py b/tests/reporters/unittest_json_reporter.py
index 2a0843e7f..fd29d8ea8 100644
--- a/tests/reporters/unittest_json_reporter.py
+++ b/tests/reporters/unittest_json_reporter.py
@@ -10,10 +10,15 @@ import json
from io import StringIO
from typing import Any
+import pytest
+
from pylint import checkers
+from pylint.interfaces import UNDEFINED
from pylint.lint import PyLinter
+from pylint.message import Message
from pylint.reporters import JSONReporter
from pylint.reporters.ureports.nodes import EvaluationSection
+from pylint.typing import MessageLocationTuple
expected_score_message = "Expected score message"
@@ -98,3 +103,35 @@ def get_linter_result(score: bool, message: dict[str, Any]) -> list[dict[str, An
reporter.display_messages(None)
report_result = json.loads(output.getvalue())
return report_result
+
+
+@pytest.mark.parametrize(
+ "message",
+ [
+ pytest.param(
+ Message(
+ msg_id="C0111",
+ symbol="missing-docstring",
+ location=MessageLocationTuple(
+ # abs-path and path must be equal because one of them is removed
+ # in the JsonReporter
+ abspath=__file__,
+ path=__file__,
+ module="unittest_json_reporter",
+ obj="obj",
+ line=1,
+ column=3,
+ end_line=3,
+ end_column=5,
+ ),
+ msg="This is the actual message",
+ confidence=UNDEFINED,
+ ),
+ id="everything-defined",
+ )
+ ],
+)
+def test_serialize_deserialize(message):
+ # TODO (3.0): Add confidence handling, add path and abs path handling
+ json_message = JSONReporter.serialize(message)
+ assert message == JSONReporter.deserialize(json_message)