Completed
Pull Request — master (#6)
by Steve
02:52 queued 43s
created

test.test_shorter_syntax.container()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
from abc import ABC
2
from typing import List
3
4
import pytest
5
6
from lagom import Construction, Container
7
8
9
class MySimpleDep:
10
    stuff: str
11
12
    def __init__(self, stuff):
13
        self.stuff = stuff
14
15
16
class MyMoreComplicatedDep:
17
    stuff: str
18
19
    def __init__(self, dep: MySimpleDep):
20
        self.stuff = dep.stuff
21
22
23
class AnotherAbc(ABC):
24
    stuff: str = "empty"
25
26
27
class AnotherConcrete(AnotherAbc):
28
    stuff = "full"
29
30
31
def test_deps_can_be_referenced_by_square_brackets(container: Container):
32
    container[MySimpleDep] = Construction(lambda: MySimpleDep("hooray"))
33
    resolved = container[MySimpleDep]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable MySimpleDep does not seem to be defined.
Loading history...
34
    assert resolved.stuff == "hooray"
35
36
37
def test_construction_type_can_be_omitted(container: Container):
38
    container[MySimpleDep] = lambda: MySimpleDep("hooray")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable MySimpleDep does not seem to be defined.
Loading history...
39
    resolved = container[MySimpleDep]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable MySimpleDep does not seem to be defined.
Loading history...
40
    assert resolved.stuff == "hooray"
41
42
43
def test_singleton_type_can_be_omitted(container: Container):
44
    container[MySimpleDep] = MySimpleDep("hooray")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable MySimpleDep does not seem to be defined.
Loading history...
45
    one = container[MySimpleDep]
46
    two = container[MySimpleDep]
47
    assert one is not None
48
    assert one is two
49
50
51
def test_alias_can_be_omitted(container: Container):
52
    container[AnotherAbc] = AnotherConcrete
53
    resolved = container[AnotherAbc]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable AnotherAbc does not seem to be defined.
Loading history...
54
    assert type(resolved) == AnotherConcrete
55
    assert resolved.stuff == "full"
56