How to use the pylint.testutils.Message function in pylint

To help you get started, we’ve selected a few pylint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyCQA / pylint / test / unittest_checker_python3.py View on Github external
def test_relative_from_import(self):
        node = test_utils.extract_node('from os import path  #@')
        message = testutils.Message('no-absolute-import', node=node)
        with self.assertAddsMessages(message):
            self.checker.visit_import(node)
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
'''function foo ...

            Args:
                xarg1 (int): bla xarg
                yarg (float): bla yarg

                zarg1 (str): bla zarg
            '''
            return xarg + yarg
        """
        )
        with self.assertAddsMessages(
            Message(msg_id="missing-param-doc", node=node, args=("xarg, zarg",)),
            Message(msg_id="missing-type-doc", node=node, args=("xarg, zarg",)),
            Message(msg_id="differing-param-doc", node=node, args=("xarg1, zarg1",)),
            Message(msg_id="differing-type-doc", node=node, args=("xarg1, zarg1",)),
        ):
            self.checker.visit_functiondef(node)

        node = astroid.extract_node(
            """
        def function_foo(xarg, yarg):
            '''function foo ...

            Args:
                yarg1 (float): bla yarg

            For the other parameters, see bla.
            '''
            return xarg + yarg
        """
        )
github PyCQA / pylint / tests / extensions / test_check_raise_docs.py View on Github external
def my_func(self):
            """This is a docstring.

            :raises NameError: Never
            """
            def ex_func(val):
                def inner_func(value):
                    return OSError(value)
                return RuntimeError(val)
            raise ex_func('hi') #@
            raise NameError('hi')
        '''
        )
        node = raise_node.frame()
        with self.assertAddsMessages(
            Message(msg_id="missing-raises-doc", node=node, args=("RuntimeError",))
        ):
            # we do NOT expect a warning about the OSError in inner_func!
            self.checker.visit_raise(raise_node)
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
"""
        func_node, node = astroid.extract_node(
            """
        class Foo(object):
            def foo(self): #@
                '''int: docstring ...

                Raises:
                    RuntimeError: Always
                '''
                raise RuntimeError()
                return 10 #@
        """
        )
        with self.assertAddsMessages(
            Message(msg_id="missing-return-doc", node=func_node),
            Message(msg_id="missing-return-type-doc", node=func_node),
        ):
            self.checker.visit_return(node)
github nelfin / pylint-protobuf / tests / test_repeated.py View on Github external
def test_missing_field_on_repeated_warns(self):
        node = astroid.extract_node("""
        import repeated_pb2

        outer = repeated_pb2.Outer()
        inner = outer.items.add()
        inner.invalid_field = 123  #@
        """)
        message = pylint.testutils.Message(
            'protobuf-undefined-attribute',
            node=node.targets[0], args=('invalid_field', 'Inner')
        )
        with self.assertAddsMessages(message):
            self.walk(node.root())
github PyCQA / pylint / tests / unittest_checker_typecheck.py View on Github external
def test_nomember_on_c_extension_error_msg(self):
        node = astroid.extract_node(
            """
        from coverage import tracer
        tracer.CTracer  #@
        """
        )
        message = Message(
            "no-member", node=node, args=("Module", "coverage.tracer", "CTracer", "")
        )
        with self.assertAddsMessages(message):
            self.checker.visit_attribute(node)
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
documentation in a Sphinx style docstring
        """
        func_node, node = astroid.extract_node(
            """
        class Foo(object):
            def foo(self): #@
                '''docstring ...

                :type: int
                '''
                return 10 #@
        """
        )
        with self.assertAddsMessages(
            Message(msg_id="missing-return-doc", node=func_node),
            Message(msg_id="missing-return-type-doc", node=func_node),
        ):
            self.checker.visit_return(node)
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
class ClassFoo(object):
            def __init__(self, x, y):
                '''docstring foo constructor

                :param y: bla

                missing constructor parameter documentation
                '''

                pass

        """
        )
        constructor_node = node.body[0]
        with self.assertAddsMessages(
            Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
            Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
        ):
            self._visit_methods_of_class(node)
github PyCQA / pylint / test / unittest_checker_logging.py View on Github external
def test_nonstandard_logging_module(self):
        stmts = test_utils.extract_node("""
        from my import logging as blogging #@
        blogging.warn('%s' % '%s')  #@
        """)
        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])
github PyCQA / pylint / test / unittest_checker_python3.py View on Github external
def test_dict_iter_method(self):
        for meth in ('keys', 'values', 'items'):
            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)