Ejemplo n.º 1
0
def test_define_function_signature_validates_function_name():
    with raises(ValueError):
        define_function_signature(
            'hello world', None,
            ArgSpec(args=['a', 'b'],
                    varargs=None,
                    keywords=None,
                    defaults=None))
Ejemplo n.º 2
0
def test_define_function_signature_validates_function_name():
    with raises(ValueError):
        define_function_signature(
            'hello world', None,
            FullArgSpec(args=['a', 'b'],
                        varargs=None,
                        varkw=None,
                        defaults=None,
                        kwonlyargs=[],
                        kwonlydefaults=None,
                        annotations={}))
Ejemplo n.º 3
0
def test_define_function_signature_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    define_function_signature(
        'hello', 'A docstring for hello',
        ArgSpec(args=('f', ), varargs=None, keywords=None,
                defaults=None))(accepts_everything)(1)

    define_function_signature(
        'hello', 'A docstring for hello',
        ArgSpec(args=(), varargs='f', keywords=None,
                defaults=None))(accepts_everything)(1)

    define_function_signature(
        'hello', 'A docstring for hello',
        ArgSpec(args=(), varargs=None, keywords='f',
                defaults=None))(accepts_everything)()

    define_function_signature(
        'hello', 'A docstring for hello',
        ArgSpec(args=('f', 'f_3'),
                varargs='f_1',
                keywords='f_2',
                defaults=None))(accepts_everything)(1, 2)
Ejemplo n.º 4
0
def test_define_function_signature_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    define_function_signature(
        "hello",
        "A docstring for hello",
        FullArgSpec(
            args=("f", ),
            varargs=None,
            varkw=None,
            defaults=None,
            kwonlyargs=[],
            kwonlydefaults=None,
            annotations={},
        ),
    )(accepts_everything)(1)

    define_function_signature(
        "hello",
        "A docstring for hello",
        FullArgSpec(
            args=(),
            varargs="f",
            varkw=None,
            defaults=None,
            kwonlyargs=[],
            kwonlydefaults=None,
            annotations={},
        ),
    )(accepts_everything)(1)

    define_function_signature(
        "hello",
        "A docstring for hello",
        FullArgSpec(
            args=(),
            varargs=None,
            varkw="f",
            defaults=None,
            kwonlyargs=[],
            kwonlydefaults=None,
            annotations={},
        ),
    )(accepts_everything)()

    define_function_signature(
        "hello",
        "A docstring for hello",
        FullArgSpec(
            args=("f", "f_3"),
            varargs="f_1",
            varkw="f_2",
            defaults=None,
            kwonlyargs=[],
            kwonlydefaults=None,
            annotations={},
        ),
    )(accepts_everything)(1, 2)
Ejemplo n.º 5
0
def test_define_function_signature_validates_arguments():
    with raises(ValueError):
        define_function_signature(
            "hello_world",
            None,
            FullArgSpec(
                args=["a b"],
                varargs=None,
                varkw=None,
                defaults=None,
                kwonlyargs=[],
                kwonlydefaults=None,
                annotations={},
            ),
        )
Ejemplo n.º 6
0
def test_copying_preserves_argspec(f):
    af = getargspec(f)
    t = define_function_signature(
        'foo', 'docstring', getargspec(f))(universal_acceptor)
    at = getargspec(t)
    assert af.args == at.args
    assert af.varargs == at.varargs
    assert af.keywords == at.keywords
    assert len(af.defaults or ()) == len(at.defaults or ())
Ejemplo n.º 7
0
def test_copying_preserves_argspec(f):
    af = getfullargspec(f)
    t = define_function_signature('foo', 'docstring', af)(universal_acceptor)
    at = getfullargspec(t)
    assert af.args == at.args
    assert af.varargs == at.varargs
    assert af.varkw == at.varkw
    assert len(af.defaults or ()) == len(at.defaults or ())
    assert af.kwonlyargs == at.kwonlyargs
    assert af.kwonlydefaults == at.kwonlydefaults
    assert af.annotations == at.annotations
def test_copying_preserves_argspec(f):
    af = getfullargspec(f)
    t = define_function_signature('foo', 'docstring', af)(universal_acceptor)
    at = getfullargspec(t)
    assert af.args == at.args[:len(af.args)]
    assert af.varargs == at.varargs
    assert af.varkw == at.varkw
    assert len(af.defaults or ()) == len(at.defaults or ())
    assert af.kwonlyargs == at.kwonlyargs
    assert af.kwonlydefaults == at.kwonlydefaults
    assert af.annotations == at.annotations
Ejemplo n.º 9
0
def define_copy_method(name):
    target = getattr(Random, name)

    def implementation(self, **kwargs):
        result = self._hypothesis_do_random(name, kwargs)
        self._hypothesis_log_random(name, kwargs, result)
        return result

    spec = inspect.getfullargspec(STUBS.get(name, target))

    result = define_function_signature(target.__name__, target.__doc__,
                                       spec)(implementation)

    result.__module__ = __name__
    result.__qualname__ = "HypothesisRandom." + result.__name__

    setattr(HypothesisRandom, name, result)
