diff options
Diffstat (limited to 'pylint/test')
-rw-r--r-- | pylint/test/extensions/test_check_docs.py | 36 | ||||
-rw-r--r-- | pylint/test/unittest_checker_base.py | 38 | ||||
-rw-r--r-- | pylint/test/unittest_checker_classes.py | 4 | ||||
-rw-r--r-- | pylint/test/unittest_checker_imports.py | 8 | ||||
-rw-r--r-- | pylint/test/unittest_checker_logging.py | 6 | ||||
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 38 | ||||
-rw-r--r-- | pylint/test/unittest_checker_spelling.py | 6 | ||||
-rw-r--r-- | pylint/test/unittest_checker_strings.py | 2 | ||||
-rw-r--r-- | pylint/test/unittest_checker_typecheck.py | 14 | ||||
-rw-r--r-- | pylint/test/unittest_checker_variables.py | 18 | ||||
-rw-r--r-- | pylint/test/unittest_utils.py | 39 |
11 files changed, 120 insertions, 89 deletions
diff --git a/pylint/test/extensions/test_check_docs.py b/pylint/test/extensions/test_check_docs.py index 07afb3ec2..3a5455a46 100644 --- a/pylint/test/extensions/test_check_docs.py +++ b/pylint/test/extensions/test_check_docs.py @@ -47,7 +47,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('x, y',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_missing_func_params_in_google_docstring(self): """Example of a function with missing Google style parameter @@ -75,7 +75,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('x, y',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_missing_func_params_in_numpy_docstring(self): """Example of a function with missing NumPy style parameter @@ -106,7 +106,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('x, y',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_tolerate_no_param_documentation_at_all(self): """Example of a function with no parameter documentation at all @@ -121,7 +121,7 @@ class ParamDocCheckerTest(CheckerTestCase): pass """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) @set_config(accept_no_param_doc=False) def test_don_t_tolerate_no_param_documentation_at_all(self): @@ -146,7 +146,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('x, y',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def _visit_methods_of_class(self, node): """Visit all methods of a class node @@ -157,7 +157,7 @@ class ParamDocCheckerTest(CheckerTestCase): for body_item in node.body: if (isinstance(body_item, astroid.FunctionDef) and hasattr(body_item, 'name')): - self.checker.visit_function(body_item) + self.checker.visit_functiondef(body_item) def test_missing_method_params_in_sphinx_docstring(self): """Example of a class method with missing parameter documentation in @@ -269,7 +269,7 @@ class ParamDocCheckerTest(CheckerTestCase): return xarg + yarg """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_existing_func_params_in_google_docstring(self): """Example of a function with correctly documented parameters and @@ -292,7 +292,7 @@ class ParamDocCheckerTest(CheckerTestCase): return xarg + yarg """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_existing_func_params_in_numpy_docstring(self): """Example of a function with correctly documented parameters and @@ -320,7 +320,7 @@ class ParamDocCheckerTest(CheckerTestCase): return xarg + yarg """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_wrong_name_of_func_params_in_sphinx_docstring(self): """Example of functions with inconsistent parameter names in the @@ -350,7 +350,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('yarg, yarg1, zarg, zarg1',)), ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) node = test_utils.extract_node(""" def function_foo(xarg, yarg): @@ -373,7 +373,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('yarg1',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_wrong_name_of_func_params_in_google_docstring(self): """Example of functions with inconsistent parameter names in the @@ -401,7 +401,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('xarg, xarg1, zarg, zarg1',)), ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) node = test_utils.extract_node(""" def function_foo(xarg, yarg): @@ -424,7 +424,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('yarg1',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_wrong_name_of_func_params_in_numpy_docstring(self): """Example of functions with inconsistent parameter names in the @@ -456,7 +456,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('xarg, xarg1, zarg, zarg1',)), ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) node = test_utils.extract_node(""" def function_foo(xarg, yarg): @@ -481,7 +481,7 @@ class ParamDocCheckerTest(CheckerTestCase): node=node, args=('yarg1',)) ): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_see_sentence_for_func_params_in_sphinx_docstring(self): """Example for the usage of "For the other parameters, see" to avoid @@ -500,7 +500,7 @@ class ParamDocCheckerTest(CheckerTestCase): return xarg + yarg """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_see_sentence_for_func_params_in_google_docstring(self): """Example for the usage of "For the other parameters, see" to avoid @@ -519,7 +519,7 @@ class ParamDocCheckerTest(CheckerTestCase): return xarg + yarg """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_see_sentence_for_func_params_in_numpy_docstring(self): """Example for the usage of "For the other parameters, see" to avoid @@ -540,7 +540,7 @@ class ParamDocCheckerTest(CheckerTestCase): return xarg + yarg """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_constr_params_in_class_sphinx(self): """Example of a class with missing constructor parameter documentation diff --git a/pylint/test/unittest_checker_base.py b/pylint/test/unittest_checker_base.py index 0d25d2982..f19544f22 100644 --- a/pylint/test/unittest_checker_base.py +++ b/pylint/test/unittest_checker_base.py @@ -36,7 +36,7 @@ class DocstringTest(CheckerTestCase): pass""") message = Message('missing-docstring', node=func, args=('function',)) with self.assertAddsMessages(message): - self.checker.visit_function(func) + self.checker.visit_functiondef(func) @set_config(docstring_min_length=2) def test_short_function_no_docstring(self): @@ -44,7 +44,7 @@ class DocstringTest(CheckerTestCase): def func(tion): pass""") with self.assertNoMessages(): - self.checker.visit_function(func) + self.checker.visit_functiondef(func) @set_config(docstring_min_length=2) def test_function_no_docstring_by_name(self): @@ -52,7 +52,7 @@ class DocstringTest(CheckerTestCase): def __fun__(tion): pass""") with self.assertNoMessages(): - self.checker.visit_function(func) + self.checker.visit_functiondef(func) def test_class_no_docstring(self): klass = test_utils.extract_node(""" @@ -60,7 +60,7 @@ class DocstringTest(CheckerTestCase): pass""") message = Message('missing-docstring', node=klass, args=('class',)) with self.assertAddsMessages(message): - self.checker.visit_class(klass) + self.checker.visit_classdef(klass) class NameCheckerTest(CheckerTestCase): @@ -79,7 +79,7 @@ class NameCheckerTest(CheckerTestCase): args=('constant', 'const', ' (hint: (([A-Z_][A-Z0-9_]*)|(__.*__))$)')) with self.assertAddsMessages(message): - self.checker.visit_assname(const.targets[0]) + self.checker.visit_assignname(const.targets[0]) @set_config(include_naming_hint=True, const_name_hint='CONSTANT') def test_naming_hint_configured_hint(self): @@ -89,7 +89,7 @@ class NameCheckerTest(CheckerTestCase): with self.assertAddsMessages( Message('invalid-name', node=const.targets[0], args=('constant', 'const', ' (hint: CONSTANT)'))): - self.checker.visit_assname(const.targets[0]) + self.checker.visit_assignname(const.targets[0]) @set_config(attr_rgx=re.compile('[A-Z]+')) def test_property_names(self): @@ -113,11 +113,11 @@ class NameCheckerTest(CheckerTestCase): pass """) with self.assertNoMessages(): - self.checker.visit_function(methods[0]) - self.checker.visit_function(methods[2]) + self.checker.visit_functiondef(methods[0]) + self.checker.visit_functiondef(methods[2]) with self.assertAddsMessages(Message('invalid-name', node=methods[1], args=('attribute', 'bar', ''))): - self.checker.visit_function(methods[1]) + self.checker.visit_functiondef(methods[1]) @set_config(attr_rgx=re.compile('[A-Z]+')) def test_property_setters(self): @@ -131,7 +131,7 @@ class NameCheckerTest(CheckerTestCase): pass """) with self.assertNoMessages(): - self.checker.visit_function(method) + self.checker.visit_functiondef(method) def test_module_level_names(self): assign = test_utils.extract_node(""" @@ -139,7 +139,7 @@ class NameCheckerTest(CheckerTestCase): Class = collections.namedtuple("a", ("b", "c")) #@ """) with self.assertNoMessages(): - self.checker.visit_assname(assign.targets[0]) + self.checker.visit_assignname(assign.targets[0]) assign = test_utils.extract_node(""" class ClassA(object): @@ -147,7 +147,7 @@ class NameCheckerTest(CheckerTestCase): ClassB = ClassA """) with self.assertNoMessages(): - self.checker.visit_assname(assign.targets[0]) + self.checker.visit_assignname(assign.targets[0]) module = astroid.parse(""" def A(): @@ -155,13 +155,13 @@ class NameCheckerTest(CheckerTestCase): CONSTA, CONSTB, CONSTC = A() CONSTD = A()""") with self.assertNoMessages(): - self.checker.visit_assname(module.body[1].targets[0].elts[0]) - self.checker.visit_assname(module.body[2].targets[0]) + self.checker.visit_assignname(module.body[1].targets[0].elts[0]) + self.checker.visit_assignname(module.body[2].targets[0]) assign = test_utils.extract_node(""" CONST = "12 34 ".rstrip().split()""") with self.assertNoMessages(): - self.checker.visit_assname(assign.targets[0]) + self.checker.visit_assignname(assign.targets[0]) class MultiNamingStyleTest(CheckerTestCase): @@ -184,7 +184,7 @@ class MultiNamingStyleTest(CheckerTestCase): args=('class', 'classb', '')) with self.assertAddsMessages(message): for cls in classes: - self.checker.visit_class(cls) + self.checker.visit_classdef(cls) self.checker.leave_module(cls.root) @set_config(class_rgx=MULTI_STYLE_RE) @@ -205,7 +205,7 @@ class MultiNamingStyleTest(CheckerTestCase): ] with self.assertAddsMessages(*messages): for cls in classes: - self.checker.visit_class(cls) + self.checker.visit_classdef(cls) self.checker.leave_module(cls.root) @set_config(method_rgx=MULTI_STYLE_RE, @@ -224,7 +224,7 @@ class MultiNamingStyleTest(CheckerTestCase): args=('function', 'FUNC', '')) with self.assertAddsMessages(message): for func in function_defs: - self.checker.visit_function(func) + self.checker.visit_functiondef(func) self.checker.leave_module(func.root) @set_config(function_rgx=re.compile('(?:(?P<ignore>FOO)|(?P<UP>[A-Z]+)|(?P<down>[a-z]+))$')) @@ -243,7 +243,7 @@ class MultiNamingStyleTest(CheckerTestCase): args=('function', 'UPPER', '')) with self.assertAddsMessages(message): for func in function_defs: - self.checker.visit_function(func) + self.checker.visit_functiondef(func) self.checker.leave_module(func.root) diff --git a/pylint/test/unittest_checker_classes.py b/pylint/test/unittest_checker_classes.py index 9f80cc98d..ae1b919fe 100644 --- a/pylint/test/unittest_checker_classes.py +++ b/pylint/test/unittest_checker_classes.py @@ -61,7 +61,7 @@ class VariablesCheckerTC(CheckerTestCase): Sequence.__init__(self) """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_super_init_not_called_regression(self): # This should not emit a super-init-not-called @@ -77,7 +77,7 @@ class VariablesCheckerTC(CheckerTestCase): ctypes.BigEndianStructure.__init__(self) """) with self.assertNoMessages(): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) if __name__ == '__main__': diff --git a/pylint/test/unittest_checker_imports.py b/pylint/test/unittest_checker_imports.py index 143d17c55..be0bc4844 100644 --- a/pylint/test/unittest_checker_imports.py +++ b/pylint/test/unittest_checker_imports.py @@ -18,13 +18,13 @@ class ImportsCheckerTC(CheckerTestCase): from external_module import anything """) with self.assertNoMessages(): - self.checker.visit_from(node) + self.checker.visit_importfrom(node) node = test_utils.extract_node(""" from external_module.another_module import anything """) with self.assertNoMessages(): - self.checker.visit_from(node) + self.checker.visit_importfrom(node) node = test_utils.extract_node(""" import external_module @@ -36,13 +36,13 @@ class ImportsCheckerTC(CheckerTestCase): from fake_module.submodule import anything """) with self.assertNoMessages(): - self.checker.visit_from(node) + self.checker.visit_importfrom(node) node = test_utils.extract_node(""" from fake_module.submodule.deeper import anything """) with self.assertNoMessages(): - self.checker.visit_from(node) + self.checker.visit_importfrom(node) if __name__ == '__main__': unittest.main() diff --git a/pylint/test/unittest_checker_logging.py b/pylint/test/unittest_checker_logging.py index e25daac68..0f19a3140 100644 --- a/pylint/test/unittest_checker_logging.py +++ b/pylint/test/unittest_checker_logging.py @@ -19,7 +19,7 @@ class LoggingModuleDetectionTest(CheckerTestCase): self.checker.visit_module(None) self.checker.visit_import(stmts[0]) with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])): - self.checker.visit_callfunc(stmts[1]) + self.checker.visit_call(stmts[1]) def test_detects_renamed_standard_logging_module(self): stmts = test_utils.extract_node(""" @@ -29,7 +29,7 @@ class LoggingModuleDetectionTest(CheckerTestCase): self.checker.visit_module(None) self.checker.visit_import(stmts[0]) with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])): - self.checker.visit_callfunc(stmts[1]) + self.checker.visit_call(stmts[1]) @set_config(logging_modules=['logging', 'my.logging']) def test_nonstandard_logging_module(self): @@ -40,7 +40,7 @@ class LoggingModuleDetectionTest(CheckerTestCase): self.checker.visit_module(None) self.checker.visit_import(stmts[0]) with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])): - self.checker.visit_callfunc(stmts[1]) + self.checker.visit_call(stmts[1]) if __name__ == '__main__': diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index 1bdea1d68..7f3b18205 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -80,7 +80,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): """.format(fxn)) message = testutils.Message(checker, node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def as_iterable_in_genexp_test(self, fxn): code = "x = (x for x in {}())".format(fxn) @@ -104,7 +104,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): """.format(fxn)) message = testutils.Message(checker, node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def as_used_in_variant_in_listcomp_test(self, fxn): checker = '{}-builtin-not-iterating'.format(fxn) @@ -115,7 +115,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): """.format(fxn)) message = testutils.Message(checker, node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def as_argument_to_callable_constructor_test(self, fxn, callable_fn): module = astroid.parse("x = {}({}())".format(callable_fn, fxn)) @@ -131,7 +131,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): """.format(fxn)) message = testutils.Message(checker, node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def as_argument_to_str_join_test(self, fxn): code = "x = ''.join({}())".format(fxn) @@ -144,7 +144,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): a, b = __({}()) """.format(fxn)) with self.assertNoMessages(): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def as_assignment(self, fxn): checker = '{}-builtin-not-iterating'.format(fxn) @@ -153,7 +153,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): """.format(fxn)) message = testutils.Message(checker, node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def iterating_context_tests(self, fxn): """Helper for verifying a function isn't used as an iterator.""" @@ -197,7 +197,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): pass""".format(method)) message = testutils.Message(warning, node=node) with self.assertAddsMessages(message): - self.checker.visit_function(node) + self.checker.visit_functiondef(node) def test_delslice_method(self): self.defined_method_test('delslice', 'delslice-method') @@ -235,7 +235,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): node = test_utils.extract_node('`test`') message = testutils.Message('backtick', node=node) with self.assertAddsMessages(message): - self.checker.visit_backquote(node) + self.checker.visit_repr(node) def test_relative_import(self): node = test_utils.extract_node('import string #@') @@ -266,7 +266,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): absolute = testutils.Message('no-absolute-import', node=node) star = testutils.Message('import-star-module-level', node=node) with self.assertAddsMessages(absolute, star): - self.checker.visit_from(node) + self.checker.visit_importfrom(node) def test_division(self): node = test_utils.extract_node('3 / 2 #@') @@ -296,13 +296,13 @@ class Python3CheckerTest(testutils.CheckerTestCase): node = test_utils.extract_node('x.iter%s() #@' % meth) message = testutils.Message('dict-iter-method', node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_dict_iter_method_on_dict(self): node = test_utils.extract_node('{}.iterkeys()') message = testutils.Message('dict-iter-method', node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_dict_not_iter_method(self): arg_node = test_utils.extract_node('x.iterkeys(x) #@') @@ -311,20 +311,20 @@ class Python3CheckerTest(testutils.CheckerTestCase): non_dict_node = test_utils.extract_node('x=[]\nx.iterkeys() #@') with self.assertNoMessages(): for node in (arg_node, stararg_node, kwarg_node, non_dict_node): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_dict_view_method(self): for meth in ('keys', 'values', 'items'): node = test_utils.extract_node('x.view%s() #@' % meth) message = testutils.Message('dict-view-method', node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_dict_view_method_on_dict(self): node = test_utils.extract_node('{}.viewkeys()') message = testutils.Message('dict-view-method', node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_dict_not_view_method(self): arg_node = test_utils.extract_node('x.viewkeys(x) #@') @@ -333,13 +333,13 @@ class Python3CheckerTest(testutils.CheckerTestCase): non_dict_node = test_utils.extract_node('x=[]\nx.viewkeys() #@') with self.assertNoMessages(): for node in (arg_node, stararg_node, kwarg_node, non_dict_node): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_next_method(self): node = test_utils.extract_node('x.next() #@') message = testutils.Message('next-method-called', node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_not_next_method(self): arg_node = test_utils.extract_node('x.next(x) #@') @@ -347,7 +347,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): kwarg_node = test_utils.extract_node('x.next(y=x) #@') with self.assertNoMessages(): for node in (arg_node, stararg_node, kwarg_node): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) def test_metaclass_assignment(self): node = test_utils.extract_node(""" @@ -355,7 +355,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): __metaclass__ = type""") message = testutils.Message('metaclass-assignment', node=node) with self.assertAddsMessages(message): - self.checker.visit_class(node) + self.checker.visit_classdef(node) def test_metaclass_global_assignment(self): module = astroid.parse('__metaclass__ = type') @@ -405,7 +405,7 @@ class Python3CheckerTest(testutils.CheckerTestCase): for node in nodes: message = testutils.Message('using-cmp-argument', node=node) with self.assertAddsMessages(message): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) @python2_only diff --git a/pylint/test/unittest_checker_spelling.py b/pylint/test/unittest_checker_spelling.py index c630eb202..3c43474ae 100644 --- a/pylint/test/unittest_checker_spelling.py +++ b/pylint/test/unittest_checker_spelling.py @@ -65,7 +65,7 @@ class SpellingCheckerTest(CheckerTestCase): args=('coment', 'bad coment', ' ^^^^^^', "comet' or 'comment' or 'moment' or 'foment"))): - self.checker.visit_function(stmt) + self.checker.visit_functiondef(stmt) stmt = test_utils.extract_node( 'class Abc(object):\n """bad coment"""\n pass') @@ -74,7 +74,7 @@ class SpellingCheckerTest(CheckerTestCase): args=('coment', 'bad coment', ' ^^^^^^', "comet' or 'comment' or 'moment' or 'foment"))): - self.checker.visit_class(stmt) + self.checker.visit_classdef(stmt) @unittest.skipIf(spell_dict is None, "missing python-enchant package or missing " @@ -86,7 +86,7 @@ class SpellingCheckerTest(CheckerTestCase): with self.assertAddsMessages( Message('invalid-characters-in-docstring', line=2, args=('test\x00',))): - self.checker.visit_function(stmt) + self.checker.visit_functiondef(stmt) if __name__ == '__main__': diff --git a/pylint/test/unittest_checker_strings.py b/pylint/test/unittest_checker_strings.py index eaf7663e5..9c6d76995 100644 --- a/pylint/test/unittest_checker_strings.py +++ b/pylint/test/unittest_checker_strings.py @@ -34,7 +34,7 @@ class StringCheckerTest(CheckerTestCase): code = "b'test'.format(1, 2)" node = test_utils.extract_node(code) with self.assertNoMessages(): - self.checker.visit_callfunc(node) + self.checker.visit_call(node) if __name__ == '__main__': diff --git a/pylint/test/unittest_checker_typecheck.py b/pylint/test/unittest_checker_typecheck.py index aa60a7bee..b7135ea9d 100644 --- a/pylint/test/unittest_checker_typecheck.py +++ b/pylint/test/unittest_checker_typecheck.py @@ -22,7 +22,7 @@ class TypeCheckerTest(CheckerTestCase): 'no-member', node=node, args=('Module', 'optparse', 'THIS_does_not_EXIST'))): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) @set_config(ignored_modules=('argparse',)) def test_no_member_in_getattr_ignored(self): @@ -35,7 +35,7 @@ class TypeCheckerTest(CheckerTestCase): argparse.THIS_does_not_EXIST """) with self.assertNoMessages(): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) @set_config(ignored_classes=('xml.etree.', )) def test_ignored_modules_invalid_pattern(self): @@ -46,7 +46,7 @@ class TypeCheckerTest(CheckerTestCase): message = Message('no-member', node=node, args=('Module', 'xml.etree', 'Lala')) with self.assertAddsMessages(message): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) @set_config(ignored_modules=('xml.etree*', )) def test_ignored_modules_patterns(self): @@ -55,7 +55,7 @@ class TypeCheckerTest(CheckerTestCase): xml.etree.portocola #@ ''') with self.assertNoMessages(): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) @set_config(ignored_classes=('xml.*', )) def test_ignored_classes_no_recursive_pattern(self): @@ -66,7 +66,7 @@ class TypeCheckerTest(CheckerTestCase): message = Message('no-member', node=node, args=('Module', 'xml.etree.ElementTree', 'Test')) with self.assertAddsMessages(message): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) @set_config(ignored_classes=('optparse.Values', )) def test_ignored_classes_qualified_name(self): @@ -76,7 +76,7 @@ class TypeCheckerTest(CheckerTestCase): optparse.Values.lala ''') with self.assertNoMessages(): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) @set_config(ignored_classes=('Values', )) def test_ignored_classes_only_name(self): @@ -86,7 +86,7 @@ class TypeCheckerTest(CheckerTestCase): optparse.Values.lala ''') with self.assertNoMessages(): - self.checker.visit_getattr(node) + self.checker.visit_attribute(node) if __name__ == '__main__': diff --git a/pylint/test/unittest_checker_variables.py b/pylint/test/unittest_checker_variables.py index a176a9088..0a235d4b2 100644 --- a/pylint/test/unittest_checker_variables.py +++ b/pylint/test/unittest_checker_variables.py @@ -36,7 +36,7 @@ class VariablesCheckerTC(CheckerTestCase): from argparse import THIS_does_not_EXIST """) with self.assertNoMessages(): - self.checker.visit_from(node) + self.checker.visit_importfrom(node) @set_config(callbacks=('callback_', '_callback')) def test_custom_callback_string(self): @@ -52,16 +52,16 @@ class VariablesCheckerTC(CheckerTestCase): ''' should not emit unused-argument. ''' """) with self.assertNoMessages(): - self.checker.visit_function(node) - self.checker.leave_function(node) + self.checker.visit_functiondef(node) + self.checker.leave_functiondef(node) node = test_utils.extract_node(""" def two_callback(abc, defg): ''' should not emit unused-argument. ''' """) with self.assertNoMessages(): - self.checker.visit_function(node) - self.checker.leave_function(node) + self.checker.visit_functiondef(node) + self.checker.leave_functiondef(node) node = test_utils.extract_node(""" def normal_func(abc): @@ -69,8 +69,8 @@ class VariablesCheckerTC(CheckerTestCase): """) with self.assertAddsMessages( Message('unused-argument', node=node['abc'], args='abc')): - self.checker.visit_function(node) - self.checker.leave_function(node) + self.checker.visit_functiondef(node) + self.checker.leave_functiondef(node) node = test_utils.extract_node(""" def cb_func(abc): @@ -78,8 +78,8 @@ class VariablesCheckerTC(CheckerTestCase): """) with self.assertAddsMessages( Message('unused-argument', node=node['abc'], args='abc')): - self.checker.visit_function(node) - self.checker.leave_function(node) + self.checker.visit_functiondef(node) + self.checker.leave_functiondef(node) class MissingSubmoduleTest(CheckerTestCase): diff --git a/pylint/test/unittest_utils.py b/pylint/test/unittest_utils.py index 193e45242..8fff282e3 100644 --- a/pylint/test/unittest_utils.py +++ b/pylint/test/unittest_utils.py @@ -12,9 +12,11 @@ # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import unittest +import warnings import astroid +from pylint import __pkginfo__ from pylint import utils from pylint import interfaces from pylint.checkers.utils import check_messages @@ -37,18 +39,18 @@ class PyLintASTWalkerTest(unittest.TestCase): self.called.add('module') @check_messages('second-message') - def visit_callfunc(self, module): + def visit_call(self, module): raise NotImplementedError @check_messages('second-message', 'third-message') - def visit_assname(self, module): + def visit_assignname(self, module): self.called.add('assname') @check_messages('second-message') - def leave_assname(self, module): + def leave_assignname(self, module): raise NotImplementedError - def testCheckMessages(self): + def test_check_messages(self): linter = self.MockLinter({'first-message': True, 'second-message': False, 'third-message': True}) @@ -58,6 +60,35 @@ class PyLintASTWalkerTest(unittest.TestCase): walker.walk(astroid.parse("x = func()")) self.assertEqual(set(['module', 'assname']), checker.called) + def test_deprecated_methods(self): + class Checker(object): + def __init__(self): + self.called = False + + @check_messages('first-message') + def visit_assname(self, node): + self.called = True + + linter = self.MockLinter({'first-message': True}) + walker = utils.PyLintASTWalker(linter) + checker = Checker() + walker.add_checker(checker) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + walker.walk(astroid.parse("x = 1")) + + if __pkginfo__.numversion < (2, 0): + expected = ('Implemented method visit_assname instead of ' + 'visit_assignname. This will be supported until ' + 'Pylint 2.0.') + self.assertEqual(len(w), 1) + self.assertIsInstance(w[0].message, PendingDeprecationWarning) + self.assertEqual(str(w[0].message), expected) + self.assertTrue(checker.called) + else: + self.assertNotEqual(len(w), 1) + self.assertFalse(checker.called) + if __name__ == '__main__': unittest.main() |