-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate wiring async injection tests
- Loading branch information
Showing
4 changed files
with
110 additions
and
110 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
tests/unit/wiring/provider_ids/test_async_injections_py36.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Async injection tests.""" | ||
|
||
from pytest import fixture, mark | ||
|
||
from wiringsamples import asyncinjections | ||
|
||
|
||
@fixture(autouse=True) | ||
def container(): | ||
container = asyncinjections.Container() | ||
container.wire(modules=[asyncinjections]) | ||
yield container | ||
container.unwire() | ||
|
||
|
||
@fixture(autouse=True) | ||
def reset_counters(): | ||
asyncinjections.resource1.reset_counters() | ||
asyncinjections.resource2.reset_counters() | ||
|
||
|
||
@mark.asyncio | ||
async def test_async_injections(): | ||
resource1, resource2 = await asyncinjections.async_injection() | ||
|
||
assert resource1 is asyncinjections.resource1 | ||
assert asyncinjections.resource1.init_counter == 1 | ||
assert asyncinjections.resource1.shutdown_counter == 0 | ||
|
||
assert resource2 is asyncinjections.resource2 | ||
assert asyncinjections.resource2.init_counter == 1 | ||
assert asyncinjections.resource2.shutdown_counter == 0 | ||
|
||
|
||
@mark.asyncio | ||
async def test_async_injections_with_closing(): | ||
resource1, resource2 = await asyncinjections.async_injection_with_closing() | ||
|
||
assert resource1 is asyncinjections.resource1 | ||
assert asyncinjections.resource1.init_counter == 1 | ||
assert asyncinjections.resource1.shutdown_counter == 1 | ||
|
||
assert resource2 is asyncinjections.resource2 | ||
assert asyncinjections.resource2.init_counter == 1 | ||
assert asyncinjections.resource2.shutdown_counter == 1 | ||
|
||
resource1, resource2 = await asyncinjections.async_injection_with_closing() | ||
|
||
assert resource1 is asyncinjections.resource1 | ||
assert asyncinjections.resource1.init_counter == 2 | ||
assert asyncinjections.resource1.shutdown_counter == 2 | ||
|
||
assert resource2 is asyncinjections.resource2 | ||
assert asyncinjections.resource2.init_counter == 2 | ||
assert asyncinjections.resource2.shutdown_counter == 2 |
55 changes: 55 additions & 0 deletions
55
tests/unit/wiring/string_ids/test_async_injections_py36.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Async injection tests.""" | ||
|
||
from pytest import fixture, mark | ||
|
||
from wiringstringidssamples import asyncinjections | ||
|
||
|
||
@fixture(autouse=True) | ||
def container(): | ||
container = asyncinjections.Container() | ||
container.wire(modules=[asyncinjections]) | ||
yield container | ||
container.unwire() | ||
|
||
|
||
@fixture(autouse=True) | ||
def reset_counters(): | ||
asyncinjections.resource1.reset_counters() | ||
asyncinjections.resource2.reset_counters() | ||
|
||
|
||
@mark.asyncio | ||
async def test_async_injections(): | ||
resource1, resource2 = await asyncinjections.async_injection() | ||
|
||
assert resource1 is asyncinjections.resource1 | ||
assert asyncinjections.resource1.init_counter == 1 | ||
assert asyncinjections.resource1.shutdown_counter == 0 | ||
|
||
assert resource2 is asyncinjections.resource2 | ||
assert asyncinjections.resource2.init_counter == 1 | ||
assert asyncinjections.resource2.shutdown_counter == 0 | ||
|
||
|
||
@mark.asyncio | ||
async def test_async_injections_with_closing(): | ||
resource1, resource2 = await asyncinjections.async_injection_with_closing() | ||
|
||
assert resource1 is asyncinjections.resource1 | ||
assert asyncinjections.resource1.init_counter == 1 | ||
assert asyncinjections.resource1.shutdown_counter == 1 | ||
|
||
assert resource2 is asyncinjections.resource2 | ||
assert asyncinjections.resource2.init_counter == 1 | ||
assert asyncinjections.resource2.shutdown_counter == 1 | ||
|
||
resource1, resource2 = await asyncinjections.async_injection_with_closing() | ||
|
||
assert resource1 is asyncinjections.resource1 | ||
assert asyncinjections.resource1.init_counter == 2 | ||
assert asyncinjections.resource1.shutdown_counter == 2 | ||
|
||
assert resource2 is asyncinjections.resource2 | ||
assert asyncinjections.resource2.init_counter == 2 | ||
assert asyncinjections.resource2.shutdown_counter == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters