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_stdlib.py @ 745
History | View | Annotate | Download (2.25 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 |
|
17 |
import contextlib |
18 |
import unittest |
19 |
|
20 |
import astroid |
21 |
from astroid import test_utils |
22 |
|
23 |
from pylint.checkers import stdlib |
24 |
from pylint.testutils import CheckerTestCase |
25 |
|
26 |
|
27 |
@contextlib.contextmanager
|
28 |
def _add_transform(manager, node, transform, predicate=None): |
29 |
manager.register_transform(node, transform, predicate) |
30 |
try:
|
31 |
yield
|
32 |
finally:
|
33 |
manager.unregister_transform(node, transform, predicate) |
34 |
|
35 |
|
36 |
class StdlibCheckerTest(CheckerTestCase): |
37 |
CHECKER_CLASS = stdlib.StdlibChecker |
38 |
|
39 |
def test_deprecated_no_qname_on_unexpected_nodes(self): |
40 |
# Test that we don't crash on nodes which don't have
|
41 |
# a qname method. While this test might seem weird since
|
42 |
# it uses a transform, it's actually testing a crash that
|
43 |
# happened in production, but there was no way to retrieve
|
44 |
# the code for which this occurred (how an AssignAttr
|
45 |
# got to be the result of a function inference
|
46 |
# beats me..)
|
47 |
|
48 |
def infer_func(node, context=None): |
49 |
new_node = astroid.AssignAttr() |
50 |
new_node.parent = node |
51 |
yield new_node
|
52 |
|
53 |
manager = astroid.MANAGER |
54 |
transform = astroid.inference_tip(infer_func) |
55 |
with _add_transform(manager, astroid.Name, transform):
|
56 |
node = test_utils.extract_node('''
|
57 |
call_something()
|
58 |
''')
|
59 |
with self.assertNoMessages(): |
60 |
self.checker.visit_call(node)
|
61 |
|
62 |
|
63 |
|
64 |
if __name__ == '__main__': |
65 |
unittest.main() |