MyDep.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import pytest
2
3
from lagom import Container, bind_to_container, injectable
4
5
6
class MyDep:
7
    value: str
8
9
    def __init__(self, value="testing"):
10
        self.value = value
11
12
13
container = Container()
14
15
16
@bind_to_container(container)
17
def example_function(message: str, resolved: MyDep = injectable) -> str:
18
    return resolved.value + message
19
20
21
@bind_to_container(container)
22
async def async_example_function(message: str, resolved: MyDep = injectable) -> str:
23
    return resolved.value + message
24
25
26
def test_functions_decorated_get_the_correct_argument():
27
    assert example_function(message=" world") == "testing world"
28
29
30
def test_injected_arguments_can_over_overridden():
31
    assert example_function(message=" world", resolved=MyDep("set")) == "set world"
32
33
34
@pytest.mark.asyncio
35
async def test_async_functions_decorated_get_the_correct_argument():
36
    assert await async_example_function(message=" world") == "testing world"
37