File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from typing import Any
2+ from unittest .mock import patch
3+
4+ from taskiq_dependencies import DependencyGraph
5+
6+
7+ class MyFastapiDepends :
8+ def __init__ (self , dependency : Any , use_cache : bool = False ) -> None :
9+ self .dependency = dependency
10+ self .use_cache = use_cache
11+
12+
13+ def test_dependency_swap () -> None :
14+ """
15+ Test that dependency classes are swapped.
16+
17+ This test checks that if function depends on FastAPI depends, it will
18+ be swapped and resolved.
19+ """
20+ with patch ("taskiq_dependencies.graph.FastapiDepends" , MyFastapiDepends ):
21+
22+ def func_a () -> int :
23+ return 1
24+
25+ def func_b (dep_a : int = MyFastapiDepends (func_a )) -> int : # type: ignore
26+ return dep_a
27+
28+ with DependencyGraph (func_b ).sync_ctx () as ctx :
29+ kwargs = ctx .resolve_kwargs ()
30+
31+ assert kwargs == {"dep_a" : 1 }
You can’t perform that action at this time.
0 commit comments