Total Complexity | 7 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from lagom import Container |
||
2 | |||
3 | |||
4 | class SomeDep: |
||
5 | pass |
||
6 | |||
7 | |||
8 | def test_temporary_singletons_work(container: Container): |
||
9 | with container.temporary_singletons([SomeDep]) as container_with_singletons: |
||
10 | # The original container is unaltered and the dep isn't a singleton |
||
11 | assert container[SomeDep] is not container[SomeDep] |
||
12 | # The temporary container has the singletons defined |
||
13 | assert container_with_singletons[SomeDep] is container_with_singletons[SomeDep] |
||
14 | |||
15 | |||
16 | def test_temporary_singletons_dont_effect_the_base_container(container: Container): |
||
17 | with container.temporary_singletons([SomeDep]) as container_with_singletons: |
||
18 | the_singleton = container_with_singletons[SomeDep] |
||
19 | assert container[SomeDep] is not the_singleton |
||
20 | |||
21 | |||
22 | def test_temporary_singletons_context_is_reusable_but_doesnt_share_state( |
||
23 | container: Container, |
||
24 | ): |
||
25 | context = container.temporary_singletons([SomeDep]) |
||
26 | |||
27 | with context as c1: |
||
28 | first = c1[SomeDep] |
||
29 | |||
30 | with context as c2: |
||
31 | second = c2[SomeDep] |
||
32 | |||
33 | assert first is not second |
||
34 |