Skip to content

Commit 17dd0e6

Browse files
joshthowardfindepi
authored andcommitted
Added flake8 test and updated affected code
1 parent d99d2b8 commit 17dd0e6

File tree

8 files changed

+34
-47
lines changed

8 files changed

+34
-47
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ jobs:
2929
- name: Run tests
3030
run: |
3131
pytest -s tests/ integration_tests/
32+
- name: Run linter
33+
run: |
34+
flake8

integration_tests/fixtures.py renamed to integration_tests/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
TRINO_PORT = 8080
3535

3636

37-
def is_process_alive(pid):
38-
try:
39-
os.kill(pid, 0)
40-
except ProcessLookupError:
41-
return False
42-
return True
43-
44-
4537
def get_local_port():
4638
with closing(socket.socket()) as s:
4739
s.bind(("localhost", 0))

integration_tests/test_dbapi.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
# limitations under the License.
1212
from __future__ import absolute_import, division, print_function
1313
from datetime import datetime
14-
import uuid
1514
import math
1615

17-
import fixtures
18-
from fixtures import run_trino
16+
from conftest import TRINO_VERSION
1917
import pytest
2018
import pytz
2119

@@ -53,7 +51,7 @@ def test_select_query(trino_connection):
5351
rows = cur.fetchall()
5452
assert len(rows) > 0
5553
row = rows[0]
56-
assert row[2] == fixtures.TRINO_VERSION
54+
assert row[2] == TRINO_VERSION
5755
columns = dict([desc[:2] for desc in cur.description])
5856
assert columns["node_id"] == "varchar"
5957
assert columns["http_uri"] == "varchar"
@@ -97,7 +95,7 @@ def test_none_query_param(trino_connection):
9795
cur.execute("SELECT ?", params=(None,))
9896
rows = cur.fetchall()
9997

100-
assert rows[0][0] == None
98+
assert rows[0][0] is None
10199

102100

103101
def test_string_query_param(trino_connection):
@@ -112,18 +110,13 @@ def test_string_query_param(trino_connection):
112110
def test_datetime_query_param(trino_connection):
113111
cur = trino_connection.cursor()
114112

115-
cur.execute(
116-
"SELECT ?",
117-
params=(datetime(2020, 1, 1, 0, 0, 0),)
118-
)
113+
cur.execute("SELECT ?", params=(datetime(2020, 1, 1, 0, 0, 0),))
119114
rows = cur.fetchall()
120115

121116
assert rows[0][0] == "2020-01-01 00:00:00.000"
122117

123-
cur.execute(
124-
"SELECT ?",
125-
params=(datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),)
126-
)
118+
cur.execute("SELECT ?",
119+
params=(datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),))
127120
rows = cur.fetchall()
128121

129122
assert rows[0][0] == "2020-01-01 00:00:00.000 UTC"
@@ -138,12 +131,10 @@ def test_array_query_param(trino_connection):
138131

139132
assert rows[0][0] == [1, 2, 3]
140133

141-
cur.execute(
142-
"SELECT ?",
143-
params=([[1, 2, 3],[4,5,6]],))
134+
cur.execute("SELECT ?", params=([[1, 2, 3], [4, 5, 6]],))
144135
rows = cur.fetchall()
145136

146-
assert rows[0][0] == [[1, 2, 3],[4,5,6]]
137+
assert rows[0][0] == [[1, 2, 3], [4, 5, 6]]
147138

148139
cur.execute("SELECT TYPEOF(?)", params=([1, 2, 3],))
149140
rows = cur.fetchall()
@@ -171,12 +162,12 @@ def test_boolean_query_param(trino_connection):
171162
cur.execute("SELECT ?", params=(True,))
172163
rows = cur.fetchall()
173164

174-
assert rows[0][0] == True
165+
assert rows[0][0] is True
175166

176167
cur.execute("SELECT ?", params=(False,))
177168
rows = cur.fetchall()
178169

179-
assert rows[0][0] == False
170+
assert rows[0][0] is False
180171

181172

182173
def test_float_query_param(trino_connection):
@@ -201,6 +192,7 @@ def test_float_nan_query_param(trino_connection):
201192

202193
@pytest.mark.skip(reason="Nan currently not returning the correct python type fon inf")
203194
def test_float_inf_query_param(trino_connection):
195+
cur = trino_connection.cursor()
204196
cur.execute("SELECT ?", params=(float("inf"),))
205197
rows = cur.fetchall()
206198

@@ -368,15 +360,15 @@ def test_transaction_multiple(trino_connection_with_transaction):
368360
assert len(rows1) == 1000
369361
assert len(rows2) == 1000
370362

