Exemplo n.º 1
0
def test_subclass_as_annotation_for_fixed_pos_arg_raises():
    # noinspection PyUnusedLocal
    def cb(i: ABar):
        pytest.fail()

    with pytest.raises(FunctionSignatureInvalid) as ex:
        call_with_args(cb, {type(None): None}, fixed_pos_args=(AFoo(), ))

    assert ex.match(r".*should always be a supertype.*")
Exemplo n.º 2
0
def test_union_type_raises_for_multiple_possibilities():
    def cb(a: Union[int, str]):
        assert isinstance(a, int)

    with pytest.raises(ValueError) as ex:
        call_with_args(cb, {int: 1, str: "str"})

    assert ex.match(
        r".*Found more than one possible target for parameter.*a: Union.*")
Exemplo n.º 3
0
def test_not_enough_fixed_pos_args_raises():
    # noinspection PyUnusedLocal
    def cb(a: int):
        pytest.fail()

    with pytest.raises(FunctionSignatureInvalid) as ex:
        call_with_args(cb, {AFoo: None}, fixed_pos_args=(3, 4))

    assert ex.match(r".*Expected at least 2 parameters.*")
Exemplo n.º 4
0
def test_with_fixed_positional_args():
    a = AFoo()
    b = BFoo()

    def callback(i: int, a: AFoo, b: BFoo) -> None:
        assert i == 3
        assert type(a) == AFoo
        assert type(b) == BFoo

    call_with_args(callback, {type(a): a, type(b): b}, fixed_pos_args=(3, ))
Exemplo n.º 5
0
def test_simple():
    a = AFoo()
    b = BFoo()

    def callback(a: AFoo, b: BFoo) -> int:
        assert type(a) == AFoo
        assert type(b) == BFoo
        return 1

    res = call_with_args(callback, {type(a): a, type(b): b})
    assert res == 1
Exemplo n.º 6
0
def test_run():
    call_with_args(user_defined_callback, available_args,
                   fixed_positional_arguments)
Exemplo n.º 7
0
def test_union_type_injects_only_possibility_int():
    def cb(a: Union[int, str]):
        assert isinstance(a, int)

    call_with_args(cb, {int: 1})
Exemplo n.º 8
0
def test_superclass_as_annotation_for_fixed_pos_arg_is_passed():
    def cb(i: AFoo):
        assert isinstance(i, ABar)

    call_with_args(cb, {type(None): None}, fixed_pos_args=(ABar(), ))