示例#1
0
def test_get_signature():
    def f(a, b):
        pass

    def f2(b, a):
        pass

    assert 'a,b||' == get_signature(f) == get_signature(f2) == get_signature(
        lambda a, b: None)
    assert 'a,b||' == f.__tri_declarative_signature
示例#2
0
def test_get_signature_description():
    assert 'a,b||' == get_signature(lambda a, b: None)
    assert 'a,b,c|d,e|' == get_signature(lambda a, b, c, d=None, e=None: None)
    assert 'c,d|a,b|' == get_signature(lambda d, c, b=None, a=None: None)
    assert 'a,b|c,d|*' == get_signature(lambda a, b, c=None, d=None, **_: None)
    assert 'c,d|a,b|*' == get_signature(lambda d, c, b=None, a=None, **_: None)
    assert '||*' == get_signature(lambda **_: None)
示例#3
0
def test_get_signature_varargs():
    assert "a,b||*" == get_signature(lambda a, b, **c: None)
示例#4
0
def test_get_signature_fails_on_native():
    # isinstance will return False for a native function. A string will also return False.
    f = 'this is not a function'
    assert None is get_signature(f)
示例#5
0
def test_early_return_from_get_signature():
    def foo(a, b, c):
        pass

    object.__setattr__(foo, '__tri_declarative_signature', 'foobar')
    assert get_signature(foo) == 'foobar'
示例#6
0
def test_get_signature_on_namespace_does_not_modify_its_contents():
    foo = Namespace()
    get_signature(foo)
    assert str(foo) == 'Namespace()'