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 / extensions / test_elseif_used.py @ 745
History | View | Annotate | Download (1.33 KB)
1 |
"""Tests for the pylint checker in :mod:`pylint.extensions.check_elif
|
---|---|
2 |
"""
|
3 |
|
4 |
import os |
5 |
import os.path as osp |
6 |
import unittest |
7 |
|
8 |
from pylint import checkers |
9 |
from pylint.extensions.check_elif import ElseifUsedChecker |
10 |
from pylint.lint import PyLinter |
11 |
from pylint.reporters import BaseReporter |
12 |
|
13 |
|
14 |
class TestReporter(BaseReporter): |
15 |
|
16 |
def handle_message(self, msg): |
17 |
self.messages.append(msg)
|
18 |
|
19 |
def on_set_current_module(self, module, filepath): |
20 |
self.messages = []
|
21 |
|
22 |
|
23 |
class CheckElseIfUsedTC(unittest.TestCase): |
24 |
|
25 |
@classmethod
|
26 |
def setUpClass(cls): |
27 |
cls._linter = PyLinter() |
28 |
cls._linter.set_reporter(TestReporter()) |
29 |
checkers.initialize(cls._linter) |
30 |
cls._linter.register_checker(ElseifUsedChecker(cls._linter)) |
31 |
|
32 |
def test_elseif_message(self): |
33 |
elif_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data',
|
34 |
'elif.py')
|
35 |
self._linter.check([elif_test])
|
36 |
msgs = self._linter.reporter.messages
|
37 |
self.assertEqual(len(msgs), 2) |
38 |
for msg in msgs: |
39 |
self.assertEqual(msg.symbol, 'else-if-used') |
40 |
self.assertEqual(msg.msg,
|
41 |
'Consider using "elif" instead of "else if"')
|
42 |
self.assertEqual(msgs[0].line, 9) |
43 |
self.assertEqual(msgs[1].line, 21) |
44 |
|
45 |
|
46 |
if __name__ == '__main__': |
47 |
unittest.main() |