diff --git a/rethinkdb/asyncio_net/net_asyncio.py b/rethinkdb/asyncio_net/net_asyncio.py index 0c0cc434..3c3b2beb 100644 --- a/rethinkdb/asyncio_net/net_asyncio.py +++ b/rethinkdb/asyncio_net/net_asyncio.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..9b2afe4a --- /dev/null +++ b/tests/conftest.py @@ -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") \ No newline at end of file diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py new file mode 100644 index 00000000..c0986f07 --- /dev/null +++ b/tests/integration/test_asyncio.py @@ -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() \ No newline at end of file diff --git a/tests/integration/test_asyncio_coroutine.py b/tests/integration/test_asyncio_coroutine.py new file mode 100644 index 00000000..e375d052 --- /dev/null +++ b/tests/integration/test_asyncio_coroutine.py @@ -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()