Exemple #1
0
    def test_get_args_of_function(self):
        function_txt = b"""def _mock_function(arg1, arg2):
                      pass"""

        ast_node = ast.walk(ast.parse(function_txt))
        function_node = [n for n in ast_node if isinstance(n, ast.FunctionDef)]
        args_list = python_utils.get_args_of_function(function_node[0], [])
        self.assertEqual(args_list, ['arg1', 'arg2'])
Exemple #2
0
    def argument_names(self):
        """Returns the names of the job's arguments.

        Returns:
            list(str). The names of the job's arguments.
        """
        # We don't want to include 'self' in the list; run() being a method
        # should be considered an implementation detail.
        return python_utils.get_args_of_function(self._job_class.run)[1:]
    def get_args_list_from_function_definition(cls, function_node):
        """Extracts the arguments from a function definition.
        Ignores class specific arguments (self and cls).

        Args:
            function_node: ast.FunctionDef. Represents a function.

        Returns:
            list(str). The args for a function as listed in the function
            definition.
        """
        # Ignore self and cls args.
        args_to_ignore = ['self', 'cls']
        return python_utils.get_args_of_function(function_node, args_to_ignore)
    def test_get_args_of_function(self):
        def func(a, b, *c, **d):  # pylint: disable=unused-argument
            """Does nothing."""
            pass

        self.assertEqual(python_utils.get_args_of_function(func), ['a', 'b'])