| Total Complexity | 8 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from abc import ABC |
||
| 2 | |||
| 3 | from lagom import Container |
||
| 4 | |||
| 5 | |||
| 6 | class MySimpleDep: |
||
| 7 | stuff: str |
||
| 8 | |||
| 9 | def __init__(self, stuff): |
||
| 10 | self.stuff = stuff |
||
| 11 | |||
| 12 | |||
| 13 | class MyMoreComplicatedDep: |
||
| 14 | stuff: str |
||
| 15 | |||
| 16 | def __init__(self, dep: MySimpleDep): |
||
| 17 | self.stuff = dep.stuff |
||
| 18 | |||
| 19 | |||
| 20 | class AnotherAbc(ABC): |
||
| 21 | stuff: str = "empty" |
||
| 22 | |||
| 23 | |||
| 24 | class AnotherConcrete(AnotherAbc): |
||
| 25 | stuff = "full" |
||
| 26 | |||
| 27 | |||
| 28 | def test_deps_can_be_referenced_by_square_brackets(container: Container): |
||
| 29 | container[MySimpleDep] = lambda: MySimpleDep("hooray") |
||
|
|
|||
| 30 | resolved = container[MySimpleDep] |
||
| 31 | assert resolved.stuff == "hooray" |
||
| 32 | |||
| 33 | |||
| 34 | def test_construction_type_can_be_omitted(container: Container): |
||
| 35 | container[MySimpleDep] = lambda: MySimpleDep("hooray") |
||
| 36 | resolved = container[MySimpleDep] |
||
| 37 | assert resolved.stuff == "hooray" |
||
| 38 | |||
| 39 | |||
| 40 | def test_singleton_type_can_be_omitted(container: Container): |
||
| 41 | container[MySimpleDep] = MySimpleDep("hooray") |
||
| 42 | one = container[MySimpleDep] |
||
| 43 | two = container[MySimpleDep] |
||
| 44 | assert one is not None |
||
| 45 | assert one is two |
||
| 46 | |||
| 47 | |||
| 48 | def test_alias_can_be_omitted(container: Container): |
||
| 49 | container[AnotherAbc] = AnotherConcrete |
||
| 50 | resolved = container[AnotherAbc] |
||
| 51 | assert type(resolved) == AnotherConcrete |
||
| 52 | assert resolved.stuff == "full" |
||
| 53 |