Skip to content

Commit 1d2a81d

Browse files
authored
Change importing of RethinkDB class (#148)
* Fix install-db script * Replace rebirthdb leftovers with rethinkdb * Fix unit tests * Use pytest 5.2.2 on python3+ * Update requirements * Adjust build matrix * Do pip freeze after dependency installation
1 parent 00ae565 commit 1d2a81d

13 files changed

+128
-193
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ python:
88
- "3.5"
99
- "3.6"
1010
- "3.7"
11-
- "3.7-dev"
12-
- "3.8-dev"
11+
- "3.8"
1312

1413
allow_failure:
15-
- python: "3.8-dev"
14+
- python: "3.8"
1615

1716
install:
1817
- pip install -r requirements.txt
18+
- pip freeze
1919

2020
before_script:
2121
- make prepare
@@ -31,7 +31,7 @@ deploy:
3131
provider: script
3232
script: make upload-pypi
3333
on:
34-
python: 3.7
34+
python: 3.8
3535
tags: true
3636

3737
notifications:

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ test-unit:
4545
pytest -v -m unit
4646

4747
test-integration:
48-
@rebirthdb&
48+
@rethinkdb&
4949
pytest -v -m integration
50-
@killall rebirthdb
50+
@killall rethinkdb
5151

5252
test-ci:
53-
@rebirthdb&
53+
@rethinkdb&
5454
pytest -v --cov rethinkdb --cov-report xml
55-
@killall rebirthdb
55+
@killall rethinkdb
5656

5757
test-remote:
5858
python ${REMOTE_TEST_SETUP_NAME} pytest -m integration

pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ python_files = test_*.py
33
markers =
44
unit: Run unit tests
55
integration: Run integration tests
6-
asyncio: Run asyncio relates tests
6+
trio: Run trio related tests
7+
tornado: Run tornado related tests
8+
asyncio: Run asyncio related tests

requirements.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ async-generator==1.10; python_version>="3.6"
22
codacy-coverage==1.3.11
33
mock==3.0.5
44
pytest-cov==2.8.1
5-
pytest-tornasync; python_version >= '3.5'
5+
pytest-tornasync==0.6.0; python_version >= '3.5'
66
pytest-trio==0.5.2; python_version>="3.6"
7-
pytest==4.5.0
7+
pytest==4.6.6; python_version<"3.5"
8+
pytest==5.2.2; python_version>="3.5"
89
six==1.12.0
9-
tornado>=5.0
10+
tornado==5.1.1; python_version<"3.6"
11+
tornado==6.0.3; python_version>="3.6"
1012
trio==0.12.1; python_version>="3.6"
13+
outcome==1.0.1; python_version>="3.5"
14+
attrs==19.3.0; python_version>="3.5"

scripts/install-db.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ set -u
55

66
export DISTRIB_CODENAME=$(lsb_release -sc)
77

8-
# echo "This currently will not work for rethinkdb. It is in the process of being fixed."
9-
# exit 1
10-
echo "deb https://dl.bintray.com/rebirthdb/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rebirthdb.list
11-
wget -qO- https://dl.bintray.com/rebirthdb/keys/pubkey.gpg | sudo apt-key add -
8+
echo "deb https://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
9+
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
1210

1311
sudo apt-get update --option Acquire::Retries=100 --option Acquire::http::Timeout="300"
14-
sudo apt-get --allow-unauthenticated install rebirthdb --option Acquire::Retries=100 --option Acquire::http::Timeout="300"
12+
sudo apt-get install -y --option Acquire::Retries=100 --option Acquire::http::Timeout="300" rethinkdb

scripts/prepare_remote_test.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ def _execute_command(self, command):
7575
std_in, _, std_err = self.ssh_client.exec_command(command)
7676
std_in.close()
7777

78-
#for line in std_out.readlines():
79-
# print(line.replace('\n', ''))
80-
8178
has_err = False
8279
for line in std_err.readlines():
8380
has_err = True
@@ -134,22 +131,23 @@ def __enter__(self):
134131
return self.__enter__()
135132
return self
136133

137-
def install_rebirthdb(self):
138-
self._print_info('getting rebirthdb')
139-
self._execute_command('source /etc/lsb-release && echo "deb https://dl.bintray.com/{username}/apt $DISTRIB_CODENAME main" | tee /etc/apt/sources.list.d/rebirthdb.list'.format(username=BINTRAY_USERNAME))
140-
self._execute_command('wget -qO- https://dl.bintray.com/{username}/keys/pubkey.gpg | apt-key add -'.format(username=BINTRAY_USERNAME))
134+
def install_rethinkdb(self):
135+
self._print_info('getting rethinkdb')
136+
137+
self._execute_command('source /etc/lsb-release && echo "deb https://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list')
138+
self._execute_command('wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -')
141139

142140
self._print_info('installing rethinkdb')
143141
self._execute_command('apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y rethinkdb')
144142
self._execute_command('echo "bind=all" > /etc/rethinkdb/instances.d/default.conf')
145143

146-
def start_rebirthdb(self):
147-
self._print_info('restarting rebirthdb')
148-
self._execute_command('/etc/init.d/rebirthdb restart')
144+
def start_rethinkdb(self):
145+
self._print_info('restarting rethinkdb')
146+
self._execute_command('/etc/init.d/rethinkdb restart')
149147

150148
def run_script(self, script, script_arguments):
151149
self._print_info('executing script')
152-
os.environ["REBIRTHDB_HOST"] = self.droplet.ip_address
150+
os.environ["RETHINKDB_HOST"] = self.droplet.ip_address
153151
check_call([script, ' '.join(script_arguments)])
154152

155153
def __exit__(self, *args):
@@ -176,8 +174,8 @@ def main():
176174
setup.create_droplet()
177175

178176
with setup:
179-
setup.install_rebirthdb()
180-
setup.start_rebirthdb()
177+
setup.install_rethinkdb()
178+
setup.start_rethinkdb()
181179
setup.run_script(script, script_arguments)
182180

183181

tests/helpers.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@
66

77

88
class IntegrationTestCaseBase(object):
9-
conn = None
9+
def setup_method(self):
10+
self.r = r
11+
self.rethinkdb_host = os.getenv('RETHINKDB_HOST')
1012

11-
def connect(self):
12-
self.conn = r.connect(
13+
self.conn = self.r.connect(
1314
host=self.rethinkdb_host
1415
)
1516

16-
def setup_method(self):
17-
self.rethinkdb_host=os.getenv('RETHINKDB_HOST')
18-
19-
self.connect()
20-
21-
if INTEGRATION_TEST_DB not in r.db_list().run(self.conn):
22-
r.db_create(INTEGRATION_TEST_DB).run(self.conn)
17+
if INTEGRATION_TEST_DB not in self.r.db_list().run(self.conn):
18+
self.r.db_create(INTEGRATION_TEST_DB).run(self.conn)
2319

2420
self.conn.use(INTEGRATION_TEST_DB)
2521

2622
def teardown_method(self):
27-
r.db_drop(INTEGRATION_TEST_DB).run(self.conn)
23+
self.r.db_drop(INTEGRATION_TEST_DB).run(self.conn)
2824
self.conn.close()

tests/integration/__init__.py

Whitespace-only changes.

tests/integration/test_asyncio.py

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
1-
import os
21
import sys
3-
from collections import namedtuple
42
import pytest
5-
from rethinkdb import r
6-
from rethinkdb.errors import ReqlRuntimeError
73

8-
Helper = namedtuple("Helper", "r connection")
9-
10-
INTEGRATION_TEST_DB = 'integration_test'
4+
from asyncio import coroutine
5+
from tests.helpers import INTEGRATION_TEST_DB, IntegrationTestCaseBase
116

127

138
@pytest.mark.asyncio
149
@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.set_loop_type("asyncio")
24-
25-
connection = await r.connect(os.getenv("REBIRTHDB_HOST"))
26-
27-
try:
28-
await r.db_create(INTEGRATION_TEST_DB).run(connection)
29-
except ReqlRuntimeError:
30-
pass
31-
32-
connection.use(INTEGRATION_TEST_DB)
33-
34-
await r.table_create("marvel").run(connection)
35-
36-
marvel_heroes = r.table('marvel')
37-
await marvel_heroes.insert({
38-
'id': 1,
39-
'name': 'Iron Man',
40-
'first_appearance': 'Tales of Suspense #39'
41-
}).run(connection)
42-
43-
cursor = await marvel_heroes.run(connection)
44-
async for hero in cursor:
45-
assert hero['name'] == 'Iron Man'
46-
47-
await connection.close()
10+
@pytest.mark.skipif(
11+
sys.version_info == (3, 4) or sys.version_info == (3, 5),
12+
reason="requires python3.4 or python3.5"
13+
)
14+
class TestAsyncio(IntegrationTestCaseBase):
15+
def setup_method(self):
16+
super(TestAsyncio, self).setup_method()
17+
self.table_name = 'test_asyncio'
18+
self.r.set_loop_type('asyncio')
19+
20+
def teardown_method(self):
21+
super(TestAsyncio, self).teardown_method()
22+
self.r.set_loop_type(None)
23+
24+
@coroutine
25+
def test_flow_coroutine_paradigm(self):
26+
connection = yield from self.conn
27+
28+
yield from self.r.table_create(self.table_name).run(connection)
29+
30+
table = self.r.table(self.table_name)
31+
yield from table.insert({
32+
'id': 1,
33+
'name': 'Iron Man',
34+
'first_appearance': 'Tales of Suspense #39'
35+
}).run(connection)
36+
37+
cursor = yield from table.run(connection)
38+
39+
while (yield from cursor.fetch_next()):
40+
hero = yield from cursor.__anext__()
41+
assert hero['name'] == 'Iron Man'
42+
43+
yield from connection.close()

tests/integration/test_asyncio_coroutine.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)