| Total Complexity | 3 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from typing import Optional |
||
| 2 | |||
| 3 | from lagom import Container, Singleton |
||
| 4 | from lagom.interfaces import ContainerDebugInfo |
||
| 5 | |||
| 6 | |||
| 7 | class InitialDep: |
||
| 8 | pass |
||
| 9 | |||
| 10 | |||
| 11 | class SomeOtherThing(InitialDep): |
||
| 12 | pass |
||
| 13 | |||
| 14 | |||
| 15 | def test_container_can_list_the_types_explicitly_defined(container: Container): |
||
| 16 | container[InitialDep] = InitialDep |
||
|
|
|||
| 17 | container[SomeOtherThing] = Singleton(SomeOtherThing) |
||
| 18 | |||
| 19 | assert container.defined_types == { |
||
| 20 | ContainerDebugInfo, |
||
| 21 | InitialDep, |
||
| 22 | SomeOtherThing, |
||
| 23 | Optional[InitialDep], |
||
| 24 | Optional[SomeOtherThing], |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | def test_container_can_list_the_types_explicitly_defined_in_a_cloned_container( |
||
| 29 | container: Container, |
||
| 30 | ): |
||
| 31 | container[InitialDep] = InitialDep |
||
| 32 | |||
| 33 | child_container = container.clone() |
||
| 34 | child_container[SomeOtherThing] = Singleton(SomeOtherThing) |
||
| 35 | |||
| 36 | assert child_container.defined_types == { |
||
| 37 | ContainerDebugInfo, |
||
| 38 | InitialDep, |
||
| 39 | SomeOtherThing, |
||
| 40 | Optional[InitialDep], |
||
| 41 | Optional[SomeOtherThing], |
||
| 42 | } |
||
| 43 | |||
| 44 | assert container.defined_types == { |
||
| 45 | ContainerDebugInfo, |
||
| 46 | InitialDep, |
||
| 47 | Optional[InitialDep], |
||
| 48 | } |
||
| 49 | |||
| 50 | |||
| 51 | def test_the_container_can_inject_its_own_overview(container: Container): |
||
| 52 | info = container[ContainerDebugInfo] # type: ignore |
||
| 53 | assert hasattr(info, "defined_types") |
||
| 54 | assert hasattr(info, "reflection_cache_overview") |
||
| 55 | assert isinstance(info, ContainerDebugInfo) |
||
| 56 |