Completed
Pull Request — master (#6)
by Steve
02:04
created

test.test_shorter_syntax   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A MySimpleDep.__init__() 0 2 1
A MyMoreComplicatedDep.__init__() 0 2 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_singleton_type_can_be_omitted() 0 6 1
A test_deps_can_be_referenced_by_square_brackets() 0 4 2
A test_construction_type_can_be_omitted() 0 4 2
A test_alias_can_be_omitted() 0 5 1
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