Skip to content

Commit 1548b03

Browse files
committed
Fix linting
1 parent 08e9401 commit 1548b03

File tree

7 files changed

+118
-80
lines changed

7 files changed

+118
-80
lines changed

src/crate/client/cursor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ def _convert_rows(self):
236236

237237
# Process result rows with conversion.
238238
for row in self._result["rows"]:
239-
yield [convert(value) for convert, value in zip(converters, row)]
239+
yield [convert(value) for convert, value
240+
in zip(converters, row, strict=False)]
240241

241242
@property
242243
def time_zone(self):

tests/client/test_connection.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
2-
from unittest import TestCase
3-
from unittest.mock import patch, MagicMock
2+
from unittest.mock import MagicMock, patch
43

54
from urllib3 import Timeout
65

@@ -15,22 +14,24 @@ def test_lowest_server_version():
1514
"""
1615
Verify the lowest server version is correctly set.
1716
"""
17+
servers = "localhost:4200 localhost:4201 localhost:4202 localhost:4207"
1818
infos = [
1919
(None, None, "1.0.3"),
2020
(None, None, "5.5.2"),
2121
(None, None, "6.0.0"),
2222
(None, None, "not a version"),
2323
]
2424

25-
client = Client(servers="localhost:4200 localhost:4201 localhost:4202 localhost:4207")
25+
client = Client(servers=servers)
2626
client.server_infos = lambda server: infos.pop()
2727
connection = connect(client=client)
2828
assert (1, 0, 3) == connection.lowest_server_version.version
2929

3030

3131
def test_invalid_server_version():
3232
"""
33-
Verify that when no correct version is set, the default (0, 0, 0) is returned.
33+
Verify that when no correct version is set,
34+
the default (0, 0, 0) is returned.
3435
"""
3536
client = Client(servers="localhost:4200")
3637
client.server_infos = lambda server: (None, None, "No version")
@@ -42,11 +43,12 @@ def test_context_manager():
4243
"""
4344
Verify the context manager implementation of `Connection`.
4445
"""
45-
with patch('crate.client.http.Client.close', return_value=MagicMock()) as close_func:
46+
close_method = 'crate.client.http.Client.close'
47+
with patch(close_method, return_value=MagicMock()) as close_func:
4648
with connect("localhost:4200") as conn:
47-
assert conn._closed == False
49+
assert not conn._closed
4850

49-
assert conn._closed == True
51+
assert conn._closed
5052
# Checks that the close method of the client
5153
# is called when the connection is closed.
5254
close_func.assert_called_once()
@@ -69,7 +71,9 @@ def test_connection_mock():
6971
connection = connect(crate_host, client=mock)
7072

7173
assert isinstance(connection, Connection)
72-
assert connection.client.server_infos("foo") == ("localhost:4200", "my server", "0.42.0")
74+
assert connection.client.server_infos("foo") == ("localhost:4200",
75+
"my server",
76+
"0.42.0")
7377

7478

7579
def test_with_timezone():

tests/client/test_cursor.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import datetime
2323
from ipaddress import IPv4Address
2424
from unittest import mock
25+
2526
import pytest
2627

