Skip to content

Commit 7279056

Browse files
committed
feat: add tornado and twisted tests
Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
1 parent 2b9766e commit 7279056

File tree

13 files changed

+2568
-327
lines changed

13 files changed

+2568
-327
lines changed

Makefile

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ docs: ## generate Sphinx HTML documentation, including API docs
9696

9797
.PHONY: format
9898
format: ## run formatters on the package
99-
isort rethinkdb tests
100-
black rethinkdb tests
99+
poetry run isort rethinkdb tests
100+
poetry run black rethinkdb tests
101101

102102
.PHONY: lint
103103
lint: ## run linters against the package
104-
mypy rethinkdb
105-
pylint rethinkdb
106-
flake8 rethinkdb --count --show-source --statistics
104+
poetry run mypy rethinkdb
105+
poetry run pylint rethinkdb || true
106+
poetry run flake8 rethinkdb --count --show-source --statistics
107107

108108
.PHONY: protobuf
109109
protobuf: ## download and convert protobuf file
@@ -113,34 +113,21 @@ protobuf: ## download and convert protobuf file
113113
.PHONY: generate-init-pyi
114114
generate-init-pyi: ## generate __init__.pyi file
115115
python scripts/generate_init_pyi.py
116-
isort rethinkdb/__init__.pyi
117-
black rethinkdb/__init__.pyi
116+
poetry run isort rethinkdb/__init__.pyi
117+
poetry run black rethinkdb/__init__.pyi
118118

119119
.PHONY: test-unit
120120
test-unit: ## run unit tests and generate coverage
121-
coverage run -m pytest -m "not integration" -vv
122-
coverage report
121+
poetry run coverage run -m pytest -m "not integration" -vv
122+
poetry run coverage report
123123

124124
.PHONY: test-integration
125125
test-integration: ## run unit tests and generate coverage
126-
coverage run -m pytest -m "integration" -m "not v2_5" -vv
127-
coverage report
126+
poetry run coverage run -m pytest -m "integration" -m "not v2_5" -vv
127+
poetry run coverage report
128128

129129
.PHONY: test
130130
test: ## run all tests and generate coverage
131-
coverage run -m pytest -m "not v2_5" -vv
132-
coverage report
133-
coverage xml
134-
135-
.PHONY: download-test-reporter
136-
download-test-reporter:
137-
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
138-
chmod +x ./cc-test-reporter
139-
140-
.PHONY: test-reporter-before
141-
test-reporter-before:
142-
./cc-test-reporter before-build
143-
144-
.PHONY: upload-coverage
145-
upload-coverage:
146-
./cc-test-reporter after-build -t "coverage.py"
131+
poetry run coverage run -m pytest -m "not v2_5" -vv
132+
poetry run coverage report
133+
poetry run coverage xml

mypy.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
[mypy]
2-
exclude = rethinkdb/cli/.*,scripts/.*,.*ql2_pb2\.py
2+
plugins = pydantic.mypy
3+
4+
[mypy-twisted.*]
5+
ignore_missing_imports = True
6+
7+
[mypy-tornado.*]
8+
ignore_missing_imports = True
9+
10+
[mypy-rethinkdb.net_twisted]
11+
ignore_errors = True

poetry.lock

Lines changed: 333 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ ujson = "^5.10.0"
5252
click = "^8.2.1"
5353
pyyaml = "^6.0.2"
5454

55+
twisted = { version = "^25.5", optional = true }
56+
tornado = { version = "^6.5", optional = true }
57+
5558
[tool.poetry.group.dev.dependencies]
5659
black = "^25.1"
5760
coverage = "^7.9"
@@ -61,10 +64,13 @@ mypy = "^1.16"
6164
pylint = "^3.3"
6265
pytest = "^8.4"
6366
sphinx-rtd-theme = "^3.0"
67+
pytest-twisted = "^1.14"
68+
pytest-asyncio = "^0.25"
6469

6570
[tool.poetry.extras]
66-
# Here comes the Trio, Twisted, etc extras
67-
all = []
71+
all = ["twisted", "tornado"]
72+
twisted = ["twisted"]
73+
tornado = ["tornado"]
6874

6975
[tool.black]
7076
target-version = ['py312']

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ python_functions=test_*
55
markers =
66
unit: Select only unit tests
77
integration: Select only integration tests
8+
twisted: Select only Twisted tests
9+
tornado: Select only Tornado tests
810
v2_5: RethinkDB 2.5+ compatible tests

rethinkdb/__init__.py

Lines changed: 203 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,213 @@
1515
# This file incorporates work covered by the following copyright:
1616
# Copyright 2010-2016 RethinkDB, all rights reserved.
1717

