tests.test_container_updaters   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_a_new_container_can_be_made_with_singletons() 0 4 1
A test_a_new_container_with_singletons_leaves_the_original_unaffected() 0 4 1
A test_a_new_container_can_be_made_with_many_types_as_singletons() 0 7 1
1
from lagom import Container
2
from lagom.updaters import update_container_singletons
3
4
5
class ThingOne:
6
    pass
7
8
9
class ThingTwo:
10
    pass
11
12
13
class ThingThree:
14
    pass
15
16
17
c = Container()
18
19
20
def test_a_new_container_can_be_made_with_singletons():
21
    singleton_container = update_container_singletons(c, [ThingOne])
22
    assert singleton_container[ThingOne] is singleton_container[ThingOne]
23
    assert isinstance(singleton_container[ThingOne], ThingOne)
24
25
26
def test_a_new_container_with_singletons_leaves_the_original_unaffected():
27
    singleton_container = update_container_singletons(c, [ThingOne])
28
    singleton_container.resolve(ThingOne)
29
    assert c[ThingOne] is not c[ThingOne]
30
31
32
def test_a_new_container_can_be_made_with_many_types_as_singletons():
33
    singleton_container = update_container_singletons(
34
        c, [ThingOne, ThingTwo, ThingThree]
35
    )
36
    assert isinstance(singleton_container[ThingOne], ThingOne)
37
    assert isinstance(singleton_container[ThingTwo], ThingTwo)
38
    assert isinstance(singleton_container[ThingThree], ThingThree)
39