| Total Complexity | 3 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from lagom import Container |
||
| 2 | from lagom.updaters import update_container_singletons |
||
| 3 | |||
| 4 | |||
| 5 | class ThingOne: |
||
| 6 | pass |
||
| 7 | |||
| 8 | |||
| 9 | class ThingTwo: |
||
| 10 | pass |
||
| 11 | |||
| 12 | |||
| 13 | class ThingThree: |
||
| 14 | pass |
||
| 15 | |||
| 16 | |||
| 17 | c = Container() |
||
| 18 | |||
| 19 | |||
| 20 | def test_a_new_container_can_be_made_with_singletons(): |
||
| 21 | singleton_container = update_container_singletons(c, [ThingOne]) |
||
| 22 | assert singleton_container[ThingOne] is singleton_container[ThingOne] |
||
| 23 | assert isinstance(singleton_container[ThingOne], ThingOne) |
||
| 24 | |||
| 25 | |||
| 26 | def test_a_new_container_with_singletons_leaves_the_original_unaffected(): |
||
| 27 | singleton_container = update_container_singletons(c, [ThingOne]) |
||
| 28 | singleton_container.resolve(ThingOne) |
||
| 29 | assert c[ThingOne] is not c[ThingOne] |
||
| 30 | |||
| 31 | |||
| 32 | def test_a_new_container_can_be_made_with_many_types_as_singletons(): |
||
| 33 | singleton_container = update_container_singletons( |
||
| 34 | c, [ThingOne, ThingTwo, ThingThree] |
||
| 35 | ) |
||
| 36 | assert isinstance(singleton_container[ThingOne], ThingOne) |
||
| 37 | assert isinstance(singleton_container[ThingTwo], ThingTwo) |
||
| 38 | assert isinstance(singleton_container[ThingThree], ThingThree) |
||
| 39 |