Ejemplo n.º 10
0
def test_define_function_signature_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    define_function_signature(
        'hello', 'A docstring for hello',
        FullArgSpec(args=('f', ),
                    varargs=None,
                    varkw=None,
                    defaults=None,
                    kwonlyargs=[],
                    kwonlydefaults=None,
                    annotations={}))(accepts_everything)(1)

    define_function_signature(
        'hello', 'A docstring for hello',
        FullArgSpec(args=(),
                    varargs='f',
                    varkw=None,
                    defaults=None,
                    kwonlyargs=[],
                    kwonlydefaults=None,
                    annotations={}))(accepts_everything)(1)

    define_function_signature(
        'hello', 'A docstring for hello',
        FullArgSpec(args=(),
                    varargs=None,
                    varkw='f',
                    defaults=None,
                    kwonlyargs=[],
                    kwonlydefaults=None,
                    annotations={}))(accepts_everything)()

    define_function_signature(
        'hello', 'A docstring for hello',
        FullArgSpec(args=('f', 'f_3'),
                    varargs='f_1',
                    varkw='f_2',
                    defaults=None,
                    kwonlyargs=[],
                    kwonlydefaults=None,
                    annotations={}))(accepts_everything)(1, 2)
Ejemplo n.º 11
0
def test_define_function_signature_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    define_function_signature('hello', 'A docstring for hello', FullArgSpec(
        args=('f',), varargs=None, varkw=None, defaults=None,
        kwonlyargs=[], kwonlydefaults=None, annotations={}
    ))(accepts_everything)(1)

    define_function_signature('hello', 'A docstring for hello', FullArgSpec(
        args=(), varargs='f', varkw=None, defaults=None,
        kwonlyargs=[], kwonlydefaults=None, annotations={}
    ))(accepts_everything)(1)

    define_function_signature('hello', 'A docstring for hello', FullArgSpec(
        args=(), varargs=None, varkw='f', defaults=None,
        kwonlyargs=[], kwonlydefaults=None, annotations={}
    ))(accepts_everything)()

    define_function_signature('hello', 'A docstring for hello', FullArgSpec(
        args=('f', 'f_3'), varargs='f_1', varkw='f_2', defaults=None,
        kwonlyargs=[], kwonlydefaults=None, annotations={}
    ))(accepts_everything)(1, 2)
Ejemplo n.º 12
0
def test_uses_varargs():
    f = define_function_signature(
        "foo", "A docstring for foo",
        getfullargspec(has_varargs))(universal_acceptor)
    assert f(1, 2) == ((1, 2), {})
Ejemplo n.º 13
0
def test_uses_defaults():
    f = define_function_signature(
        "foo", "A docstring for foo",
        getfullargspec(has_a_default))(universal_acceptor)
    assert f(3, 2) == ((3, 2, 1), {})
Ejemplo n.º 14
0
def test_copying_sets_docstring():
    f = define_function_signature(
        "foo", "A docstring for foo",
        getfullargspec(has_two_args))(universal_acceptor)
    assert f.__doc__ == "A docstring for foo"
Ejemplo n.º 15
0
def test_copying_sets_name():
    f = define_function_signature(
        "hello_world", "A docstring for hello_world",
        getfullargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == "hello_world"
Ejemplo n.º 16
0
def test_copying_sets_docstring():
    f = define_function_signature(
        'foo', 'A docstring for foo',
        getfullargspec(has_two_args))(universal_acceptor)
    assert f.__doc__ == 'A docstring for foo'
Ejemplo n.º 17
0
def test_define_function_signature_validates_function_name():
    with raises(ValueError):
        define_function_signature('hello world', None, FullArgSpec(
            args=['a', 'b'], varargs=None, varkw=None, defaults=None,
            kwonlyargs=[], kwonlydefaults=None, annotations={}))
Ejemplo n.º 18
0
def test_uses_varargs():
    f = define_function_signature(
        'foo', 'A docstring for foo',
        getfullargspec(has_varargs))(universal_acceptor)
    assert f(1, 2) == ((1, 2), {})
Ejemplo n.º 19
0
def test_uses_defaults():
    f = define_function_signature(
        'foo', 'A docstring for foo',
        getfullargspec(has_a_default))(universal_acceptor)
    assert f(3, 2) == ((3, 2, 1), {})
Ejemplo n.º 20
0
def test_copying_sets_docstring():
    f = define_function_signature(
        'foo', 'A docstring for foo',
        getargspec(has_two_args))(universal_acceptor)
    assert f.__doc__ == 'A docstring for foo'
Ejemplo n.º 21
0
def test_copying_sets_name():
    f = define_function_signature(
        'hello_world', 'A docstring for hello_world',
        getfullargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == 'hello_world'