Skip to content

Commit d7e7054

Browse files
authored
Merge pull request #93 from MichalMazurek/master
Fixing AsyncioCursor to not return a generator
2 parents 7e5ba81 + 28a2196 commit d7e7054

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

rethinkdb/asyncio_net/net_asyncio.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def __init__(self, *args, **kwargs):
9292
Cursor.__init__(self, *args, **kwargs)
9393
self.new_response = asyncio.Future()
9494

95-
@asyncio.coroutine
9695
def __aiter__(self):
9796
return self
9897

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
collect_ignore = []
4+
if sys.version_info < (3, 4):
5+
collect_ignore += ["integration/test_asyncio.py", "integration/test_asyncio_coroutine.py"]
6+
elif sys.version_info < (3, 6):
7+
collect_ignore.append("integration/test_asyncio.py")

tests/integration/test_asyncio.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import sys
3+
from collections import namedtuple
4+
import pytest
5+
from rethinkdb import RethinkDB
6+
from rethinkdb.errors import ReqlRuntimeError
7+
8+
Helper = namedtuple("Helper", "r connection")
9+
10+
INTEGRATION_TEST_DB = 'integration_test'
11+
12+
13+
@pytest.mark.asyncio
14+
@pytest.mark.integration
15+
@pytest.mark.skipif(sys.version_info < (3, 6),
16+
reason="requires python3.6 or higher")
17+
async def test_flow():
18+
"""
19+
Test the flow for 3.6 and up, async generators are
20+
not supported in 3.5.
21+
"""
22+
23+
r = RethinkDB()
24+
r.set_loop_type("asyncio")
25+
26+
connection = await r.connect(os.getenv("REBIRTHDB_HOST"))
27+
28+
try:
29+
await r.db_create(INTEGRATION_TEST_DB).run(connection)
30+
except ReqlRuntimeError:
31+
pass
32+
33+
connection.use(INTEGRATION_TEST_DB)
34+
35+
await r.table_create("marvel").run(connection)
36+
37+
marvel_heroes = r.table('marvel')
38+
await marvel_heroes.insert({
39+
'id': 1,
40+
'name': 'Iron Man',
41+
'first_appearance': 'Tales of Suspense #39'
42+
}).run(connection)
43+
44+
cursor = await marvel_heroes.run(connection)
45+
async for hero in cursor:
46+
assert hero['name'] == 'Iron Man'
47+
48+
await connection.close()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
import sys
3+
from asyncio import coroutine
4+
import pytest
5+
from rethinkdb import RethinkDB
6+
from rethinkdb.errors import ReqlRuntimeError
7+
8+
9+
INTEGRATION_TEST_DB = 'integration_test'
10+
11+
12+
@pytest.mark.integration
13+
@pytest.mark.skipif(sys.version_info == (3, 4) or sys.version_info == (3, 5),
14+
reason="requires python3.4 or python3.5")
15+
@coroutine
16+
def test_flow_couroutine_paradigm():
17+
18+
r = RethinkDB()
19+
r.set_loop_type("asyncio")
20+
21+
connection = yield from r.connect(os.getenv("REBIRTHDB_HOST"))
22+
23+
try:
24+
yield from r.db_create(INTEGRATION_TEST_DB).run(connection)
25+
except ReqlRuntimeError:
26+
pass
27+
28+
connection.use(INTEGRATION_TEST_DB)
29+
30+
yield from r.table_create("marvel").run(connection)
31+
32+
marvel_heroes = r.table('marvel')
33+
yield from marvel_heroes.insert({
34+
'id': 1,
35+
'name': 'Iron Man',
36+
'first_appearance': 'Tales of Suspense #39'
37+
}).run(connection)
38+
39+
cursor = yield from marvel_heroes.run(connection)
40+
41+
while (yield from cursor.fetch_next()):
42+
hero = yield from cursor.__anext__()
43+
assert hero['name'] == 'Iron Man'
44+
45+
yield from connection.close()

0 commit comments

Comments
 (0)