18-
import warnings
18+
# pylint: disable=redefined-builtin, unused-import
19+
1920
from types import SimpleNamespace
21+
import warnings
2022

2123
from rethinkdb import net
22-
# pylint: disable=redefined-builtin
2324
from rethinkdb.query import (
24-
add, and_, april, args, asc, august, avg, binary, bit_and, bit_not, bit_or,
25-
bit_sal, bit_sar, bit_xor, branch, ceil, circle, contains, count, db,
26-
db_create, db_drop, db_list, december, desc, distance, distinct, div, do,
27-
epoch_time, eq, error, february, floor, format, friday, ge, geojson, grant,
28-
group, gt, http, info, intersects, iso8601, january, json, july, june, le,
29-
line, literal, lt, make_timezone, map, march, max, maxval, may, min, minval,
30-
mod, monday, mul, ne, not_, november, now, object, october, or_, point,
31-
polygon, random, range, reduce, round, row, saturday, september, sub, sum,
32-
sunday, table, table_create, table_drop, table_list, thursday, time, tuesday,
33-
type_of, union, uuid, wednesday, js
25+
add,
26+
and_,
27+
april,
28+
args,
29+
asc,
30+
august,
31+
avg,
32+
binary,
33+
bit_and,
34+
bit_not,
35+
bit_or,
36+
bit_sal,
37+
bit_sar,
38+
bit_xor,
39+
branch,
40+
ceil,
41+
circle,
42+
contains,
43+
count,
44+
db,
45+
db_create,
46+
db_drop,
47+
db_list,
48+
december,
49+
desc,
50+
distance,
51+
distinct,
52+
div,
53+
do,
54+
epoch_time,
55+
eq,
56+
error,
57+
february,
58+
floor,
59+
format,
60+
friday,
61+
ge,
62+
geojson,
63+
grant,
64+
group,
65+
gt,
66+
http,
67+
info,
68+
intersects,
69+
iso8601,
70+
january,
71+
js,
72+
json,
73+
july,
74+
june,
75+
le,
76+
line,
77+
literal,
78+
lt,
79+
make_timezone,
80+
map,
81+
march,
82+
max,
83+
maxval,
84+
may,
85+
min,
86+
minval,
87+
mod,
88+
monday,
89+
mul,
90+
ne,
91+
not_,
92+
november,
93+
now,
94+
object,
95+
october,
96+
or_,
97+
point,
98+
polygon,
99+
random,
100+
range,
101+
reduce,
102+
round,
103+
row,
104+
saturday,
105+
september,
106+
sub,
107+
sum,
108+
sunday,
109+
table,
110+
table_create,
111+
table_drop,
112+
table_list,
113+
thursday,
114+
time,
115+
tuesday,
116+
type_of,
117+
union,
118+
uuid,
119+
wednesday,
34120
)
35-
# pylint: enable=redefined-builtin
121+
122+
# pylint: enable=redefined-builtin, unused-import
36123

37124
__version__ = "2.5.0"
38125

39126
# Create the r namespace object containing all query functions
40127
r = SimpleNamespace()
41128

