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
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
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