2021-01-11 00:26:15 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2020-08-27 02:24:20 +00:00
|
|
|
from dependency_injector import providers
|
|
|
|
|
|
|
|
|
|
|
|
# Test 1: to check the return type
|
|
|
|
provider1 = providers.Selector(
|
2021-10-01 00:09:42 +00:00
|
|
|
lambda: "a",
|
2020-08-27 02:24:20 +00:00
|
|
|
a=providers.Factory(object),
|
|
|
|
b=providers.Factory(object),
|
|
|
|
)
|
2021-01-11 00:26:15 +00:00
|
|
|
var1: Any = provider1()
|
2020-08-27 02:24:20 +00:00
|
|
|
|
|
|
|
# Test 2: to check the provided instance interface
|
|
|
|
provider2 = providers.Selector(
|
2021-10-01 00:09:42 +00:00
|
|
|
lambda: "a",
|
2020-08-27 02:24:20 +00:00
|
|
|
a=providers.Factory(object),
|
|
|
|
b=providers.Factory(object),
|
|
|
|
)
|
|
|
|
provided2: providers.ProvidedInstance = provider2.provided
|
|
|
|
attr_getter2: providers.AttributeGetter = provider2.provided.attr
|
2021-10-01 00:09:42 +00:00
|
|
|
item_getter2: providers.ItemGetter = provider2.provided["item"]
|
2020-08-27 02:24:20 +00:00
|
|
|
method_caller2: providers.MethodCaller = provider2.provided.method.call(123, arg=324)
|
|
|
|
|
|
|
|
# Test3 to check the getattr
|
|
|
|
provider3 = providers.Selector(
|
2021-10-01 00:09:42 +00:00
|
|
|
lambda: "a",
|
2020-08-27 02:24:20 +00:00
|
|
|
a=providers.Factory(object),
|
|
|
|
b=providers.Factory(object),
|
|
|
|
)
|
|
|
|
attr3: providers.Provider = provider3.a
|
2021-01-11 00:26:15 +00:00
|
|
|
|
|
|
|
# Test 4: to check the return type with await
|
|
|
|
provider4 = providers.Selector(
|
2021-10-01 00:09:42 +00:00
|
|
|
lambda: "a",
|
2021-01-11 00:26:15 +00:00
|
|
|
a=providers.Factory(object),
|
|
|
|
b=providers.Factory(object),
|
|
|
|
)
|
|
|
|
async def _async4() -> None:
|
|
|
|
var1: Any = await provider4() # type: ignore
|
|
|
|
var2: Any = await provider4.async_()
|