def test_non_annotated_function_call_bad_arguments():
""" User tries to call a non-annotated function on arguments of the wrong type.
"""
program = f'def add_num(num1, num2):\n' \
f' return num1 + num2\n' \
f'\n' \
f'add_num("bob", 1.0)\n'
try:
module, inferer = cs._parse_text(program)
except:
raise SkipTest()
call_node = next(module.nodes_of_class(astroid.Call))
expected_msg = f'In the Call node in line 4, there was an error in calling the function "add_num":\n' \
f'in parameter (1), the function was expecting an object of inferred type ' \
f'int but was given an object of type str.\n' \
f'in parameter (1), the function was expecting an object of inferred type ' \
f'int but was given an object of type float.\n'
# TODO: should we use the term inferred?
assert call_node.type_constraints.type.msg == expected_msg
评论列表
文章目录