|
@@ 153-169 (lines=17) @@
|
| 150 |
|
assert context_container.resolve(Thing).contents == "managed thing" |
| 151 |
|
|
| 152 |
|
|
| 153 |
|
@pytest.mark.asyncio |
| 154 |
|
async def test_it_works_with_actual_context_managers_as_singletons(): |
| 155 |
|
fresh_container = Container(container) |
| 156 |
|
|
| 157 |
|
class ThingManager: |
| 158 |
|
def __enter__(self): |
| 159 |
|
return Thing("managed thing") |
| 160 |
|
|
| 161 |
|
def __exit__(self, exc_type, exc_val, exc_tb): |
| 162 |
|
pass |
| 163 |
|
|
| 164 |
|
fresh_container[ContextManager[Thing]] = ThingManager # type: ignore |
| 165 |
|
|
| 166 |
|
async with AsyncContextContainer( |
| 167 |
|
fresh_container, context_types=[], context_singletons=[Thing] |
| 168 |
|
) as context_container: |
| 169 |
|
assert context_container.resolve(Thing).contents == "managed thing" |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
@pytest.mark.asyncio |
|
@@ 134-149 (lines=16) @@
|
| 131 |
|
) |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
@pytest.mark.asyncio |
| 135 |
|
async def test_it_works_with_actual_context_managers(): |
| 136 |
|
fresh_container = Container(container) |
| 137 |
|
|
| 138 |
|
class ThingManager: |
| 139 |
|
def __enter__(self): |
| 140 |
|
return Thing("managed thing") |
| 141 |
|
|
| 142 |
|
def __exit__(self, exc_type, exc_val, exc_tb): |
| 143 |
|
pass |
| 144 |
|
|
| 145 |
|
fresh_container[ContextManager[Thing]] = ThingManager # type: ignore |
| 146 |
|
|
| 147 |
|
async with AsyncContextContainer( |
| 148 |
|
fresh_container, context_types=[Thing] |
| 149 |
|
) as context_container: |
| 150 |
|
assert context_container.resolve(Thing).contents == "managed thing" |
| 151 |
|
|
| 152 |
|
|