@@ -48,12 +48,14 @@ def test_cursor_fetch(mocked_connection):
4848 "rowcount" : 2 ,
4949 "duration" : 123 ,
5050 }
51- with mock .patch .object (mocked_connection . client ,
52- ' sql' ,
53- return_value = response ):
51+ with mock .patch .object (
52+ mocked_connection . client , " sql" , return_value = response
53+ ):
5454 cursor .execute ("" )
55- assert cursor .fetchone () == ['foo' , '10.10.10.1' ]
56- assert cursor .fetchmany () == [["bar" , "10.10.10.2" ], ]
55+ assert cursor .fetchone () == ["foo" , "10.10.10.1" ]
56+ assert cursor .fetchmany () == [
57+ ["bar" , "10.10.10.2" ],
58+ ]
5759
5860
5961def test_cursor_executemany (mocked_connection ):
@@ -64,25 +66,24 @@ def test_cursor_executemany(mocked_connection):
6466 "col_types" : [],
6567 "cols" : [],
6668 "duration" : 123 ,
67- "results" : [{' rowcount' : 1 , ' rowcount:' : 1 }]
69+ "results" : [{" rowcount" : 1 , " rowcount:" : 1 }],
6870 }
69- with mock .patch .object (mocked_connection .client ,
70- 'sql' ,
71- return_value = response ):
72-
71+ with mock .patch .object (
72+ mocked_connection .client , "sql" , return_value = response
73+ ):
7374 cursor = mocked_connection .cursor ()
7475 result = cursor .executemany ("some sql" , ())
7576
7677 assert isinstance (result , list )
77- assert response [' results' ] == result
78+ assert response [" results" ] == result
7879
7980
8081def test_create_with_timezone_as_datetime_object (mocked_connection ):
8182 """
82- The cursor can return timezone-aware `datetime` objects when requested.
83- Switching the time zone at runtime on the cursor object is possible.
84- Here: Use a `datetime.timezone` instance.
85- """
83+ The cursor can return timezone-aware `datetime` objects when requested.
84+ Switching the time zone at runtime on the cursor object is possible.
85+ Here: Use a `datetime.timezone` instance.
86+ """
8687 tz_mst = datetime .timezone (datetime .timedelta (hours = 7 ), name = "MST" )
8788 cursor = mocked_connection .cursor (time_zone = tz_mst )
8889
@@ -101,8 +102,9 @@ def test_create_with_timezone_as_pytz_object(mocked_connection):
101102 Here: Use a `pytz.timezone` instance.
102103 """
103104
104- cursor = (mocked_connection
105- .cursor (time_zone = pytz .timezone ("Australia/Sydney" )))
105+ cursor = mocked_connection .cursor (
106+ time_zone = pytz .timezone ("Australia/Sydney" )
107+ )
106108 assert cursor .time_zone .tzname (None ) == "Australia/Sydney"
107109
108110 # Apparently, when using `pytz`, the timezone object does not return
@@ -136,8 +138,9 @@ def test_create_with_timezone_as_utc_offset_success(mocked_connection):
136138
137139 cursor = mocked_connection .cursor (time_zone = "-1145" )
138140 assert cursor .time_zone .tzname (None ) == "-1145"
139- assert cursor .time_zone .utcoffset (None ) == datetime .timedelta (days = - 1 ,
140- seconds = 44100 )
141+ assert cursor .time_zone .utcoffset (None ) == datetime .timedelta (
142+ days = - 1 , seconds = 44100
143+ )
141144
142145
143146def test_create_with_timezone_as_utc_offset_failure (mocked_connection ):
@@ -147,14 +150,15 @@ def test_create_with_timezone_as_utc_offset_failure(mocked_connection):
147150
148151 with pytest .raises (ValueError ) as err :
149152 mocked_connection .cursor (time_zone = "foobar" )
150- assert err == \
151- "Time zone 'foobar' is given in invalid UTC offset format"
153+ assert err == "Time zone 'foobar' is given in invalid UTC offset format"
152154
153155 with pytest .raises (ValueError ) as err :
154156 mocked_connection .cursor (time_zone = "+abcd" )
155- assert err == \
156- "Time zone '+abcd' is given in invalid UTC offset format: " + \
157- "invalid literal for int() with base 10: '+ab'"
157+ assert (
158+ err
159+ == "Time zone '+abcd' is given in invalid UTC offset format: "
160+ + "invalid literal for int() with base 10: '+ab'"
161+ )
158162
159163
160164def test_create_with_timezone_connection_cursor_precedence (mocked_connection ):
@@ -164,7 +168,7 @@ def test_create_with_timezone_connection_cursor_precedence(mocked_connection):
164168 """
165169 connection = connect (
166170 client = mocked_connection .client ,
167- time_zone = pytz .timezone ("Australia/Sydney" )
171+ time_zone = pytz .timezone ("Australia/Sydney" ),
168172 )
169173 cursor = connection .cursor (time_zone = "+0530" )
170174 assert cursor .time_zone .tzname (None ) == "+0530"
@@ -200,8 +204,8 @@ def test_execute_custom_converter(mocked_connection):
200204 converter = DefaultTypeConverter (
201205 {
202206 DataType .BIT : lambda value : value is not None
203- and int (value [2 :- 1 ], 2 )
204- or None
207+ and int (value [2 :- 1 ], 2 )
208+ or None
205209 }
206210 )
207211 cursor = mocked_connection .cursor (converter = converter )
@@ -216,9 +220,9 @@ def test_execute_custom_converter(mocked_connection):
216220 "duration" : 123 ,
217221 }
218222
219- with mock .patch .object (mocked_connection . client ,
220- ' sql' ,
221- return_value = response ):
223+ with mock .patch .object (
224+ mocked_connection . client , " sql" , return_value = response
225+ ):
222226 cursor .execute ("" )
223227 result = cursor .fetchall ()
224228
@@ -258,9 +262,8 @@ def test_execute_with_converter_and_invalid_data_type(mocked_connection):
258262 "duration" : 123 ,
259263 }
260264 with mock .patch .object (
261- mocked_connection .client ,
262- 'sql' ,
263- return_value = response ):
265+ mocked_connection .client , "sql" , return_value = response
266+ ):
264267 cursor .execute ("" )
265268 with pytest .raises (ValueError ) as e :
266269 cursor .fetchone ()
@@ -277,9 +280,9 @@ def test_execute_array_with_converter(mocked_connection):
277280 "rowcount" : 1 ,
278281 "duration" : 123 ,
279282 }
280- with mock .patch .object (mocked_connection . client ,
281- ' sql' ,
282- return_value = response ):
283+ with mock .patch .object (
284+ mocked_connection . client , " sql" , return_value = response
285+ ):
283286 cursor .execute ("" )
284287 result = cursor .fetchone ()
285288
@@ -301,14 +304,15 @@ def test_execute_array_with_converter_invalid(mocked_connection):
301304 }
302305 # Converting collections only works for `ARRAY`s. (ID=100).
303306 # When using `DOUBLE` (ID=6), it should raise an Exception.
304- with mock .patch .object (mocked_connection . client ,
305- ' sql' ,
306- return_value = response ):
307+ with mock .patch .object (
308+ mocked_connection . client , " sql" , return_value = response
309+ ):
307310 cursor .execute ("" )
308311 with pytest .raises (ValueError ) as e :
309312 cursor .fetchone ()
310- assert e .exception .args == ("Data type 6 is not implemented"
311- " as collection type" )
313+ assert e .exception .args == (
314+ "Data type 6 is not implemented as collection type"
315+ )
312316
313317
314318def test_execute_nested_array_with_converter (mocked_connection ):
@@ -332,9 +336,9 @@ def test_execute_nested_array_with_converter(mocked_connection):
332336 "duration" : 123 ,
333337 }
334338
335- with mock .patch .object (mocked_connection . client ,
336- ' sql' ,
337- return_value = response ):
339+ with mock .patch .object (
340+ mocked_connection . client , " sql" , return_value = response
341+ ):
338342 cursor .execute ("" )
339343 result = cursor .fetchone ()
340344 assert result == [
@@ -358,9 +362,9 @@ def test_executemany_with_converter(mocked_connection):
358362 "rowcount" : 1 ,
359363 "duration" : 123 ,
360364 }
361- with mock .patch .object (mocked_connection . client ,
362- ' sql' ,
363- return_value = response ):
365+ with mock .patch .object (
366+ mocked_connection . client , " sql" , return_value = response
367+ ):
364368 cursor .executemany ("" , [])
365369 result = cursor .fetchall ()
366370
@@ -383,9 +387,9 @@ def test_execute_with_timezone(mocked_connection):
383387 [None , None ],
384388 ],
385389 }
386- with mock .patch .object (mocked_connection . client ,
387- ' sql' ,
388- return_value = response ):
390+ with mock .patch .object (
391+ mocked_connection . client , " sql" , return_value = response
392+ ):
389393 # Run execution and verify the returned `datetime` object is
390394 # timezone-aware, using the designated timezone object.
391395 cursor .execute ("" )
@@ -456,7 +460,7 @@ def test_cursor_close(mocked_connection):
456460 assert not cursor ._result
457461 assert cursor .duration == - 1
458462
459- with pytest .raises (ProgrammingError , match = ' Connection closed' ):
463+ with pytest .raises (ProgrammingError , match = " Connection closed" ):
460464 mocked_connection .close ()
461465 cursor .execute ("" )
462466
0 commit comments