tests.test_lambda_loaders   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 19
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ComplexDep.__init__() 0 2 1

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_lambda_arity_one_is_passed_the_container() 0 4 3
A test_lambda_arity_zero_works() 0 3 2
A test_lambda_arity_two_results_in_an_error() 0 3 3
1
import pytest
2
3
from lagom import Container
4
from lagom.exceptions import InvalidDependencyDefinition
5
6
7
class MyBasicDep:
8
    basic_value = 5
9
10
11
class ComplexDep:
12
    def __init__(self, some_dep):
13
        self.value = some_dep.basic_value
14
15
16
def test_lambda_arity_zero_works(container: Container):
17
    container.define(MyBasicDep, lambda: MyBasicDep())
18
    assert type(container[MyBasicDep]) == MyBasicDep
19
20
21
def test_lambda_arity_one_is_passed_the_container(container: Container):
22
    container.define(MyBasicDep, lambda: MyBasicDep())
23
    container.define(ComplexDep, lambda c: ComplexDep(c[MyBasicDep]))
24
    assert container[ComplexDep].value == 5
25
26
27
def test_lambda_arity_two_results_in_an_error(container: Container):
28
    with pytest.raises(InvalidDependencyDefinition):
29
        container.define(MyBasicDep, lambda _x, _y: MyBasicDep)  # type: ignore
30