Test Failed
Pull Request — master (#252)
by Steve
06:28
created

tests.test_composition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 8

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_the_result_of_a_composition_can_be_composed() 0 8 1
A test_two_containers_can_be_composed_together_and_all_dependencies_resolved() 0 5 1
A test_composed_container_definitions_cannot_overlap() 0 3 2
A test_the_composed_container_can_list_all_defined_deps() 0 5 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A B.__init__() 0 2 1
A A.__init__() 0 2 1
A C.__init__() 0 2 1
1
import pytest
2
3
from lagom import Container, compose
4
5
6
class A:
7
    def __init__(self, something: str):
8
        pass
9
10
11
class B:
12
    def __init__(self, something: str):
13
        pass
14
15
16
class C:
17
    def __init__(self, something: str):
18
        pass
19
20
21
container_a = Container()
22
container_a[A] = lambda: A("hello")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable A does not seem to be defined.
Loading history...
23
24
container_b = Container()
25
container_b[B] = lambda: B("world")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable B does not seem to be defined.
Loading history...
26
27
container_c = Container()
28
container_c[C] = lambda: C("!!!!")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable C does not seem to be defined.
Loading history...
29
30
31
def test_two_containers_can_be_composed_together_and_all_dependencies_resolved():
32
    composed_container = compose(container_a, container_b)
33
34
    assert composed_container[A]
35
    assert composed_container[B]
36
37
38
def test_the_composed_container_can_list_all_defined_deps():
39
    composed_container = compose(container_a, container_b)
40
41
    assert A in composed_container.defined_types
42
    assert B in composed_container.defined_types
43
44
45
def test_composed_container_definitions_cannot_overlap():
46
    with pytest.raises(ValueError):
47
        compose(container_a, container_a)
48
49
50
def test_the_result_of_a_composition_can_be_composed():
51
    composed_container = compose(container_a, container_b)
52
    next_composed_container = compose(composed_container, container_c)
53
54
    assert A in next_composed_container.defined_types
55
    assert B in next_composed_container.defined_types
56
    assert C in next_composed_container.defined_types
57
    assert C not in composed_container.defined_types
58