def test_copy_argspec_validates_arguments():
    with pytest.raises(ValueError):
        copy_argspec(
            u'hello_world',
            inspect.ArgSpec(args=[u'a b'],
                            varargs=None,
                            keywords=None,
                            defaults=None))
def test_copy_argspec_validates_function_name():
    with raises(ValueError):
        copy_argspec(
            'hello world',
            ArgSpec(args=['a', 'b'],
                    varargs=None,
                    keywords=None,
                    defaults=None))
def test_copy_argspec_validates_function_name():
    with pytest.raises(ValueError):
        copy_argspec(
            u'hello world',
            inspect.ArgSpec(args=[u'a', u'b'],
                            varargs=None,
                            keywords=None,
                            defaults=None))
def test_copy_argspec_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    copy_argspec(
        u'hello',
        inspect.ArgSpec(args=(u'f', ),
                        varargs=None,
                        keywords=None,
                        defaults=None))(accepts_everything)(1)

    copy_argspec(
        u'hello',
        inspect.ArgSpec(args=(), varargs=u'f', keywords=None,
                        defaults=None))(accepts_everything)(1)

    copy_argspec(
        u'hello',
        inspect.ArgSpec(args=(), varargs=None, keywords=u'f',
                        defaults=None))(accepts_everything)()

    copy_argspec(
        u'hello',
        inspect.ArgSpec(args=(u'f', u'f_3'),
                        varargs=u'f_1',
                        keywords=u'f_2',
                        defaults=None))(accepts_everything)(1, 2)
def test_copying_preserves_argspec(f):
    af = inspect.getargspec(f)
    t = copy_argspec('foo', inspect.getargspec(f))(universal_acceptor)
    at = inspect.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 ())
def test_copying_preserves_argspec(f):
    af = inspect.getargspec(f)
    t = copy_argspec(u'foo', inspect.getargspec(f))(universal_acceptor)
    at = inspect.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 ())
def test_copying_preserves_argspec():
    for f in [has_one_arg, has_two_args, has_varargs, has_kwargs]:
        af = getargspec(f)
        t = copy_argspec('foo', 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 ())
def test_copying_preserves_argspec():
    for f in [has_one_arg, has_two_args, has_varargs, has_kwargs]:
        af = getargspec(f)
        t = copy_argspec('foo', 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 ())
def test_copy_argspec_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    copy_argspec(u"hello", ArgSpec(args=(u"f",), varargs=None, keywords=None, defaults=None))(accepts_everything)(1)

    copy_argspec(u"hello", ArgSpec(args=(), varargs=u"f", keywords=None, defaults=None))(accepts_everything)(1)

    copy_argspec(u"hello", ArgSpec(args=(), varargs=None, keywords=u"f", defaults=None))(accepts_everything)()

    copy_argspec(u"hello", ArgSpec(args=(u"f", u"f_3"), varargs=u"f_1", keywords=u"f_2", defaults=None))(
        accepts_everything
    )(1, 2)
def test_copy_argspec_works_with_conflicts():
    def accepts_everything(*args, **kwargs):
        pass

    copy_argspec('hello', inspect.ArgSpec(
        args=('f',), varargs=None, keywords=None, defaults=None
    ))(accepts_everything)(1)

    copy_argspec('hello', inspect.ArgSpec(
        args=(), varargs='f', keywords=None, defaults=None
    ))(accepts_everything)(1)

    copy_argspec('hello', inspect.ArgSpec(
        args=(), varargs=None, keywords='f', defaults=None
    ))(accepts_everything)()

    copy_argspec('hello', inspect.ArgSpec(
        args=('f', 'f_3'), varargs='f_1', keywords='f_2', defaults=None
    ))(accepts_everything)(1, 2)
def test_uses_defaults():
    f = copy_argspec(
        'foo', inspect.getargspec(has_a_default))(universal_acceptor)
    assert f(3, 2) == ((3, 2, 1), {})
def test_copying_sets_name():
    f = copy_argspec(u"hello_world", getargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == u"hello_world"
def test_copying_sets_name():
    f = copy_argspec(
        'hello_world', inspect.getargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == 'hello_world'
def test_copy_argspec_validates_function_name():
    with pytest.raises(ValueError):
        copy_argspec(u"hello world", ArgSpec(args=[u"a", u"b"], varargs=None, keywords=None, defaults=None))
def test_copy_argspec_validates_arguments():
    with pytest.raises(ValueError):
        copy_argspec(u"hello_world", ArgSpec(args=[u"a b"], varargs=None, keywords=None, defaults=None))
def test_copy_argspec_validates_arguments():
    with raises(ValueError):
        copy_argspec('hello_world', ArgSpec(
            args=['a b'], varargs=None, keywords=None, defaults=None))
Exemple #17
0
def test_uses_varargs():
    f = copy_argspec(u'foo',
                     inspect.getargspec(has_varargs))(universal_acceptor)
    assert f(1, 2) == ((1, 2), {})
Exemple #18
0
def test_passes_args_as_keyword():
    f = copy_argspec(
        'foo', inspect.getargspec(has_two_args))(universal_acceptor)
    assert f(1, 2) == ((), {'hello': 1, 'world': 2})
def test_copy_argspec_validates_arguments():
    with pytest.raises(ValueError):
        copy_argspec('hello_world', inspect.ArgSpec(
            args=['a b'], varargs=None, keywords=None, defaults=None))
def test_uses_varargs():
    f = copy_argspec(
        'foo', inspect.getargspec(has_varargs))(universal_acceptor)
    assert f(1, 2) == ((1, 2), {})
Exemple #21
0
def test_copying_sets_name():
    f = copy_argspec(u'hello_world',
                     inspect.getargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == u'hello_world'
Exemple #22
0
def test_uses_defaults():
    f = copy_argspec(u'foo',
                     inspect.getargspec(has_a_default))(universal_acceptor)
    assert f(3, 2) == ((3, 2, 1), {})
def test_copy_argspec_validates_function_name():
    with pytest.raises(ValueError):
        copy_argspec('hello world', inspect.ArgSpec(
            args=['a', 'b'], varargs=None, keywords=None, defaults=None))
Exemple #24
0
def test_uses_defaults():
    f = copy_argspec(
        'foo', inspect.getargspec(has_a_default))(universal_acceptor)
    assert f(3, 2) == ((), {'z': 1, 'x': 3, 'y': 2})