How to use the hacking.checks.mock_checks.FunctionNameFinder function in hacking

To help you get started, we’ve selected a few hacking 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 openstack / hacking / hacking / checks / mock_checks.py View on Github external
def check_missing_autospec(self, call_node):

        def find_autospec_keyword(keyword_node):
            for keyword_obj in keyword_node:
                keyword = keyword_obj.arg
                # If they have defined autospec or new then it is okay
                if keyword in self.spec_keywords:
                    return True
            return False

        if isinstance(call_node, ast.Call):
            func_info = FunctionNameFinder(self.filename)
            func_info.visit(call_node)

            # We are only looking at our patchers
            if func_info.function_name not in self.patchers:
                return

            min_args = self.patchers[func_info.function_name]

            if not find_autospec_keyword(call_node.keywords):
                if len(call_node.args) < min_args:
                    self.messages.append(
                        (call_node.lineno, call_node.col_offset,
                         "H210 Missing 'autospec' or 'spec_set' keyword in "
                         "mock.patch/mock.patch.object", MockCheckVisitor)
                    )
github openstack / hacking / hacking / checks / mock_checks.py View on Github external
def visit(self, node):
        # If we get called with an ast.Call node, then work on the 'node.func',
        # as we want the function name.
        if isinstance(node, ast.Call):
            return super(FunctionNameFinder, self).visit(node.func)
        return super(FunctionNameFinder, self).visit(node)