2728
from crate.client.exceptions import ProgrammingError
@@ -61,7 +62,8 @@ def test_create_with_timezone_as_pytz_object(mocked_connection):
6162
Here: Use a `pytz.timezone` instance.
6263
"""
6364

64-
cursor = mocked_connection.cursor(time_zone=pytz.timezone("Australia/Sydney"))
65+
cursor = (mocked_connection
66+
.cursor(time_zone=pytz.timezone("Australia/Sydney")))
6567
assert cursor.time_zone.tzname(None) == "Australia/Sydney"
6668

6769
# Apparently, when using `pytz`, the timezone object does not return
@@ -83,7 +85,9 @@ def test_create_with_timezone_as_zoneinfo_object(mocked_connection):
8385

8486
def test_create_with_timezone_as_utc_offset_success(mocked_connection):
8587
"""
86-
Verify the cursor can return timezone-aware `datetime` objects when requested.
88+
Verify the cursor can return timezone-aware `datetime` objects when
89+
requested.
90+
8791
Here: Use a UTC offset in string format.
8892
"""
8993

@@ -93,7 +97,8 @@ def test_create_with_timezone_as_utc_offset_success(mocked_connection):
9397

9498
cursor = mocked_connection.cursor(time_zone="-1145")
9599
assert cursor.time_zone.tzname(None) == "-1145"
96-
assert cursor.time_zone.utcoffset(None) == datetime.timedelta(days=-1, seconds=44100)
100+
assert cursor.time_zone.utcoffset(None) == datetime.timedelta(days=-1,
101+
seconds=44100)
97102

98103

99104
def test_create_with_timezone_as_utc_offset_failure(mocked_connection):
@@ -172,7 +177,10 @@ def test_execute_custom_converter(mocked_connection):
172177
"duration": 123,
173178
}
174179

175-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
180+
with mock.patch.object(
181+
mocked_connection.client,
182+
'sql',
183+
return_value=response):
176184
cursor.execute("")
177185
result = cursor.fetchall()
178186

@@ -211,7 +219,11 @@ def test_execute_with_converter_and_invalid_data_type(mocked_connection):
211219
"rowcount": 1,
212220
"duration": 123,
213221
}
214-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
222+
with mock.patch.object(
223+
mocked_connection.client,
224+
'sql',
225+
return_value=response
226+
):
215227
cursor.execute("")
216228
with pytest.raises(ValueError) as e:
217229
cursor.fetchone()
@@ -228,7 +240,10 @@ def test_execute_array_with_converter(mocked_connection):
228240
"rowcount": 1,
229241
"duration": 123,
230242
}
231-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
243+
with mock.patch.object(
244+
mocked_connection.client,
245+
'sql',
246+
return_value=response):
232247
cursor.execute("")
233248
result = cursor.fetchone()
234249

@@ -238,7 +253,7 @@ def test_execute_array_with_converter(mocked_connection):
238253
]
239254

240255

241-
def test_execute_array_with_converter_and_invalid_collection_type(mocked_connection):
256+
def test_execute_array_with_converter_invalid(mocked_connection):
242257
converter = DefaultTypeConverter()
243258
cursor = mocked_connection.cursor(converter=converter)
244259
response = {
@@ -250,11 +265,14 @@ def test_execute_array_with_converter_and_invalid_collection_type(mocked_connect
250265
}
251266
# Converting collections only works for `ARRAY`s. (ID=100).
252267
# When using `DOUBLE` (ID=6), it should raise an Exception.
253-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
268+
with mock.patch.object(mocked_connection.client,
269+
'sql',
270+
return_value=response):
254271
cursor.execute("")
255272
with pytest.raises(ValueError) as e:
256273
cursor.fetchone()
257-
assert e.exception.args == "Data type 6 is not implemented as collection type"
274+
assert e.exception.args == ("Data type 6 is not implemented"
275+
" as collection type")
258276

259277

260278
def test_execute_nested_array_with_converter(mocked_connection):
@@ -278,7 +296,9 @@ def test_execute_nested_array_with_converter(mocked_connection):
278296
"duration": 123,
279297
}
280298

281-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
299+
with mock.patch.object(mocked_connection.client,
300+
'sql',
301+
return_value=response):
282302
cursor.execute("")
283303
result = cursor.fetchone()
284304
assert result == [
@@ -302,7 +322,9 @@ def test_executemany_with_converter(mocked_connection):
302322
"rowcount": 1,
303323
"duration": 123,
304324
}
305-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
325+
with mock.patch.object(mocked_connection.client,
326+
'sql',
327+
return_value=response):
306328
cursor.executemany("", [])
307329
result = cursor.fetchall()
308330

@@ -325,7 +347,9 @@ def test_execute_with_timezone(mocked_connection):
325347
[None, None],
326348
],
327349
}
328-
with mock.patch.object(mocked_connection.client, 'sql', return_value=response):
350+
with mock.patch.object(mocked_connection.client,
351+
'sql',
352+
return_value=response):
329353
# Run execution and verify the returned `datetime` object is
330354
# timezone-aware, using the designated timezone object.
331355
cursor.execute("")

tests/client/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def test_error_with_error_trace():
1313

1414
def test_blob_exception():
1515
err = BlobException(table="sometable", digest="somedigest")
16-
assert str(err) == "BlobException('sometable/somedigest)'"
16+
assert str(err) == "BlobException('sometable/somedigest)'"

0 commit comments

Comments
 (0)