Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rethinkdb/asyncio_net/net_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def __init__(self, *args, **kwargs):
Cursor.__init__(self, *args, **kwargs)
self.new_response = asyncio.Future()

@asyncio.coroutine
def __aiter__(self):
return self

Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys

collect_ignore = []
if sys.version_info < (3, 4):
collect_ignore += ["integration/test_asyncio.py", "integration/test_asyncio_coroutine.py"]
elif sys.version_info < (3, 6):
collect_ignore.append("integration/test_asyncio.py")
48 changes: 48 additions & 0 deletions tests/integration/test_asyncio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import sys
from collections import namedtuple
import pytest
from rethinkdb import RethinkDB
from rethinkdb.errors import ReqlRuntimeError

Helper = namedtuple("Helper", "r connection")

INTEGRATION_TEST_DB = 'integration_test'


@pytest.mark.asyncio
@pytest.mark.integration
@pytest.mark.skipif(sys.version_info < (3, 6),
reason="requires python3.6 or higher")
async def test_flow():
"""
Test the flow for 3.6 and up, async generators are
not supported in 3.5.
"""

r = RethinkDB()
r.set_loop_type("asyncio")

connection = await r.connect(os.getenv("REBIRTHDB_HOST"))

try:
await r.db_create(INTEGRATION_TEST_DB).run(connection)
except ReqlRuntimeError:
pass

connection.use(INTEGRATION_TEST_DB)

await r.table_create("marvel").run(connection)

marvel_heroes = r.table('marvel')
await marvel_heroes.insert({
'id': 1,
'name': 'Iron Man',
'first_appearance': 'Tales of Suspense #39'
}).run(connection)

cursor = await marvel_heroes.run(connection)
async for hero in cursor:
assert hero['name'] == 'Iron Man'

await connection.close()
45 changes: 45 additions & 0 deletions tests/integration/test_asyncio_coroutine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import sys
from asyncio import coroutine
import pytest
from rethinkdb import RethinkDB
from rethinkdb.errors import ReqlRuntimeError


INTEGRATION_TEST_DB = 'integration_test'


@pytest.mark.integration
@pytest.mark.skipif(sys.version_info == (3, 4) or sys.version_info == (3, 5),
reason="requires python3.4 or python3.5")
@coroutine
def test_flow_couroutine_paradigm():

r = RethinkDB()
r.set_loop_type("asyncio")

connection = yield from r.connect(os.getenv("REBIRTHDB_HOST"))

try:
yield from r.db_create(INTEGRATION_TEST_DB).run(connection)
except ReqlRuntimeError:
pass

connection.use(INTEGRATION_TEST_DB)

yield from r.table_create("marvel").run(connection)

marvel_heroes = r.table('marvel')
yield from marvel_heroes.insert({
'id': 1,
'name': 'Iron Man',
'first_appearance': 'Tales of Suspense #39'
}).run(connection)

cursor = yield from marvel_heroes.run(connection)

while (yield from cursor.fetch_next()):
hero = yield from cursor.__anext__()
assert hero['name'] == 'Iron Man'

yield from connection.close()