Passed
Push — master ( 29ab2b...f3ee24 )
by Steve
01:53
created

test.test_lambda_loaders.container()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 0
1
import pytest
2
3
from lagom import Singleton, Construction, Container
4
from lagom.exceptions import InvalidDependencyDefinition
5
6
7
class MyBasicDep:
8
    basic_value = 5
9
    pass
10
11
12
class ComplexDep:
13
    def __init__(self, some_dep):
14
        self.value = some_dep.basic_value
15
16
17
@pytest.fixture
18
def container():
19
    return Container()
20
21
22
def test_lambda_arity_zero_works(container: Container):
23
    container.define(MyBasicDep, lambda: MyBasicDep())
24
    assert type(container[MyBasicDep]) == MyBasicDep
25
26
27
def test_lambda_arity_one_is_passed_the_container(container: Container):
28
    container.define(MyBasicDep, lambda: MyBasicDep())
29
    container.define(ComplexDep, lambda c: ComplexDep(c[MyBasicDep]))
30
    assert container[ComplexDep].value == 5
31
32
33
def test_lambda_arity_two_results_in_an_error(container: Container):
34
    with pytest.raises(InvalidDependencyDefinition):
35
        container.define(MyBasicDep, lambda _x, _y: MyBasicDep)
36