Exemplo n.º 1
0
def test_introspect_curry_py3():
    if not PY3:
        return
    f = cytoolz.curry(make_func(""))
    assert num_required_args(f) == 0
    assert is_arity(0, f)
    assert has_varargs(f) is False
    assert has_keywords(f) is False

    f = cytoolz.curry(make_func("x"))
    assert num_required_args(f) == 0
    assert is_arity(0, f) is False
    assert is_arity(1, f) is False
    assert has_varargs(f) is False
    assert has_keywords(f)  # A side-effect of being curried

    f = cytoolz.curry(make_func("x, y, z=0"))
    assert num_required_args(f) == 0
    assert is_arity(0, f) is False
    assert is_arity(1, f) is False
    assert is_arity(2, f) is False
    assert is_arity(3, f) is False
    assert has_varargs(f) is False
    assert has_keywords(f)

    f = cytoolz.curry(make_func("*args, **kwargs"))
    assert num_required_args(f) == 0
    assert has_varargs(f)
    assert has_keywords(f)
Exemplo n.º 2
0
def test_introspect_curry_py3():
    if not PY3:
        return
    f = cytoolz.curry(make_func(''))
    assert num_required_args(f) == 0
    assert is_arity(0, f)
    assert has_varargs(f) is False
    assert has_keywords(f) is False

    f = cytoolz.curry(make_func('x'))
    assert num_required_args(f) == 0
    assert is_arity(0, f) is False
    assert is_arity(1, f) is False
    assert has_varargs(f) is False
    assert has_keywords(f)  # A side-effect of being curried

    f = cytoolz.curry(make_func('x, y, z=0'))
    assert num_required_args(f) == 0
    assert is_arity(0, f) is False
    assert is_arity(1, f) is False
    assert is_arity(2, f) is False
    assert is_arity(3, f) is False
    assert has_varargs(f) is False
    assert has_keywords(f)

    f = cytoolz.curry(make_func('*args, **kwargs'))
    assert num_required_args(f) == 0
    assert has_varargs(f)
    assert has_keywords(f)
Exemplo n.º 3
0
def test_has_varargs():
    assert has_varargs(lambda: None) is False
    assert has_varargs(lambda *args: None)
    assert has_varargs(lambda **kwargs: None) is False
    assert has_varargs(map)
    if PY3:
        assert has_varargs(max) is None
Exemplo n.º 4
0
def test_has_varargs():
    assert has_varargs(lambda: None) is False
    assert has_varargs(lambda *args: None)
    assert has_varargs(lambda **kwargs: None) is False
    assert has_varargs(map)
    if PY3:
        assert has_varargs(max) is None
Exemplo n.º 5
0
def test_introspect_curry_py3():
    f = cytoolz.curry(make_func(''))
    assert num_required_args(f) == 0
    assert is_arity(0, f)
    assert has_varargs(f) is False
    assert has_keywords(f) is False

    f = cytoolz.curry(make_func('x'))
    assert num_required_args(f) == 0
    assert is_arity(0, f) is False
    assert is_arity(1, f) is False
    assert has_varargs(f) is False
    assert has_keywords(f)  # A side-effect of being curried

    f = cytoolz.curry(make_func('x, y, z=0'))
    assert num_required_args(f) == 0
    assert is_arity(0, f) is False
    assert is_arity(1, f) is False
    assert is_arity(2, f) is False
    assert is_arity(3, f) is False
    assert has_varargs(f) is False
    assert has_keywords(f)

    f = cytoolz.curry(make_func('*args, **kwargs'))
    assert num_required_args(f) == 0
    assert has_varargs(f)
    assert has_keywords(f)
Exemplo n.º 6
0
def test_has_unknown_args():
    assert has_varargs(1) is False
    assert has_varargs(map)
    assert has_varargs(make_func("")) is False
    assert has_varargs(make_func("x, y, z")) is False
    assert has_varargs(make_func("*args"))
    assert has_varargs(make_func("**kwargs")) is False
    assert has_varargs(make_func("x, y, *args, **kwargs"))
    assert has_varargs(make_func("x, y, z=1")) is False
    assert has_varargs(make_func("x, y, z=1, **kwargs")) is False

    if PY3:
        f = make_func("*args")
        f.__signature__ = 34
        assert has_varargs(f) is False

        class RaisesValueError(object):
            def __call__(self):
                pass

            @property
            def __signature__(self):
                raise ValueError("Testing Python 3.4")

        f = RaisesValueError()
        assert has_varargs(f) is None
Exemplo n.º 7
0
def test_has_unknown_args():
    assert has_varargs(1) is False
    assert has_varargs(map)
    assert has_varargs(make_func('')) is False
    assert has_varargs(make_func('x, y, z')) is False
    assert has_varargs(make_func('*args'))
    assert has_varargs(make_func('**kwargs')) is False
    assert has_varargs(make_func('x, y, *args, **kwargs'))
    assert has_varargs(make_func('x, y, z=1')) is False
    assert has_varargs(make_func('x, y, z=1, **kwargs')) is False

    if PY3:
        f = make_func('*args')
        f.__signature__ = 34
        assert has_varargs(f) is False

        class RaisesValueError(object):
            def __call__(self):
                pass
            @property
            def __signature__(self):
                raise ValueError('Testing Python 3.4')

        f = RaisesValueError()
        assert has_varargs(f) is None
Exemplo n.º 8
0
def test_has_unknown_args():
    assert has_varargs(1) is False
    assert has_varargs(map)
    assert has_varargs(make_func('')) is False
    assert has_varargs(make_func('x, y, z')) is False
    assert has_varargs(make_func('*args'))
    assert has_varargs(make_func('**kwargs')) is False
    assert has_varargs(make_func('x, y, *args, **kwargs'))
    assert has_varargs(make_func('x, y, z=1')) is False
    assert has_varargs(make_func('x, y, z=1, **kwargs')) is False

    f = make_func('*args')
    f.__signature__ = 34
    assert has_varargs(f) is False

    class RaisesValueError(object):
        def __call__(self):
            pass

        @property
        def __signature__(self):
            raise ValueError('Testing Python 3.4')

    f = RaisesValueError()
    assert has_varargs(f) is None