From 76894a954e5fa447d52a76b536b28d945ca3c64c Mon Sep 17 00:00:00 2001 From: MichalMazurek Date: Sun, 3 Mar 2019 15:58:28 +0000 Subject: [PATCH 1/9] Fixing AsyncioCursor to not return a generator TypeEror 'async for' received an object from `__aiter__` that does not implement __anext__: generator --- rethinkdb/asyncio_net/net_asyncio.py | 1 - 1 file changed, 1 deletion(-) 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 From 19356d8e136d14fd1828995f51a9eed408ad7493 Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Mon, 4 Mar 2019 10:33:08 +0000 Subject: [PATCH 2/9] adding tests for asyncio example flow --- tests/integration/test_asyncio.py | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/integration/test_asyncio.py diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py new file mode 100644 index 00000000..5a8439fc --- /dev/null +++ b/tests/integration/test_asyncio.py @@ -0,0 +1,49 @@ +import pytest +import os +from rethinkdb import RethinkDB +from rethinkdb.errors import ReqlRuntimeError +from collections import namedtuple + +Helper = namedtuple("Helper", "r connection") + +INTEGRATION_TEST_DB = 'integration_test' + + +@pytest.fixture +async def rethinkdb_helper(): + + 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) + + yield Helper(r=r, connection=connection) + + await connection.close() + + +@pytest.mark.integration +async def test_flow(rethinkdb_helper): + + r: RethinkDB = rethinkdb_helper.r + connection = rethinkdb_helper.connection + + 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' From dc337bbc5bf391831ba50cbfae710ad38503a20a Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Mon, 4 Mar 2019 10:53:42 +0000 Subject: [PATCH 3/9] fixing asyncio tests to python >=3.4 --- tests/integration/test_asyncio.py | 35 ++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py index 5a8439fc..397c9efa 100644 --- a/tests/integration/test_asyncio.py +++ b/tests/integration/test_asyncio.py @@ -1,8 +1,10 @@ -import pytest import os +import sys +from collections import namedtuple +from asyncio import coroutine +import pytest from rethinkdb import RethinkDB from rethinkdb.errors import ReqlRuntimeError -from collections import namedtuple Helper = namedtuple("Helper", "r connection") @@ -30,9 +32,11 @@ async def rethinkdb_helper(): @pytest.mark.integration +@pytest.mark.skipif(sys.version_info < (3, 5), + reason="requires python3.5 or higher") async def test_flow(rethinkdb_helper): - r: RethinkDB = rethinkdb_helper.r + r = rethinkdb_helper.r connection = rethinkdb_helper.connection await r.table_create("marvel").run(connection) @@ -47,3 +51,28 @@ async def test_flow(rethinkdb_helper): cursor = await marvel_heroes.run(connection) async for hero in cursor: assert hero['name'] == 'Iron Man' + + +@pytest.mark.integration +@pytest.mark.skipif(sys.version_info < (3, 4), + reason="requires python3.4") +@coroutine +def test_flow_couroutine_paradigm(rethinkdb_helper): + + r = rethinkdb_helper.r + connection = rethinkdb_helper.connection + + 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' From f8dea1dbc453e1921493820a090f3faa35ceef56 Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Mon, 4 Mar 2019 11:24:53 +0000 Subject: [PATCH 4/9] separating coroutine paradigm and allow fail for python2.7 and 3.4 --- .travis.yml | 2 ++ tests/integration/test_asyncio.py | 26 ---------------- tests/integration/test_asyncio_3_4.py | 45 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 tests/integration/test_asyncio_3_4.py diff --git a/.travis.yml b/.travis.yml index 3ea0a250..de187051 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ python: allow_failure: - python: "3.7" + - python: "3.4" + - python: "2.7" install: - pip install -r requirements.txt diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py index 397c9efa..56d38129 100644 --- a/tests/integration/test_asyncio.py +++ b/tests/integration/test_asyncio.py @@ -1,7 +1,6 @@ import os import sys from collections import namedtuple -from asyncio import coroutine import pytest from rethinkdb import RethinkDB from rethinkdb.errors import ReqlRuntimeError @@ -51,28 +50,3 @@ async def test_flow(rethinkdb_helper): cursor = await marvel_heroes.run(connection) async for hero in cursor: assert hero['name'] == 'Iron Man' - - -@pytest.mark.integration -@pytest.mark.skipif(sys.version_info < (3, 4), - reason="requires python3.4") -@coroutine -def test_flow_couroutine_paradigm(rethinkdb_helper): - - r = rethinkdb_helper.r - connection = rethinkdb_helper.connection - - 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' diff --git a/tests/integration/test_asyncio_3_4.py b/tests/integration/test_asyncio_3_4.py new file mode 100644 index 00000000..59ebbd75 --- /dev/null +++ b/tests/integration/test_asyncio_3_4.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), + reason="requires python3.4") +@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() From 250b493c6bdb7f401bb2239b23e612fbe3530c20 Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Mon, 4 Mar 2019 11:33:28 +0000 Subject: [PATCH 5/9] test support for 3.5 and 3.4 --- tests/integration/test_asyncio.py | 25 ++++++++----------- ...yncio_3_4.py => test_asyncio_coroutine.py} | 4 +-- 2 files changed, 12 insertions(+), 17 deletions(-) rename tests/integration/{test_asyncio_3_4.py => test_asyncio_coroutine.py} (87%) diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py index 56d38129..ee6b5166 100644 --- a/tests/integration/test_asyncio.py +++ b/tests/integration/test_asyncio.py @@ -10,8 +10,14 @@ INTEGRATION_TEST_DB = 'integration_test' -@pytest.fixture -async def rethinkdb_helper(): +@pytest.mark.integration +@pytest.mark.skipif(sys.version_info < (3, 6), + reason="requires python3.6 or higher") +async def test_flow(rethinkdb_helper): + """ + Test the flow for 3.6 and up, async generators are + not supported in 3.5. + """ r = RethinkDB() r.set_loop_type("asyncio") @@ -25,19 +31,6 @@ async def rethinkdb_helper(): connection.use(INTEGRATION_TEST_DB) - yield Helper(r=r, connection=connection) - - await connection.close() - - -@pytest.mark.integration -@pytest.mark.skipif(sys.version_info < (3, 5), - reason="requires python3.5 or higher") -async def test_flow(rethinkdb_helper): - - r = rethinkdb_helper.r - connection = rethinkdb_helper.connection - await r.table_create("marvel").run(connection) marvel_heroes = r.table('marvel') @@ -50,3 +43,5 @@ async def test_flow(rethinkdb_helper): 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_3_4.py b/tests/integration/test_asyncio_coroutine.py similarity index 87% rename from tests/integration/test_asyncio_3_4.py rename to tests/integration/test_asyncio_coroutine.py index 59ebbd75..e375d052 100644 --- a/tests/integration/test_asyncio_3_4.py +++ b/tests/integration/test_asyncio_coroutine.py @@ -10,8 +10,8 @@ @pytest.mark.integration -@pytest.mark.skipif(sys.version_info == (3, 4), - reason="requires python3.4") +@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(): From d69e0d0feb43bf71d4ae6bc2e3c10a4bdf4a7b33 Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Mon, 4 Mar 2019 11:37:42 +0000 Subject: [PATCH 6/9] kicking out unused fixture --- tests/integration/test_asyncio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py index ee6b5166..c499ff8c 100644 --- a/tests/integration/test_asyncio.py +++ b/tests/integration/test_asyncio.py @@ -13,7 +13,7 @@ @pytest.mark.integration @pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6 or higher") -async def test_flow(rethinkdb_helper): +async def test_flow(): """ Test the flow for 3.6 and up, async generators are not supported in 3.5. From fb6e3c13cb0c03cfd7e7eedf4429d6d62f177a1a Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Mon, 4 Mar 2019 11:42:37 +0000 Subject: [PATCH 7/9] marking asyncio test --- tests/integration/test_asyncio.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/test_asyncio.py b/tests/integration/test_asyncio.py index c499ff8c..c0986f07 100644 --- a/tests/integration/test_asyncio.py +++ b/tests/integration/test_asyncio.py @@ -10,6 +10,7 @@ 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") From c3d6ce2e5104b62d0e66e5213d183e6d6ccf8a95 Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Wed, 6 Mar 2019 13:20:31 +0100 Subject: [PATCH 8/9] adding collection ignore per python version --- tests/conftest.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/conftest.py 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 From 28a21960ad5a303e4690c6b3fb3da5b8d6c547ca Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Wed, 6 Mar 2019 13:24:06 +0100 Subject: [PATCH 9/9] removing allow_failure from 2.7 and 3.4 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index de187051..3ea0a250 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ python: allow_failure: - python: "3.7" - - python: "3.4" - - python: "2.7" install: - pip install -r requirements.txt