File: unittest_reporters_json.py

package info (click to toggle)
pylint 1.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,852 kB
  • ctags: 4,564
  • sloc: python: 38,086; makefile: 187; lisp: 163; sh: 50
file content (55 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright (c) 2014 Vlad Temian <vladtemian@gmail.com>
# Copyright (c) 2015-2016 Claudiu Popa <pcmanticore@gmail.com>
# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING

"""Test for the JSON reporter."""

import json
import unittest

import six

from pylint.lint import PyLinter
from pylint import checkers
from pylint.reporters.json import JSONReporter


class TestJSONReporter(unittest.TestCase):

    def test_simple_json_output(self):
        output = six.StringIO()

        reporter = JSONReporter()
        linter = PyLinter(reporter=reporter)
        checkers.initialize(linter)

        linter.config.persistent = 0
        linter.reporter.set_output(output)
        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
        reporter.display_messages(None)

        expected_result = [[
            ("column", 0),
            ("line", 1),
            ("message", "Line too long (1/2)"),
            ("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])]
        self.assertEqual(report_result, expected_result)


if __name__ == '__main__':
    unittest.main()