tests.test_container_dependency_listing   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_the_container_can_inject_its_own_overview() 0 5 1
A test_container_can_list_the_types_explicitly_defined() 0 10 1
A test_container_can_list_the_types_explicitly_defined_in_a_cloned_container() 0 20 1
1
from typing import Optional
2
3
from lagom import Container, Singleton
4
from lagom.interfaces import ContainerDebugInfo
5
6
7
class InitialDep:
8
    pass
9
10
11
class SomeOtherThing(InitialDep):
12
    pass
13
14
15
def test_container_can_list_the_types_explicitly_defined(container: Container):
16
    container[InitialDep] = InitialDep
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable InitialDep does not seem to be defined.
Loading history...
17
    container[SomeOtherThing] = Singleton(SomeOtherThing)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable SomeOtherThing does not seem to be defined.
Loading history...
18
19
    assert container.defined_types == {
20
        ContainerDebugInfo,
21
        InitialDep,
22
        SomeOtherThing,
23
        Optional[InitialDep],
24
        Optional[SomeOtherThing],
25
    }
26
27
28
def test_container_can_list_the_types_explicitly_defined_in_a_cloned_container(
29
    container: Container,
30
):
31
    container[InitialDep] = InitialDep
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable InitialDep does not seem to be defined.
Loading history...
32
33
    child_container = container.clone()
34
    child_container[SomeOtherThing] = Singleton(SomeOtherThing)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable SomeOtherThing does not seem to be defined.
Loading history...
35
36
    assert child_container.defined_types == {
37
        ContainerDebugInfo,
38
        InitialDep,
39
        SomeOtherThing,
40
        Optional[InitialDep],
41
        Optional[SomeOtherThing],
42
    }
43
44
    assert container.defined_types == {
45
        ContainerDebugInfo,
46
        InitialDep,
47
        Optional[InitialDep],
48
    }
49
50
51
def test_the_container_can_inject_its_own_overview(container: Container):
52
    info = container[ContainerDebugInfo]  # type: ignore
53
    assert hasattr(info, "defined_types")
54
    assert hasattr(info, "reflection_cache_overview")
55
    assert isinstance(info, ContainerDebugInfo)
56