1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
"""Unittest for the type checker."""
import unittest
from astroid import test_utils
from pylint.checkers import typecheck
from pylint.testutils import CheckerTestCase, Message, set_config
class TypeCheckerTest(CheckerTestCase):
"Tests for pylint.checkers.typecheck"
CHECKER_CLASS = typecheck.TypeChecker
def test_no_member_in_getattr(self):
"""Make sure that a module attribute access is checked by pylint.
"""
node = test_utils.extract_node("""
import optparse
optparse.THIS_does_not_EXIST
""")
with self.assertAddsMessages(
Message(
'no-member',
node=node,
args=('Module', 'optparse', 'THIS_does_not_EXIST'))):
self.checker.visit_attribute(node)
@set_config(ignored_modules=('argparse',))
def test_no_member_in_getattr_ignored(self):
"""Make sure that a module attribute access check is omitted with a
module that is configured to be ignored.
"""
node = test_utils.extract_node("""
import argparse
argparse.THIS_does_not_EXIST
""")
with self.assertNoMessages():
self.checker.visit_attribute(node)
@set_config(ignored_classes=('xml.etree.', ))
def test_ignored_modules_invalid_pattern(self):
node = test_utils.extract_node('''
import xml
xml.etree.Lala
''')
message = Message('no-member', node=node,
args=('Module', 'xml.etree', 'Lala'))
with self.assertAddsMessages(message):
self.checker.visit_attribute(node)
@set_config(ignored_modules=('xml.etree*', ))
def test_ignored_modules_patterns(self):
node = test_utils.extract_node('''
import xml
xml.etree.portocola #@
''')
with self.assertNoMessages():
self.checker.visit_attribute(node)
@set_config(ignored_classes=('xml.*', ))
def test_ignored_classes_no_recursive_pattern(self):
node = test_utils.extract_node('''
import xml
xml.etree.ElementTree.Test
''')
message = Message('no-member', node=node,
args=('Module', 'xml.etree.ElementTree', 'Test'))
with self.assertAddsMessages(message):
self.checker.visit_attribute(node)
@set_config(ignored_classes=('optparse.Values', ))
def test_ignored_classes_qualified_name(self):
"""Test that ignored-classes supports qualified name for ignoring."""
node = test_utils.extract_node('''
import optparse
optparse.Values.lala
''')
with self.assertNoMessages():
self.checker.visit_attribute(node)
@set_config(ignored_classes=('Values', ))
def test_ignored_classes_only_name(self):
"""Test that ignored_classes works with the name only."""
node = test_utils.extract_node('''
import optparse
optparse.Values.lala
''')
with self.assertNoMessages():
self.checker.visit_attribute(node)
if __name__ == '__main__':
unittest.main()
|