forked from ivankorobkov/python-inject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_param.py
More file actions
34 lines (25 loc) · 900 Bytes
/
Copy pathtest_param.py
File metadata and controls
34 lines (25 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
import inject
from test import BaseTestInject
import inspect
import asyncio
class TestInjectParams(BaseTestInject):
def test_param_by_name(self):
@inject.param('val')
def test_func(val=None):
return val
inject.configure(lambda binder: binder.bind('val', 123))
assert test_func() == 123
assert test_func(val=321) == 321
def test_param_by_class(self):
@inject.param('val', int)
def test_func(val):
return val
inject.configure(lambda binder: binder.bind(int, 123))
assert test_func() == 123
def test_async_param(self):
@inject.param('val')
async def test_func(val):
return val
inject.configure(lambda binder: binder.bind('val', 123))
assert inspect.iscoroutinefunction(test_func)
assert self.run_async(test_func()) == 123