Add test for checkers

authorCezar
changeset0da10976f0a5
branchdeprecated_methods
phasepublic
hiddenno
parent revision#ab9a29c02849 Add checker for deprecated methods
child revision#42a46cb47d7a Close branch
files modified by this revision
pylint/test/unittest_checker_stdlib.py
# HG changeset patch
# User Cezar
# Date 1442692412 -10800
# Sat Sep 19 22:53:32 2015 +0300
# Branch deprecated_methods
# Node ID 0da10976f0a51993218f0814b554ad8a6e54ee59
# Parent ab9a29c02849ca55bba61f72e770694a6ca50e07
Add test for checkers

diff --git a/pylint/test/unittest_checker_stdlib.py b/pylint/test/unittest_checker_stdlib.py
@@ -0,0 +1,122 @@
1 +"""Unit tests for the imports checker."""
2 +import unittest
3 +
4 +from astroid import test_utils
5 +from pylint.checkers import stdlib
6 +from pylint.testutils import CheckerTestCase, Message
7 +
8 +
9 +class StdlibCheckerTC(CheckerTestCase):
10 +
11 +    CHECKER_CLASS = stdlib.StdlibChecker
12 +
13 +    def test_asyncio_deprecated(self):
14 +        """
15 +        `asyncio.async` is deprecated.
16 +        """
17 +        node = test_utils.extract_node("""
18 +        import asyncio
19 +        asyncio.async()
20 +        """)
21 +        msg = Message(msg_id='deprecated-method', node=node,
22 +                      args=('async', ))
23 +        with self.assertAddsMessages(msg):
24 +            self.checker.visit_call(node)
25 +
26 +    def test_base64_deprecated(self):
27 +        """
28 +        `base64.encodestring` and `base64.decodestring` are deprecated.
29 +        """
30 +        node = test_utils.extract_node("""
31 +        import base64
32 +        base64.encodestring('a')
33 +        """)
34 +        msg = Message(msg_id='deprecated-method', node=node,
35 +                      args=('encodestring', ))
36 +        with self.assertAddsMessages(msg):
37 +            self.checker.visit_call(node)
38 +
39 +        node = test_utils.extract_node("""
40 +        import base64
41 +        base64.decodestring('a')
42 +        """)
43 +        msg = Message(msg_id='deprecated-method', node=node,
44 +                      args=('decodestring', ))
45 +        with self.assertAddsMessages(msg):
46 +            self.checker.visit_call(node)
47 +
48 +    def test_cgi_deprecated(self):
49 +        """
50 +        All deprecated methods in package `cgi`
51 +        """
52 +
53 +        node = test_utils.extract_node("""
54 +        from cgi import parse_qs
55 +        parse_qs()
56 +        """)
57 +        msg = Message(msg_id='deprecated-method', node=node,
58 +                      args=('parse_qs', ))
59 +        with self.assertAddsMessages(msg):
60 +            self.checker.visit_call(node)
61 +
62 +        node = test_utils.extract_node("""
63 +        import cgi
64 +        cgi.parse_qsl()
65 +        """)
66 +        msg = Message(msg_id='deprecated-method', node=node,
67 +                      args=('parse_qsl', ))
68 +        with self.assertAddsMessages(msg):
69 +            self.checker.visit_call(node)
70 +
71 +        node = test_utils.extract_node("""
72 +        from cgi import escape
73 +        escape()
74 +        """)
75 +        msg = Message(msg_id='deprecated-method', node=node,
76 +                      args=('escape', ))
77 +        with self.assertAddsMessages(msg):
78 +            self.checker.visit_call(node)
79 +
80 +    def test_unittest_deprecated(self):
81 +        """
82 +        Deprecated methods in package `unittest`
83 +        """
84 +        node = test_utils.extract_node("""
85 +        import unittest
86 +        class TestMe(unittest.TestCase):
87 +            def test(self):
88 +                self.failIf(True)
89 +        """)
90 +        msg = Message(msg_id='deprecated-method', node=node,
91 +                      args=('failIf', ))
92 +        with self.assertAddsMessages(msg):
93 +            self.checker.visit_call(node)
94 +
95 +    def test_html_deprecated(self):
96 +        """
97 +        `html` deprecation
98 +        """
99 +        node = test_utils.extract_node("""
100 +        import html.parser
101 +        html.parser.unescape('a')
102 +        """)
103 +        msg = Message(msg_id='deprecated-method', node=node,
104 +                      args=('unescape', ))
105 +        with self.assertAddsMessages(msg):
106 +            self.checker.visit_call(node)
107 +
108 +    def test_distutils_deprecated(self):
109 +        """
110 +        `distutil` deprecation
111 +        """
112 +        node = test_utils.extract_node("""
113 +        import distutils
114 +        distutils.command.register.register('a').check_metadata()
115 +        """)
116 +        msg = Message(msg_id='deprecated-method', node=node,
117 +                      args=('check_metadata', ))
118 +        with self.assertAddsMessages(msg):
119 +            self.checker.visit_call(node)
120 +
121 +if __name__ == '__main__':
122 +    unittest.main()