예제 #1
0
def test_tail_injector_correctly_injects_class():
    @inject(target=cls24, injector=TailInjector())
    def handler():
        x = 11

    assert cls24.x == 11
    assert cls24().x == 11
def test_tail_injector_correctly_injects_async_function():
    async def target(x):
        if x > 100:
            return x

    @inject(target=target, injector=TailInjector())
    def handler():
        return -1

    assert run(target(13)) == -1
    assert run(target(101)) == 101
예제 #3
0
def test_tail_injector_correctly_injects_method():
    class Target:
        def target(self, x):
            if x > 100:
                return x

    @inject(target=Target.target, injector=TailInjector())
    def handler():
        return -1

    target = Target()
    assert target.target(13) == -1
    assert target.target(101) == 101
def test_nested_injector_correctly_injects_nested_sync_function_async_nested():
    async def target(x):
        async def nested(y):
            if y > 100:
                return y

        if x < 200:
            return await nested(x)

    @inject(target=target, injector=NestedInjector('nested', TailInjector()))
    def handler():
        return -1

    assert run(target(13)) == -1
    assert run(target(101)) == 101
    assert run(target(200)) is None
예제 #5
0
def test_nested_injector_correctly_injects_function():
    def target(x):
        def nested(y):
            if y > 100:
                return y

        if x < 200:
            return nested(x)

    @inject(target=target, injector=NestedInjector('nested', TailInjector()))
    def handler():
        return -1

    assert target(13) == -1
    assert target(101) == 101
    assert target(200) is None
예제 #6
0
def test_nested_injector_correctly_injects_method():
    class Target:
        def target(self, x):
            def nested(y):
                if y > 100:
                    return y

            if x < 200:
                return nested(x)

    @inject(target=Target.target,
            injector=NestedInjector('nested', TailInjector()))
    def handler():
        return -1

    target = Target()
    assert target.target(13) == -1
    assert target.target(101) == 101
    assert target.target(200) is None