363+
371364
def test_invalid_query_throws_correct_error(trino_connection):
372-
"""
373-
tests that an invalid query raises the correct exception
365+
"""Tests that an invalid query raises the correct exception
374366
"""
375367
cur = trino_connection.cursor()
376368
with pytest.raises(TrinoQueryError):
377369
cur.execute(
378370
"""
379-
select * FRMO foo WHERE x = ?;
371+
select * FRMO foo WHERE x = ?;
380372
""",
381373
params=(3,),
382374
)

setup.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
[aliases]
22
test=pytest
3+
4+
[flake8]
5+
max-line-length = 120
6+
# W503 raises a warning when there is a line break before a binary operator.
7+
# This is best practice according to PEP 8 and the rule should be ignored.
8+
#
9+
# https://www.flake8rules.com/rules/W503.html
10+
# https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
11+
ignore = W503

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
all_require = [kerberos_require]
3333

34-
tests_require = all_require + ["httpretty", "pytest", "pytest-runner", "mock", "pytz"]
34+
tests_require = all_require + ["httpretty", "pytest", "pytest-runner", "mock", "pytz", "flake8"]
3535

3636
py27_require = ["ipaddress", "typing"]
3737

tests/test_client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import httpretty
1717
import pytest
1818
import requests
19-
import socket
2019
import time
2120

2221
try:
@@ -26,7 +25,7 @@
2625
import mock
2726

2827
from requests_kerberos.exceptions import KerberosExchangeError
29-
from trino.client import PROXIES, TrinoQuery, TrinoRequest, TrinoResult
28+
from trino.client import TrinoQuery, TrinoRequest, TrinoResult
3029
from trino.auth import KerberosAuthentication
3130
from trino import constants
3231
import trino.exceptions
@@ -143,7 +142,7 @@
143142
},
144143
],
145144
"taskDownloadUris": [],
146-
"partialCancelUri": "http://localhost:8080/v1/stage/20161116_195728_00000_xtnym.0", # NOQA
145+
"partialCancelUri": "http://localhost:8080/v1/stage/20161116_195728_00000_xtnym.0", # NOQA: E501
147146
"stats": {
148147
"nodes": 2,
149148
"processedBytes": 880,
@@ -192,7 +191,7 @@
192191
"queuedSplits": 0,
193192
"wallTimeMillis": 36,
194193
},
195-
"infoUri": "http://coordinator:8080/query.html?20161116_195728_00000_xtnym", # NOQA
194+
"infoUri": "http://coordinator:8080/query.html?20161116_195728_00000_xtnym", # NOQA: E501
196195
}
197196

198197
RESP_ERROR_GET_0 = {
@@ -214,8 +213,8 @@
214213
"com.facebook.presto.sql.tree.Table.accept(Table.java:50)",
215214
"com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:22)",
216215
"com.facebook.presto.sql.analyzer.StatementAnalyzer.analyzeFrom(StatementAnalyzer.java:1413)",
217-
"com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuerySpecification(StatementAnalyzer.java:670)",
218-
"com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuerySpecification(StatementAnalyzer.java:166)",
216+
"com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuerySpecification(StatementAnalyzer.java:670)", # NOQA: E501
217+
"com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuerySpecification(StatementAnalyzer.java:166)", # NOQA: E501
219218
"com.facebook.presto.sql.tree.QuerySpecification.accept(QuerySpecification.java:125)",
220219
"com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:22)",
221220
"com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuery(StatementAnalyzer.java:438)",
@@ -672,4 +671,3 @@ def json(self):
672671

673672
# Validate the result is an instance of TrinoResult
674673
assert isinstance(result, TrinoResult)
675-

trino/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
from . import exceptions
2121
from . import logging
2222

23+
__all__ = ['auth', 'dbapi', 'client', 'constants', 'exceptions', 'logging']
24+
2325
__version__ = "0.305.0"

trino/dbapi.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@
2323

2424
from typing import Any, List, Optional # NOQA for mypy types
2525

26-
try:
27-
from urllib.parse import urlencode
28-
except ImportError:
29-
# Python 2
30-
from urllib import urlencode
31-
3226
import copy
3327
import uuid
3428
import datetime
35-
import re
3629
import math
3730

3831
from trino import constants
@@ -283,7 +276,6 @@ def _prepare_statement(self, operation, statement_name):
283276

284277
raise trino.exceptions.FailedToObtainAddedPrepareHeader
285278

286-
287279
def _get_added_prepare_statement_trino_query(
288280
self,
289281
statement_name,
@@ -347,7 +339,6 @@ def _format_prepared_param(self, param):
347339

348340
raise trino.exceptions.NotSupportedError("Query parameter of type '%s' is not supported." % type(param))
349341

350-
351342
def _deallocate_prepare_statement(self, added_prepare_header, statement_name):
352343
sql = 'DEALLOCATE PREPARE ' + statement_name
353344

0 commit comments

Comments
 (0)