예제 #1
0
def test_typed_arg_varg():
    def func(arg: str, *args: int):
        return arg, args

    assert typic.bind(func, 1).eval() == typic.bind(func,
                                                    arg=1).eval() == ("1", ())
    assert typic.bind(func, 1, "1").eval() == ("1", (1, ))
예제 #2
0
def test_typed_arg_varg_kwarg():
    def func(arg: str, *args: int, **kwargs: str):
        return arg, args, kwargs

    assert typic.bind(func, 1).eval() == typic.bind(
        func, arg=1).eval() == ("1", (), {})
    assert typic.bind(func, 1, "1").eval() == ("1", (1, ), {})
    assert typic.bind(func, 1, "1", k=1).eval() == ("1", (1, ), {"k": "1"})
예제 #3
0
def test_typed_arg_kwarg():
    def func(arg: str, **kwargs: str):
        return arg, kwargs

    assert typic.bind(func, 1).eval() == typic.bind(func,
                                                    arg=1).eval() == ("1", {})
    assert (typic.bind(func, 1, k=1).eval() == typic.bind(
        func, k=1, arg=1).eval() == ("1", {
            "k": "1"
        }))
예제 #4
0
def test_bind():
    sig = inspect.signature(foo)
    args, kwargs = (1, 2), {"kwd": "kwd", "kwarg": "kwarg"}
    builtin: inspect.BoundArguments = sig.bind(*args, **kwargs)
    baked = typic.bind(foo, *args, **kwargs)
    assert builtin.kwargs == baked.kwargs
    assert builtin.args == baked.args
예제 #5
0
def test_bind_errors(func, params):
    args, kwargs = params
    with pytest.raises(TypeError):
        typic.bind(func, *args, **kwargs)
예제 #6
0
def test_typed_no_coerce():
    bound = typic.bind(typed, 1, coerce=False)
    assert bound.arguments["arg"] == 1
예제 #7
0
def test_typed_args_kwd():
    def func(*args: int, kwd: str):
        return args, kwd

    assert typic.bind(func, "1", kwd=1).eval() == ((1, ), "1")
예제 #8
0
def test_typed_kwarg():
    def func(**kwargs: str):
        return kwargs

    assert typic.bind(func).eval() == {}
    assert typic.bind(func, k=1).eval() == {"k": "1"}
예제 #9
0
def test_typed_varg():
    def func(*args: str):
        return args

    assert typic.bind(func).eval() == ()
    assert typic.bind(func, 1).eval() == ("1", )
예제 #10
0
def test_typed_arg():
    def func(arg: str):
        return arg

    assert typic.bind(func, 1).eval() == typic.bind(func, arg=1).eval() == "1"