2222import datetime
2323from ipaddress import IPv4Address
2424from unittest import mock
25+
2526import pytest
2627
2728from 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
8486def 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
99104def 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
260278def 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 ("" )
0 commit comments