-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_asfunction.py
More file actions
34 lines (23 loc) · 900 Bytes
/
test_asfunction.py
File metadata and controls
34 lines (23 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import NamedTuple
from injection import asfunction
class TestAsFunction:
def test_asfunction_with_sync_call_method(self, module):
@module.injectable
class Dependency: ...
@asfunction(module=module)
class SyncFunction(NamedTuple):
dependency: Dependency
def call(self):
return self.dependency
assert isinstance(SyncFunction(), Dependency)
async def test_asfunction_with_async_call_method(self, module):
class Dependency: ...
@module.injectable
async def dependency_recipe() -> Dependency:
return Dependency()
@asfunction(module=module)
class AsyncFunction(NamedTuple):
dependency: Dependency
async def call(self):
return self.dependency
assert isinstance(await AsyncFunction(), Dependency)