From 2a41113c489b9ff38c1f3e9621e62c7607bc2c69 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 26 Apr 2020 16:12:06 +0200 Subject: [PATCH] Fix the Windows's bug with \r\n instead of \n --- pylint/reporters/json_reporter.py | 5 +++-- tests/unittest_reporters_json.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pylint/reporters/json_reporter.py b/pylint/reporters/json_reporter.py index 6a67689815d..833e6660911 100644 --- a/pylint/reporters/json_reporter.py +++ b/pylint/reporters/json_reporter.py @@ -54,8 +54,9 @@ def display_messages(self, layout): def display_reports(self, layout): output = io.StringIO() TextWriter().format(layout, output) - score = output.getvalue().split("\n")[1] - self.messages.append({"score": score}) + score = output.getvalue().split("Your")[1] + score = score.split(r"/10")[0] + self.messages.append({"score": "Your{}/10".format(score)}) def _display(self, layout): """Do nothing.""" diff --git a/tests/unittest_reporters_json.py b/tests/unittest_reporters_json.py index e04bdea1d0a..6677186ce3b 100644 --- a/tests/unittest_reporters_json.py +++ b/tests/unittest_reporters_json.py @@ -20,7 +20,7 @@ from pylint.reporters import JSONReporter from pylint.reporters.ureports.nodes import EvaluationSection -expected_score_message = "Expected score message" +expected_score_message = "Your code has been rated at 7.50/10" expected_result = [ [ ("column", 0), @@ -63,7 +63,10 @@ def get_linter_result(score): linter.add_message("line-too-long", line=1, args=(1, 2)) # we call those methods because we didn't actually run the checkers if score: - reporter.display_reports(EvaluationSection(expected_score_message)) + generated_msg = "-------------------------------------\r\n{}\r\n".format( + expected_score_message + ) + reporter.display_reports(EvaluationSection(generated_msg)) reporter.display_messages(None) report_result = json.loads(output.getvalue()) return report_result