-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from agronholm/async_generator
Added support for the async_generator library
- Loading branch information
Showing
5 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
coverage==4.1 | ||
tox==2.5.0 | ||
tox==2.5.0 | ||
async_generator==1.8 |
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,40 @@ | ||
import unittest.mock | ||
|
||
import pytest | ||
from async_generator import yield_, async_generator | ||
|
||
START = object() | ||
END = object() | ||
RETVAL = object() | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def mock(): | ||
return unittest.mock.Mock(return_value=RETVAL) | ||
|
||
|
||
@pytest.fixture | ||
@async_generator | ||
async def async_gen_fixture(mock): | ||
try: | ||
await yield_(mock(START)) | ||
except Exception as e: | ||
mock(e) | ||
else: | ||
mock(END) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_gen_fixture(async_gen_fixture, mock): | ||
assert mock.called | ||
assert mock.call_args_list[-1] == unittest.mock.call(START) | ||
assert async_gen_fixture is RETVAL | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_gen_fixture_finalized(mock): | ||
try: | ||
assert mock.called | ||
assert mock.call_args_list[-1] == unittest.mock.call(END) | ||
finally: | ||
mock.reset_mock() |