@@ -115,7 +115,6 @@ class TestParameterizedQueries(PySQLPytestTestCase):
115115 Primitive .NONE : "null_col" ,
116116 }
117117
118-
119118 def _get_inline_table_column (self , value ):
120119 return self .inline_type_map [Primitive (value )]
121120
@@ -225,7 +224,11 @@ def _get_one_result(
225224 if approach == ParameterApproach .INLINE :
226225 # inline mode always uses ParamStyle.PYFORMAT
227226 # inline mode doesn't support positional parameters
228- return self ._inline_roundtrip (params , paramstyle = ParamStyle .PYFORMAT ,target_column = self ._get_inline_table_column (params .get ("p" )))
227+ return self ._inline_roundtrip (
228+ params ,
229+ paramstyle = ParamStyle .PYFORMAT ,
230+ target_column = self ._get_inline_table_column (params .get ("p" )),
231+ )
229232 elif approach == ParameterApproach .NATIVE :
230233 # native mode can use either ParamStyle.NAMED or ParamStyle.PYFORMAT
231234 # native mode can use either ParameterStructure.NAMED or ParameterStructure.POSITIONAL
@@ -252,7 +255,7 @@ def _eq(self, actual, expected: Primitive):
252255 actual_parsed = actual .tolist ()
253256 elif expected == Primitive .MAPS :
254257 expected_parsed = list (expected .value .items ())
255-
258+
256259 return actual_parsed == expected_parsed
257260
258261 def _parse_to_common_type (self , value ):
@@ -263,28 +266,30 @@ def _parse_to_common_type(self, value):
263266 MAP Datatype on server is returned as a list of tuples
264267 Ex:
265268 {"a":1,"b":2} -> [("a",1),("b",2)]
266-
269+
267270 ARRAY Datatype on server is returned as a numpy array
268271 Ex:
269272 ["a","b","c"] -> np.array(["a","b","c"],dtype=object)
270-
273+
271274 Primitive datatype on server is returned as a numpy primitive
272275 Ex:
273276 1 -> np.int64(1)
274277 2 -> np.int32(2)
275278 """
276279 if value is None :
277280 return None
278- elif isinstance (value , (Sequence ,np .ndarray )) and not isinstance (value , (str , bytes )):
281+ elif isinstance (value , (Sequence , np .ndarray )) and not isinstance (
282+ value , (str , bytes )
283+ ):
279284 return tuple (value )
280- elif isinstance (value ,dict ):
285+ elif isinstance (value , dict ):
281286 return tuple (value .items ())
282287 elif isinstance (value , np .generic ):
283288 return value .item ()
284289 else :
285290 return value
286291
287- def _recursive_compare (self ,actual , expected ):
292+ def _recursive_compare (self , actual , expected ):
288293 """
289294 Function to compare the :actual and :expected values, recursively checks and ensures that all the data matches till the leaf level
290295
@@ -301,10 +306,12 @@ def _recursive_compare(self,actual, expected):
301306 if isinstance (actual_parsed , (list , tuple )):
302307 if len (actual_parsed ) != len (expected_parsed ):
303308 return False
304- return all (self ._recursive_compare (o1 , o2 ) for o1 , o2 in zip (actual_parsed , expected_parsed ))
305-
306- return actual_parsed == expected_parsed
309+ return all (
310+ self ._recursive_compare (o1 , o2 )
311+ for o1 , o2 in zip (actual_parsed , expected_parsed )
312+ )
307313
314+ return actual_parsed == expected_parsed
308315
309316 @pytest .mark .parametrize ("primitive" , Primitive )
310317 @pytest .mark .parametrize (
@@ -436,24 +443,33 @@ def test_readme_example(self):
436443 assert result [0 ].p == "foo"
437444
438445 @pytest .mark .parametrize (
439- "col_name,data" ,[
440- ("array_map_col" , [{"a" : 1 , "b" : 2 }, {"c" : 3 , "d" : 4 }]),
441- ("map_array_col" , {1 : ["a" , "b" ], 2 : ["c" , "d" ]}),
442- ])
443- def test_inline_recursive_complex_type (self ,col_name ,data ):
444- params = {'p' :data }
445- result = self ._inline_roundtrip (params = params ,paramstyle = ParamStyle .PYFORMAT ,target_column = col_name )
446+ "col_name,data" ,
447+ [
448+ ("array_map_col" , [{"a" : 1 , "b" : 2 }, {"c" : 3 , "d" : 4 }]),
449+ ("map_array_col" , {1 : ["a" , "b" ], 2 : ["c" , "d" ]}),
450+ ],
451+ )
452+ def test_inline_recursive_complex_type (self , col_name , data ):
453+ params = {"p" : data }
454+ result = self ._inline_roundtrip (
455+ params = params , paramstyle = ParamStyle .PYFORMAT , target_column = col_name
456+ )
446457 assert self ._recursive_compare (result .col , data )
447-
448-
458+
449459 @pytest .mark .parametrize (
450460 "description,data" ,
451461 [
452- ("ARRAY<MAP<STRING,INT>>" ,[{"a" : 1 , "b" : 2 }, {"c" : 3 , "d" : 4 }]),
453- ("MAP<INT,ARRAY<STRING>>" ,{1 : ["a" , "b" ], 2 : ["c" , "d" ]}),
454- ("ARRAY<ARRAY<INT>>" ,[[1 ,2 ,3 ],[1 ,2 ,3 ]]),
455- ("ARRAY<ARRAY<ARRAY<INT>>>" ,[[[1 ,2 ,3 ],[1 ,2 ,3 ]],[[1 ,2 ,3 ],[1 ,2 ,3 ]]]),
456- ("MAP<STRING,MAP<STRING,STRING>>" ,{"a" :{"b" :"c" ,"d" :"e" },"f" :{"g" :"h" ,"i" :"j" }})
462+ ("ARRAY<MAP<STRING,INT>>" , [{"a" : 1 , "b" : 2 }, {"c" : 3 , "d" : 4 }]),
463+ ("MAP<INT,ARRAY<STRING>>" , {1 : ["a" , "b" ], 2 : ["c" , "d" ]}),
464+ ("ARRAY<ARRAY<INT>>" , [[1 , 2 , 3 ], [1 , 2 , 3 ]]),
465+ (
466+ "ARRAY<ARRAY<ARRAY<INT>>>" ,
467+ [[[1 , 2 , 3 ], [1 , 2 , 3 ]], [[1 , 2 , 3 ], [1 , 2 , 3 ]]],
468+ ),
469+ (
470+ "MAP<STRING,MAP<STRING,STRING>>" ,
471+ {"a" : {"b" : "c" , "d" : "e" }, "f" : {"g" : "h" , "i" : "j" }},
472+ ),
457473 ],
458474 )
459475 @pytest .mark .parametrize (
@@ -462,14 +478,20 @@ def test_inline_recursive_complex_type(self,col_name,data):
462478 (ParamStyle .NONE , ParameterStructure .POSITIONAL ),
463479 (ParamStyle .PYFORMAT , ParameterStructure .NAMED ),
464480 (ParamStyle .NAMED , ParameterStructure .NAMED ),
465- ]
481+ ],
466482 )
467- def test_native_recursive_complex_type (self ,description ,data ,paramstyle ,parameter_structure ):
468- if (paramstyle == ParamStyle .NONE ):
469- params = [data ]
483+ def test_native_recursive_complex_type (
484+ self , description , data , paramstyle , parameter_structure
485+ ):
486+ if paramstyle == ParamStyle .NONE :
487+ params = [data ]
470488 else :
471- params = {'p' :data }
472- result = self ._native_roundtrip (parameters = params ,paramstyle = paramstyle ,parameter_structure = parameter_structure )
489+ params = {"p" : data }
490+ result = self ._native_roundtrip (
491+ parameters = params ,
492+ paramstyle = paramstyle ,
493+ parameter_structure = parameter_structure ,
494+ )
473495 assert self ._recursive_compare (result .col , data )
474496
475497
0 commit comments