Пример #1
0
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))
Пример #2
0
def test_copy_argspec_validates_function_name():
    with raises(ValueError):
        copy_argspec(
            'hello world',
            ArgSpec(args=['a', 'b'],
                    varargs=None,
                    keywords=None,
                    defaults=None))
Пример #3
0
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))
Пример #4
0
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)
Пример #5
0
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 ())
Пример #6
0
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 ())
Пример #7
0
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 ())
Пример #8
0
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 ())
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
def test_uses_defaults():
    f = copy_argspec(
        'foo', inspect.getargspec(has_a_default))(universal_acceptor)
    assert f(3, 2) == ((3, 2, 1), {})
Пример #12
0
def test_copying_sets_name():
    f = copy_argspec(u"hello_world", getargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == u"hello_world"
Пример #13
0
def test_copying_sets_name():
    f = copy_argspec(
        'hello_world', inspect.getargspec(has_two_args))(universal_acceptor)
    assert f.__name__ == 'hello_world'
Пример #14
0
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))
Пример #15
0
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))
Пример #16
0
def test_copy_argspec_validates_arguments():
    with raises(ValueError):
        copy_argspec('hello_world', ArgSpec(
            args=['a b'], varargs=None, keywords=None, defaults=None))
Пример #17
0
def test_uses_varargs():
    f = copy_argspec(u'foo',
                     inspect.getargspec(has_varargs))(universal_acceptor)
    assert f(1, 2) == ((1, 2), {})
Пример #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})
Пример #19
0
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))
Пример #20
0
def test_uses_varargs():
    f = copy_argspec(
        'foo', inspect.getargspec(has_varargs))(universal_acceptor)
    assert f(1, 2) == ((1, 2), {})
Пример #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'
Пример #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), {})
Пример #23
0
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))
Пример #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})