tests.test_temporary_singletons   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 7

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_temporary_singletons_work() 0 6 2
A test_temporary_singletons_context_is_reusable_but_doesnt_share_state() 0 12 3
A test_temporary_singletons_dont_effect_the_base_container() 0 4 2
1
from lagom import Container
2
3
4
class SomeDep:
5
    pass
6
7
8
def test_temporary_singletons_work(container: Container):
9
    with container.temporary_singletons([SomeDep]) as container_with_singletons:
10
        # The original container is unaltered and the dep isn't a singleton
11
        assert container[SomeDep] is not container[SomeDep]
12
        # The temporary container has the singletons defined
13
        assert container_with_singletons[SomeDep] is container_with_singletons[SomeDep]
14
15
16
def test_temporary_singletons_dont_effect_the_base_container(container: Container):
17
    with container.temporary_singletons([SomeDep]) as container_with_singletons:
18
        the_singleton = container_with_singletons[SomeDep]
19
    assert container[SomeDep] is not the_singleton
20
21
22
def test_temporary_singletons_context_is_reusable_but_doesnt_share_state(
23
    container: Container,
24
):
25
    context = container.temporary_singletons([SomeDep])
26
27
    with context as c1:
28
        first = c1[SomeDep]
29
30
    with context as c2:
31
        second = c2[SomeDep]
32
33
    assert first is not second
34