diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-04-22 13:55:30 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-04-26 12:43:49 +0200 |
commit | 352cd4c91a7fe22526a91709e49fad3e9b14fe38 (patch) | |
tree | b1f9e7f7b5e0b92ac5d7118f5a2300db9d839993 /tests/unittest_reporters_json.py | |
parent | cbce442a195c50559b59f813af644f079088c8a4 (diff) | |
download | pylint-git-352cd4c91a7fe22526a91709e49fad3e9b14fe38.tar.gz |
[test json] Refactor the json reporter unittest
Permit to test score more easily later on.
Diffstat (limited to 'tests/unittest_reporters_json.py')
-rw-r--r-- | tests/unittest_reporters_json.py | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/tests/unittest_reporters_json.py b/tests/unittest_reporters_json.py index 19a215acf..831c4cbd4 100644 --- a/tests/unittest_reporters_json.py +++ b/tests/unittest_reporters_json.py @@ -16,37 +16,44 @@ from io import StringIO from pylint import checkers from pylint.lint import PyLinter from pylint.reporters import JSONReporter +from pylint.reporters.ureports.nodes import EvaluationSection + +expected_score_message = "Expected score message" +expected_result = [ + [ + ("column", 0), + ("line", 1), + ("message", "Line too long (1/2)"), + ("message-id", "C0301"), + ("module", "0123"), + ("obj", ""), + ("path", "0123"), + ("symbol", "line-too-long"), + ("type", "convention"), + ] +] -def test_simple_json_output(): - output = StringIO() +def test_simple_json_output_no_score(): + report = get_linter_result(score=False) + assert len(report) == 1 + report_result = [sorted(report[0].items(), key=lambda item: item[0])] + assert report_result == expected_result - reporter = JSONReporter() + +def get_linter_result(score): + output = StringIO() + reporter = JSONReporter(output) linter = PyLinter(reporter=reporter) checkers.initialize(linter) - linter.config.persistent = 0 - linter.reporter.set_output(output) + linter.config.score = score linter.open() linter.set_current_module("0123") linter.add_message("line-too-long", line=1, args=(1, 2)) - - # we call this method because we didn't actually run the checkers + # we call those methods because we didn't actually run the checkers + if score: + reporter.display_reports(EvaluationSection(expected_score_message)) reporter.display_messages(None) - - expected_result = [ - [ - ("column", 0), - ("line", 1), - ("message", "Line too long (1/2)"), - ("message-id", "C0301"), - ("module", "0123"), - ("obj", ""), - ("path", "0123"), - ("symbol", "line-too-long"), - ("type", "convention"), - ] - ] report_result = json.loads(output.getvalue()) - report_result = [sorted(report_result[0].items(), key=lambda item: item[0])] - assert report_result == expected_result + return report_result |