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_classes.py @ 745
History | View | Annotate | Download (2.81 KB)
1 |
"""Unit tests for the variables checker."""
|
---|---|
2 |
import unittest |
3 |
import sys |
4 |
|
5 |
import astroid |
6 |
from astroid import test_utils |
7 |
from pylint.checkers import classes |
8 |
from pylint.testutils import CheckerTestCase, Message, set_config |
9 |
|
10 |
class VariablesCheckerTC(CheckerTestCase): |
11 |
|
12 |
CHECKER_CLASS = classes.ClassChecker |
13 |
|
14 |
def test_bitbucket_issue_164(self): |
15 |
"""Issue 164 report a false negative for access-member-before-definition"""
|
16 |
n1, n2 = test_utils.extract_node("""
|
17 |
class MyClass1(object):
|
18 |
def __init__(self):
|
19 |
self.first += 5 #@
|
20 |
self.first = 0 #@
|
21 |
""")
|
22 |
message = Message('access-member-before-definition',
|
23 |
node=n1.target, args=('first', n2.lineno))
|
24 |
with self.assertAddsMessages(message): |
25 |
self.walk(n1.root())
|
26 |
|
27 |
@set_config(exclude_protected=('_meta', '_manager')) |
28 |
def test_exclude_protected(self): |
29 |
"""Test that exclude-protected can be used to
|
30 |
exclude names from protected-access warning.
|
31 |
"""
|
32 |
|
33 |
node = astroid.parse("""
|
34 |
class Protected(object):
|
35 |
'''empty'''
|
36 |
def __init__(self):
|
37 |
self._meta = 42
|
38 |
self._manager = 24
|
39 |
self._teta = 29
|
40 |
OBJ = Protected()
|
41 |
OBJ._meta
|
42 |
OBJ._manager
|
43 |
OBJ._teta
|
44 |
""")
|
45 |
with self.assertAddsMessages( |
46 |
Message('protected-access',
|
47 |
node=node.body[-1].value,
|
48 |
args='_teta')):
|
49 |
self.walk(node.root())
|
50 |
|
51 |
@unittest.skipUnless(sys.version_info[0] == 3, |
52 |
"The test works on Python 3.")
|
53 |
def test_regression_non_parent_init_called_tracemalloc(self): |
54 |
# This used to raise a non-parent-init-called on Pylint 1.3
|
55 |
# See issue https://bitbucket.org/logilab/pylint/issue/308/
|
56 |
# for reference.
|
57 |
node = test_utils.extract_node("""
|
58 |
from tracemalloc import Sequence
|
59 |
class _Traces(Sequence):
|
60 |
def __init__(self, traces): #@
|
61 |
Sequence.__init__(self)
|
62 |
""")
|
63 |
with self.assertNoMessages(): |
64 |
self.checker.visit_functiondef(node)
|
65 |
|
66 |
def test_super_init_not_called_regression(self): |
67 |
# This should not emit a super-init-not-called
|
68 |
# warning. It previously did this, because
|
69 |
# ``next(node.infer())`` was used in that checker's
|
70 |
# logic and the first inferred node was an YES object,
|
71 |
# leading to this false positive.
|
72 |
node = test_utils.extract_node("""
|
73 |
import ctypes
|
74 |
|
75 |
class Foo(ctypes.BigEndianStructure):
|
76 |
def __init__(self): #@
|
77 |
ctypes.BigEndianStructure.__init__(self)
|
78 |
""")
|
79 |
with self.assertNoMessages(): |
80 |
self.checker.visit_functiondef(node)
|
81 |
|
82 |
|
83 |
if __name__ == '__main__': |
84 |
unittest.main() |