Skip to content

Commit eb905b3

Browse files
committed
Added tests with aliased variables.
Signed-off-by: Pavel Kirilin <win10@list.ru>
1 parent c60759d commit eb905b3

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

tests/test_annotated.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if sys.version_info < (3, 10):
66
pytest.skip("Annotated is available only for python 3.10+", allow_module_level=True)
77

8-
from typing import Annotated, AsyncGenerator, Generic, TypeVar
8+
from typing import Annotated, AsyncGenerator, Generic, Tuple, TypeVar
99

1010
from taskiq_dependencies import DependencyGraph, Depends
1111

@@ -74,3 +74,34 @@ def test_func(dep: Annotated[int, Depends(my_gen)]) -> int:
7474
assert value == 1
7575

7676
assert opened and closed
77+
78+
79+
def test_multiple() -> None:
80+
class TestClass:
81+
pass
82+
83+
MyType = Annotated[TestClass, Depends(use_cache=False)]
84+
85+
def test_func(dep: MyType, dep2: MyType) -> Tuple[MyType, MyType]:
86+
return dep, dep2
87+
88+
with DependencyGraph(target=test_func).sync_ctx(exception_propagation=False) as g:
89+
value = test_func(**(g.resolve_kwargs()))
90+
assert value[0] != value[1]
91+
assert isinstance(value[0], TestClass)
92+
assert isinstance(value[1], TestClass)
93+
94+
95+
def test_multiple_with_cache() -> None:
96+
class TestClass:
97+
pass
98+
99+
MyType = Annotated[TestClass, Depends()]
100+
101+
def test_func(dep: MyType, dep2: MyType) -> Tuple[MyType, MyType]:
102+
return dep, dep2
103+
104+
with DependencyGraph(target=test_func).sync_ctx(exception_propagation=False) as g:
105+
value = test_func(**(g.resolve_kwargs()))
106+
assert id(value[0]) == id(value[1])
107+
assert isinstance(value[0], TestClass)

0 commit comments

Comments
 (0)