test_functions.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pyta 作者: pyta-uoft 项目源码 文件源码
def test_user_defined_annotated_call_wrong_arguments_type():
    """ User tries to call an annotated user-defined function on the wrongly-typed arguments.
    """
    program = f'def add_3(num1: int, num2: int, num3: int) -> int:\n' \
              f'    return num1 + num2 + num3\n' \
              f'\n' \
              f'add_3(1, "bob", 1.0)\n'
    try:
        module, inferer = cs._parse_text(program)
    except:
        raise SkipTest()
    call_node = list(module.nodes_of_class(astroid.Call))[0]
    expected_msg = f'In the Call node in line 4, there was an error in calling the annotated function "add_3":\n' \
                   f'in parameter (2), the annotated type is int but was given an object of type str.\n' \
                   f'in parameter (3), the annotated type is int but was given an object of type float.\n'
    assert call_node.type_constraints.type.msg == expected_msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号