Completed
Pull Request — master (#6)
by Steve
02:04
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
def test_lambda_arity_zero_works(container: Container):
18
    container.define(MyBasicDep, lambda: MyBasicDep())
19
    assert type(container[MyBasicDep]) == MyBasicDep
20
21
22
def test_lambda_arity_one_is_passed_the_container(container: Container):
23
    container.define(MyBasicDep, lambda: MyBasicDep())
24
    container.define(ComplexDep, lambda c: ComplexDep(c[MyBasicDep]))
25
    assert container[ComplexDep].value == 5
26
27
28
def test_lambda_arity_two_results_in_an_error(container: Container):
29
    with pytest.raises(InvalidDependencyDefinition):
30
        container.define(MyBasicDep, lambda _x, _y: MyBasicDep)
31