@@ -405,20 +405,9 @@ def test_use_inline_off_by_default_with_warning(self, use_inline_params, caplog)
405
405
"Consider using native parameters." not in caplog .text
406
406
), "Log message should not be supressed"
407
407
408
- @pytest .mark .parametrize (
409
- "extra_params" ,
410
- [
411
- {},
412
- {
413
- "use_sea" : True ,
414
- "use_cloud_fetch" : False ,
415
- "enable_query_result_lz4_compression" : False ,
416
- },
417
- ],
418
- )
419
- def test_positional_native_params_with_defaults (self , extra_params ):
408
+ def test_positional_native_params_with_defaults (self ):
420
409
query = "SELECT ? col"
421
- with self .cursor (extra_params ) as cursor :
410
+ with self .cursor () as cursor :
422
411
result = cursor .execute (query , parameters = [1 ]).fetchone ()
423
412
424
413
assert result .col == 1
@@ -434,42 +423,19 @@ def test_positional_native_params_with_defaults(self, extra_params):
434
423
["foo" , "bar" , "baz" ],
435
424
),
436
425
)
437
- @pytest .mark .parametrize (
438
- "extra_params" ,
439
- [
440
- {},
441
- {
442
- "use_sea" : True ,
443
- "use_cloud_fetch" : False ,
444
- "enable_query_result_lz4_compression" : False ,
445
- },
446
- ],
447
- )
448
- def test_positional_native_multiple (self , params , extra_params ):
426
+ def test_positional_native_multiple (self , params ):
449
427
query = "SELECT ? `foo`, ? `bar`, ? `baz`"
450
428
451
- combined_params = {"use_inline_params" : False , ** extra_params }
452
- with self .cursor (extra_params = combined_params ) as cursor :
429
+ with self .cursor (extra_params = {"use_inline_params" : False }) as cursor :
453
430
result = cursor .execute (query , params ).fetchone ()
454
431
455
432
expected = [i .value if isinstance (i , DbsqlParameterBase ) else i for i in params ]
456
433
outcome = [result .foo , result .bar , result .baz ]
457
434
458
435
assert set (outcome ) == set (expected )
459
436
460
- @pytest .mark .parametrize (
461
- "extra_params" ,
462
- [
463
- {},
464
- {
465
- "use_sea" : True ,
466
- "use_cloud_fetch" : False ,
467
- "enable_query_result_lz4_compression" : False ,
468
- },
469
- ],
470
- )
471
- def test_readme_example (self , extra_params ):
472
- with self .cursor (extra_params ) as cursor :
437
+ def test_readme_example (self ):
438
+ with self .cursor () as cursor :
473
439
result = cursor .execute (
474
440
"SELECT :param `p`, * FROM RANGE(10)" , {"param" : "foo" }
475
441
).fetchall ()
@@ -533,42 +499,19 @@ def test_native_recursive_complex_type(
533
499
class TestInlineParameterSyntax (PySQLPytestTestCase ):
534
500
"""The inline parameter approach uses pyformat markers"""
535
501
536
- @pytest .mark .parametrize (
537
- "extra_params" ,
538
- [
539
- {},
540
- {
541
- "use_sea" : True ,
542
- "use_cloud_fetch" : False ,
543
- "enable_query_result_lz4_compression" : False ,
544
- },
545
- ],
546
- )
547
- def test_params_as_dict (self , extra_params ):
502
+ def test_params_as_dict (self ):
548
503
query = "SELECT %(foo)s foo, %(bar)s bar, %(baz)s baz"
549
504
params = {"foo" : 1 , "bar" : 2 , "baz" : 3 }
550
505
551
- combined_params = {"use_inline_params" : True , ** extra_params }
552
- with self .connection (extra_params = combined_params ) as conn :
506
+ with self .connection (extra_params = {"use_inline_params" : True }) as conn :
553
507
with conn .cursor () as cursor :
554
508
result = cursor .execute (query , parameters = params ).fetchone ()
555
509
556
510
assert result .foo == 1
557
511
assert result .bar == 2
558
512
assert result .baz == 3
559
513
560
- @pytest .mark .parametrize (
561
- "extra_params" ,
562
- [
563
- {},
564
- {
565
- "use_sea" : True ,
566
- "use_cloud_fetch" : False ,
567
- "enable_query_result_lz4_compression" : False ,
568
- },
569
- ],
570
- )
571
- def test_params_as_sequence (self , extra_params ):
514
+ def test_params_as_sequence (self ):
572
515
"""One side-effect of ParamEscaper using Python string interpolation to inline the values
573
516
is that it can work with "ordinal" parameters, but only if a user writes parameter markers
574
517
that are not defined with PEP-249. This test exists to prove that it works in the ideal case.
@@ -578,8 +521,7 @@ def test_params_as_sequence(self, extra_params):
578
521
query = "SELECT %s foo, %s bar, %s baz"
579
522
params = (1 , 2 , 3 )
580
523
581
- combined_params = {"use_inline_params" : True , ** extra_params }
582
- with self .connection (extra_params = combined_params ) as conn :
524
+ with self .connection (extra_params = {"use_inline_params" : True }) as conn :
583
525
with conn .cursor () as cursor :
584
526
result = cursor .execute (query , parameters = params ).fetchone ()
585
527
assert result .foo == 1
@@ -599,18 +541,7 @@ def test_inline_ordinals_can_break_sql(self):
599
541
):
600
542
cursor .execute (query , parameters = params )
601
543
602
- @pytest .mark .parametrize (
603
- "extra_params" ,
604
- [
605
- {},
606
- {
607
- "use_sea" : True ,
608
- "use_cloud_fetch" : False ,
609
- "enable_query_result_lz4_compression" : False ,
610
- },
611
- ],
612
- )
613
- def test_inline_named_dont_break_sql (self , extra_params ):
544
+ def test_inline_named_dont_break_sql (self ):
614
545
"""With inline mode, ordinal parameters can break the SQL syntax
615
546
because `%` symbols are used to wildcard match within LIKE statements. This test
616
547
just proves that's the case.
@@ -620,30 +551,17 @@ def test_inline_named_dont_break_sql(self, extra_params):
620
551
SELECT col_1 FROM base WHERE col_1 LIKE CONCAT(%(one)s, 'onite')
621
552
"""
622
553
params = {"one" : "%(one)s" }
623
- combined_params = {"use_inline_params" : True , ** extra_params }
624
- with self .cursor (extra_params = combined_params ) as cursor :
554
+ with self .cursor (extra_params = {"use_inline_params" : True }) as cursor :
625
555
result = cursor .execute (query , parameters = params ).fetchone ()
626
556
print ("hello" )
627
557
628
- @pytest .mark .parametrize (
629
- "extra_params" ,
630
- [
631
- {},
632
- {
633
- "use_sea" : True ,
634
- "use_cloud_fetch" : False ,
635
- "enable_query_result_lz4_compression" : False ,
636
- },
637
- ],
638
- )
639
- def test_native_ordinals_dont_break_sql (self , extra_params ):
558
+ def test_native_ordinals_dont_break_sql (self ):
640
559
"""This test accompanies test_inline_ordinals_can_break_sql to prove that ordinal
641
560
parameters work in native mode for the exact same query, if we use the right marker `?`
642
561
"""
643
562
query = "SELECT 'samsonite', ? WHERE 'samsonite' LIKE '%sonite'"
644
563
params = ["luggage" ]
645
- combined_params = {"use_inline_params" : False , ** extra_params }
646
- with self .cursor (extra_params = combined_params ) as cursor :
564
+ with self .cursor (extra_params = {"use_inline_params" : False }) as cursor :
647
565
result = cursor .execute (query , parameters = params ).fetchone ()
648
566
649
567
assert result .samsonite == "samsonite"
@@ -659,25 +577,13 @@ def test_inline_like_wildcard_breaks(self):
659
577
with pytest .raises (ValueError , match = "unsupported format character" ):
660
578
result = cursor .execute (query , parameters = params ).fetchone ()
661
579
662
- @pytest .mark .parametrize (
663
- "extra_params" ,
664
- [
665
- {},
666
- {
667
- "use_sea" : True ,
668
- "use_cloud_fetch" : False ,
669
- "enable_query_result_lz4_compression" : False ,
670
- },
671
- ],
672
- )
673
- def test_native_like_wildcard_works (self , extra_params ):
580
+ def test_native_like_wildcard_works (self ):
674
581
"""This is a mirror of test_inline_like_wildcard_breaks that proves that LIKE
675
582
wildcards work under the native approach.
676
583
"""
677
584
query = "SELECT 1 `col` WHERE 'foo' LIKE '%'"
678
585
params = {"param" : "bar" }
679
- combined_params = {"use_inline_params" : False , ** extra_params }
680
- with self .cursor (extra_params = combined_params ) as cursor :
586
+ with self .cursor (extra_params = {"use_inline_params" : False }) as cursor :
681
587
result = cursor .execute (query , parameters = params ).fetchone ()
682
588
683
589
assert result .col == 1
0 commit comments