Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / unittest_reporters_json.py @ 745

History | View | Annotate | Download (2.03 KB)

1
# Copyright (c) 2003-2015 LOGILAB S.A. (Paris, FRANCE).
2
# This program is free software; you can redistribute it and/or modify it under
3
# the terms of the GNU General Public License as published by the Free Software
4
# Foundation; either version 2 of the License, or (at your option) any later
5
# version.
6
#
7
# This program is distributed in the hope that it will be useful, but WITHOUT
8
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
#
11
# You should have received a copy of the GNU General Public License along with
12
# this program; if not, write to the Free Software Foundation, Inc.,
13
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14

    
15
"""Test for the JSON reporter."""
16

    
17
import json
18
import unittest
19

    
20
import six
21

    
22
from pylint.lint import PyLinter
23
from pylint import checkers
24
from pylint.reporters.json import JSONReporter
25

    
26

    
27
class TestJSONReporter(unittest.TestCase):
28

    
29
    def test_simple_json_output(self):
30
        output = six.StringIO()
31

    
32
        reporter = JSONReporter()
33
        linter = PyLinter(reporter=reporter)
34
        checkers.initialize(linter)
35

    
36
        linter.config.persistent = 0
37
        linter.reporter.set_output(output)
38
        linter.open()
39
        linter.set_current_module('0123')
40
        linter.add_message('line-too-long', line=1, args=(1, 2))
41

    
42
        # we call this method because we didn't actually run the checkers
43
        reporter.display_messages(None)
44

    
45
        expected_result = [[
46
            ("column", 0),
47
            ("line", 1),
48
            ("message", "Line too long (1/2)"),
49
            ("module", "0123"),
50
            ("obj", ""),
51
            ("path", "0123"),
52
            ("symbol", "line-too-long"),
53
            ("type", "convention"),
54
        ]]
55
        report_result = json.loads(output.getvalue())
56
        report_result = [sorted(report_result[0].items(),
57
                                key=lambda item: item[0])]
58
        self.assertEqual(report_result, expected_result)
59

    
60

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