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_checker_exceptions.py @ 745
History | View | Annotate | Download (2.67 KB)
1 |
# Copyright (c) 2003-2015 LOGILAB S.A. (Paris, FRANCE).
|
---|---|
2 |
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
|
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify it under
|
5 |
# the terms of the GNU General Public License as published by the Free Software
|
6 |
# Foundation; either version 2 of the License, or (at your option) any later
|
7 |
# version.
|
8 |
#
|
9 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
10 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
11 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
12 |
#
|
13 |
# You should have received a copy of the GNU General Public License along with
|
14 |
# this program; if not, write to the Free Software Foundation, Inc.,
|
15 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
16 |
"""Tests for pylint.checkers.exceptions."""
|
17 |
|
18 |
import sys |
19 |
import unittest |
20 |
|
21 |
from astroid import test_utils |
22 |
from pylint.checkers import exceptions |
23 |
from pylint.testutils import CheckerTestCase, Message |
24 |
|
25 |
|
26 |
class ExceptionsCheckerTest(CheckerTestCase): |
27 |
"""Tests for pylint.checkers.exceptions."""
|
28 |
|
29 |
CHECKER_CLASS = exceptions.ExceptionsChecker |
30 |
|
31 |
# These tests aren't in the functional test suite,
|
32 |
# since they will be converted with 2to3 for Python 3
|
33 |
# and `raise (Error, ...)` will be converted to
|
34 |
# `raise Error(...)`, so it beats the purpose of the test.
|
35 |
|
36 |
@unittest.skipUnless(sys.version_info[0] == 3, |
37 |
"The test should emit an error on Python 3.")
|
38 |
def test_raising_bad_type_python3(self): |
39 |
node = test_utils.extract_node('raise (ZeroDivisionError, None) #@')
|
40 |
message = Message('raising-bad-type', node=node, args='tuple') |
41 |
with self.assertAddsMessages(message): |
42 |
self.checker.visit_raise(node)
|
43 |
|
44 |
@unittest.skipUnless(sys.version_info[0] == 2, |
45 |
"The test is valid only on Python 2.")
|
46 |
def test_raising_bad_type_python2(self): |
47 |
nodes = test_utils.extract_node('''
|
48 |
raise (ZeroDivisionError, None) #@
|
49 |
from something import something
|
50 |
raise (something, None) #@
|
51 |
|
52 |
raise (4, None) #@
|
53 |
raise () #@
|
54 |
''')
|
55 |
with self.assertNoMessages(): |
56 |
self.checker.visit_raise(nodes[0]) |
57 |
with self.assertNoMessages(): |
58 |
self.checker.visit_raise(nodes[1]) |
59 |
|
60 |
message = Message('raising-bad-type', node=nodes[2], args='tuple') |
61 |
with self.assertAddsMessages(message): |
62 |
self.checker.visit_raise(nodes[2]) |
63 |
message = Message('raising-bad-type', node=nodes[3], args='tuple') |
64 |
with self.assertAddsMessages(message): |
65 |
self.checker.visit_raise(nodes[3]) |
66 |
|
67 |
|
68 |
if __name__ == '__main__': |
69 |
unittest.main() |