Skip to content

Commit 5350bca

Browse files
committed
Merge branch 'master' of github.com:rethinkdb/rethinkdb-python
2 parents e7a5eb8 + a9db380 commit 5350bca

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ sudo: required
55

66
python:
77
- "2.7"
8-
- "3.4"
98
- "3.5"
109
- "3.6"
1110
- "3.7"

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
codacy-coverage==1.3.11
22
mock==2.0.0
33
pytest-cov==2.6.1
4-
pytest==4.3.1
4+
pytest==4.4.0
55
six==1.12.0
6+
trio==0.11.0; python_version>="3.6"
7+
pytest-trio==0.5.2; python_version>="3.6"
8+
async-generator==1.10; python_version>="3.6"

rethinkdb/trio_net/net_trio.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from rethinkdb.errors import ReqlAuthError, ReqlCursorEmpty, ReqlDriverError, \
2929
ReqlTimeoutError, RqlCursorEmpty
3030
from rethinkdb.net import Connection as ConnectionBase, Cursor, Query, \
31-
Response, maybe_profile, connect
31+
Response, maybe_profile, make_connection
3232

3333

3434
__all__ = ['Connection']
@@ -415,7 +415,8 @@ def open(cls, *args, **kwargs):
415415
return cls(*args, **kwargs)
416416

417417
async def __aenter__(self):
418-
self._conn = await connect(*self._args, **self._kwargs)
418+
self._conn = await make_connection(Connection, *self._args,
419+
**self._kwargs)
419420
return self._conn
420421

421422
async def __aexit__(self, exc_type, exc, traceback):
@@ -480,7 +481,7 @@ async def acquire(self):
480481
# still connected.
481482
conn = self._connections.popleft()
482483
except IndexError:
483-
conn = await connect(*self._args, **self._kwargs)
484+
conn = await make_connection(*self._args, **self._kwargs)
484485

485486
self._lent_out.add(conn)
486487
return conn

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
if sys.version_info < (3, 4):
55
collect_ignore += ["integration/test_asyncio.py", "integration/test_asyncio_coroutine.py"]
66
elif sys.version_info < (3, 6):
7-
collect_ignore.append("integration/test_asyncio.py")
7+
collect_ignore.append("integration/test_asyncio.py")
8+
if sys.version_info < (3, 6):
9+
collect_ignore.append("integration/test_trio.py")

tests/integration/test_trio.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from collections import namedtuple
2+
import os
3+
import sys
4+
5+
from async_generator import async_generator, yield_
6+
import pytest
7+
from rethinkdb import RethinkDB
8+
from rethinkdb.errors import ReqlRuntimeError
9+
import trio
10+
11+
12+
INTEGRATION_TEST_DB = 'integration_test'
13+
r = RethinkDB()
14+
r.set_loop_type('trio')
15+
16+
17+
@pytest.fixture
18+
@async_generator
19+
async def integration_db(nursery):
20+
async with r.open(db='test', nursery=nursery) as conn:
21+
try:
22+
await r.db_create(INTEGRATION_TEST_DB).run(conn)
23+
except ReqlRuntimeError:
24+
pass
25+
await yield_(r.db(INTEGRATION_TEST_DB))
26+
27+
28+
@pytest.fixture
29+
@async_generator
30+
async def marvel_table(integration_db, nursery):
31+
async with r.open(db='test', nursery=nursery) as conn:
32+
await r.table_create('marvel').run(conn)
33+
await yield_(r.table('marvel'))
34+
await r.table_drop('marvel').run(conn)
35+
36+
37+
@pytest.mark.trio
38+
@pytest.mark.integration
39+
async def test_trio(marvel_table, nursery):
40+
"""
41+
Test the flow for 3.6 and up, async generators are
42+
not supported in 3.5.
43+
"""
44+
async with r.open(db='test', nursery=nursery) as conn:
45+
await marvel_table.insert({
46+
'id': 1,
47+
'name': 'Iron Man',
48+
'first_appearance': 'Tales of Suspense #39'
49+
}).run(conn)
50+
51+
cursor = await marvel_table.run(conn)
52+
async for hero in cursor:
53+
hero['name'] == 'Iron Man'

0 commit comments

Comments
 (0)