def test_function_def_args_simple_return(function_name, arguments):
"""Test whether visitor was able to infer type of function given function called on it's arguments."""
assume(function_name not in arguments)
for argument in arguments:
program = _parse_to_function_no_return(function_name, arguments, ('return ' + argument + " + " + repr('bob')))
module, inferer = cs._parse_text(program)
function_def_node = next(module.nodes_of_class(astroid.FunctionDef))
expected_arg_type_vars = [function_def_node.type_environment.lookup_in_env(argument) for argument in arguments]
expected_arg_types = [inferer.type_constraints.lookup_concrete(type_var) for type_var in expected_arg_type_vars]
function_type_var = module.type_environment.lookup_in_env(function_name)
function_type = inferer.type_constraints.lookup_concrete(function_type_var)
actual_arg_types, actual_return_type = inferer.type_constraints.types_in_callable(function_type)
return_type_var = function_def_node.type_environment.lookup_in_env(argument)
expected_return_type = inferer.type_constraints.lookup_concrete(return_type_var)
assert Callable[actual_arg_types, actual_return_type] == Callable[expected_arg_types, expected_return_type]
评论列表
文章目录