42129
query_functions = {
43-
'add': add, 'and_': and_, 'april': april, 'args': args, 'asc': asc,
44-
'august': august, 'avg': avg, 'binary': binary, 'bit_and': bit_and,
45-
'bit_not': bit_not, 'bit_or': bit_or, 'bit_sal': bit_sal, 'bit_sar': bit_sar,
46-
'bit_xor': bit_xor, 'branch': branch, 'ceil': ceil, 'circle': circle,
47-
'contains': contains, 'count': count, 'db': db, 'db_create': db_create,
48-
'db_drop': db_drop, 'db_list': db_list, 'december': december, 'desc': desc,
49-
'distance': distance, 'distinct': distinct, 'div': div, 'do': do,
50-
'epoch_time': epoch_time, 'eq': eq, 'error': error, 'february': february,
51-
'floor': floor, 'format': format, 'friday': friday, 'ge': ge, 'geojson': geojson,
52-
'grant': grant, 'group': group, 'gt': gt, 'http': http, 'info': info,
53-
'intersects': intersects, 'iso8601': iso8601, 'january': january, 'json': json,
54-
'july': july, 'june': june, 'le': le, 'line': line, 'literal': literal,
55-
'lt': lt, 'make_timezone': make_timezone, 'map': map, 'march': march,
56-
'max': max, 'maxval': maxval, 'may': may, 'min': min, 'minval': minval,
57-
'mod': mod, 'monday': monday, 'mul': mul, 'ne': ne, 'not_': not_,
58-
'november': november, 'now': now, 'object': object, 'october': october,
59-
'or_': or_, 'point': point, 'polygon': polygon, 'random': random,
60-
'range': range, 'reduce': reduce, 'round': round, 'row': row,
61-
'saturday': saturday, 'september': september, 'sub': sub, 'sum': sum,
62-
'sunday': sunday, 'table': table, 'table_create': table_create,
63-
'table_drop': table_drop, 'table_list': table_list, 'thursday': thursday,
64-
'time': time, 'tuesday': tuesday, 'type_of': type_of, 'union': union,
65-
'uuid': uuid, 'wednesday': wednesday, 'js': js
130+
"add": add,
131+
"and_": and_,
132+
"april": april,
133+
"args": args,
134+
"asc": asc,
135+
"august": august,
136+
"avg": avg,
137+
"binary": binary,
138+
"bit_and": bit_and,
139+
"bit_not": bit_not,
140+
"bit_or": bit_or,
141+
"bit_sal": bit_sal,
142+
"bit_sar": bit_sar,
143+
"bit_xor": bit_xor,
144+
"branch": branch,
145+
"ceil": ceil,
146+
"circle": circle,
147+
"contains": contains,
148+
"count": count,
149+
"db": db,
150+
"db_create": db_create,
151+
"db_drop": db_drop,
152+
"db_list": db_list,
153+
"december": december,
154+
"desc": desc,
155+
"distance": distance,
156+
"distinct": distinct,
157+
"div": div,
158+
"do": do,
159+
"epoch_time": epoch_time,
160+
"eq": eq,
161+
"error": error,
162+
"february": february,
163+
"floor": floor,
164+
"format": format,
165+
"friday": friday,
166+
"ge": ge,
167+
"geojson": geojson,
168+
"grant": grant,
169+
"group": group,
170+
"gt": gt,
171+
"http": http,
172+
"info": info,
173+
"intersects": intersects,
174+
"iso8601": iso8601,
175+
"january": january,
176+
"json": json,
177+
"july": july,
178+
"june": june,
179+
"le": le,
180+
"line": line,
181+
"literal": literal,
182+
"lt": lt,
183+
"make_timezone": make_timezone,
184+
"map": map,
185+
"march": march,
186+
"max": max,
187+
"maxval": maxval,
188+
"may": may,
189+
"min": min,
190+
"minval": minval,
191+
"mod": mod,
192+
"monday": monday,
193+
"mul": mul,
194+
"ne": ne,
195+
"not_": not_,
196+
"november": november,
197+
"now": now,
198+
"object": object,
199+
"october": october,
200+
"or_": or_,
201+
"point": point,
202+
"polygon": polygon,
203+
"random": random,
204+
"range": range,
205+
"reduce": reduce,
206+
"round": round,
207+
"row": row,
208+
"saturday": saturday,
209+
"september": september,
210+
"sub": sub,
211+
"sum": sum,
212+
"sunday": sunday,
213+
"table": table,
214+
"table_create": table_create,
215+
"table_drop": table_drop,
216+
"table_list": table_list,
217+
"thursday": thursday,
218+
"time": time,
219+
"tuesday": tuesday,
220+
"type_of": type_of,
221+
"union": union,
222+
"uuid": uuid,
223+
"wednesday": wednesday,
224+
"js": js,
66225
}
67226

68227
for name, func in query_functions.items():
@@ -85,7 +244,6 @@ def __init__(self):
85244
net.Connection._r = self
86245
self.connection_type = None
87246

88-
# Ensure the `make_connection` function is not overridden accidentally
89247
self.make_connection = self.net.make_connection
90248
self.set_loop_type(None)
91249

@@ -103,16 +261,20 @@ def set_loop_type(self, library=None) -> None:
103261
library = None
104262

105263
if library == "tornado":
106-
warnings.warn(f"{library} is not yet supported, using the default one")
107-
library = None
264+
# pylint: disable=import-outside-toplevel
265+
from rethinkdb.net_tornado import Connection as TornadoConnection
266+
267+
self.connection_type = TornadoConnection
108268

109269
if library == "trio":
110270
warnings.warn(f"{library} is not yet supported, using the default one")
111271
library = None
112272

113273
if library == "twisted":
114-
warnings.warn(f"{library} is not yet supported, using the default one")
115-
library = None
274+
# pylint: disable=import-outside-toplevel
275+
from rethinkdb.net_twisted import Connection as TwistedConnection
276+
277+
self.connection_type = TwistedConnection
116278

117279
if library is None or self.connection_type is None:
118280
self.connection_type = self.net.DefaultConnection

0 commit comments

Comments
 (0)