-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from random import randint | ||
|
||
import pytest | ||
|
||
from yadm import Document | ||
from yadm import fields | ||
# from yadm.aio.aggregation import AioAggregator | ||
|
||
|
||
class Doc(Document): | ||
__collection__ = 'docs' | ||
i = fields.IntegerField() | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def docs(loop, db): | ||
async def gen_docs(): | ||
docs = [] | ||
for n in range(randint(10, 20)): | ||
doc = Doc(i=randint(-666, 666)) | ||
await db.insert(doc) | ||
docs.append(doc) | ||
|
||
return docs | ||
|
||
return loop.run_until_complete(gen_docs()) | ||
|
||
|
||
def test_async_for(loop, db, docs): | ||
async def test(): | ||
agg = db.aggregate(Doc).match(i={'$gt': 0}).project(n='$i') | ||
count = 0 | ||
|
||
async for item in agg: | ||
assert item['n'] > 0 | ||
count += 1 | ||
|
||
assert count == len([d.i for d in docs if d.i > 0]) | ||
|
||
loop.run_until_complete(test()) |
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,6 @@ | ||
from yadm.aggregation import BaseAggregator | ||
|
||
|
||
class AioAggregator(BaseAggregator): | ||
async def __aiter__(self): | ||
return self._cursor |
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