Total Complexity | 8 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 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] |
||
|
|||
34 | assert resolved.stuff == "hooray" |
||
35 | |||
36 | |||
37 | def test_construction_type_can_be_omitted(container: Container): |
||
38 | container[MySimpleDep] = lambda: MySimpleDep("hooray") |
||
39 | resolved = container[MySimpleDep] |
||
40 | assert resolved.stuff == "hooray" |
||
41 | |||
42 | |||
43 | def test_singleton_type_can_be_omitted(container: Container): |
||
44 | container[MySimpleDep] = MySimpleDep("hooray") |
||
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] |
||
54 | assert type(resolved) == AnotherConcrete |
||
55 | assert resolved.stuff == "full" |
||
56 |