Пример #1
0
def test_only_defaults():
    def foo(a='val_a', b='val_b'):
        assert a == 'val_a'
        assert b == 'val_b'

    scope = Scope()
    scope.inject_and_call(foo)
Пример #2
0
def test_call_simple():
    def foo(a, b, c='xx'):
        assert a == 'val_a'
        assert b == 'val_b'
        assert c == 'val_c'

    scope = Scope()

    scope.inject_and_call(foo, 'val_a', 'val_b', 'val_c')
    scope.inject_and_call(foo, b='val_b', c='val_c', a='val_a')
Пример #3
0
def test_automatic_injection():
    def foo(d, e, f):
        assert d == 'val_d'
        assert e == 'val_e'
        assert f == 'val_f'

    scope = Scope()
    scope['e'] = 'val_e'
    scope['f'] = 'val_f'

    scope.inject_and_call(foo, 'val_d')
Пример #4
0
def test_overwrite_works():
    def foo(d, e, f):
        assert d == 'val_d'
        assert e == 'val_e'
        assert f == 'val_f'

    scope = Scope()
    scope['d'] = 'bad'
    scope['e'] = 'also bad'
    scope['f'] = 'val_f'

    scope.inject_and_call(foo, 'val_d', e='val_e')