@@ -83,7 +83,7 @@ async def test_with_config(conn_cnx):
83
83
async with conn_cnx (timezone = "UTC" ) as cnx :
84
84
assert cnx , "invalid cnx"
85
85
# Default depends on server; if unreachable, fall back to False
86
- from ..conftest import get_server_parameter_value
86
+ from ... conftest import get_server_parameter_value
87
87
88
88
server_default_str = get_server_parameter_value (
89
89
cnx , "CLIENT_SESSION_KEEP_ALIVE"
@@ -620,6 +620,7 @@ async def mock_auth(self, auth_instance):
620
620
async with conn_cnx (
621
621
timezone = "UTC" ,
622
622
authenticator = orig_authenticator ,
623
+ password = "test-password" ,
623
624
) as cnx :
624
625
assert cnx
625
626
@@ -713,82 +714,42 @@ async def test_dashed_url_account_name(db_parameters):
713
714
),
714
715
],
715
716
)
716
- async def test_invalid_connection_parameter (db_parameters , name , value , exc_warn ):
717
- with warnings .catch_warnings (record = True ) as w :
718
- conn_params = {
719
- "account" : db_parameters ["account" ],
720
- "user" : db_parameters ["user" ],
721
- "password" : db_parameters ["password" ],
722
- "schema" : db_parameters ["schema" ],
723
- "database" : db_parameters ["database" ],
724
- "protocol" : db_parameters ["protocol" ],
725
- "host" : db_parameters ["host" ],
726
- "port" : db_parameters ["port" ],
727
- "validate_default_parameters" : True ,
728
- name : value ,
729
- }
730
- try :
731
- conn = snowflake .connector .aio .SnowflakeConnection (** conn_params )
732
- await conn .connect ()
717
+ async def test_invalid_connection_parameter (conn_cnx , name , value , exc_warn ):
718
+ with warnings .catch_warnings (record = True ) as warns :
719
+ async with conn_cnx (validate_default_parameters = True , ** {name : value }) as conn :
733
720
assert getattr (conn , "_" + name ) == value
734
- assert len (w ) == 1
735
- assert str (w [0 ].message ) == str (exc_warn )
736
- finally :
737
- await conn .close ()
721
+ assert any (str (exc_warn ) == str (w .message ) for w in warns )
738
722
739
723
740
- async def test_invalid_connection_parameters_turned_off (db_parameters ):
724
+ async def test_invalid_connection_parameters_turned_off (conn_cnx ):
741
725
"""Makes sure parameter checking can be turned off."""
742
- with warnings .catch_warnings (record = True ) as w :
743
- conn_params = {
744
- "account" : db_parameters ["account" ],
745
- "user" : db_parameters ["user" ],
746
- "password" : db_parameters ["password" ],
747
- "schema" : db_parameters ["schema" ],
748
- "database" : db_parameters ["database" ],
749
- "protocol" : db_parameters ["protocol" ],
750
- "host" : db_parameters ["host" ],
751
- "port" : db_parameters ["port" ],
752
- "validate_default_parameters" : False ,
753
- "autocommit" : "True" , # Wrong type
754
- "applucation" : "this is a typo or my own variable" , # Wrong name
755
- }
756
- try :
757
- conn = snowflake .connector .aio .SnowflakeConnection (** conn_params )
758
- await conn .connect ()
759
- assert conn ._autocommit == conn_params ["autocommit" ]
760
- assert conn ._applucation == conn_params ["applucation" ]
761
- assert len (w ) == 0
762
- finally :
763
- await conn .close ()
726
+ with warnings .catch_warnings (record = True ) as warns :
727
+ async with conn_cnx (
728
+ validate_default_parameters = False ,
729
+ autocommit = "True" ,
730
+ applucation = "this is a typo or my own variable" ,
731
+ ) as conn :
732
+ assert conn ._autocommit == "True"
733
+ assert conn ._applucation == "this is a typo or my own variable"
734
+ assert not any (
735
+ "_autocommit" in w .message or "_applucation" in w .message for w in warns
736
+ )
764
737
765
738
766
- async def test_invalid_connection_parameters_only_warns (db_parameters ):
739
+ async def test_invalid_connection_parameters_only_warns (conn_cnx ):
767
740
"""This test supresses warnings to only have warehouse, database and schema checking."""
768
- with warnings .catch_warnings (record = True ) as w :
769
- conn_params = {
770
- "account" : db_parameters ["account" ],
771
- "user" : db_parameters ["user" ],
772
- "password" : db_parameters ["password" ],
773
- "schema" : db_parameters ["schema" ],
774
- "database" : db_parameters ["database" ],
775
- "protocol" : db_parameters ["protocol" ],
776
- "host" : db_parameters ["host" ],
777
- "port" : db_parameters ["port" ],
778
- "validate_default_parameters" : True ,
779
- "autocommit" : "True" , # Wrong type
780
- "applucation" : "this is a typo or my own variable" , # Wrong name
781
- }
782
- try :
783
- with warnings .catch_warnings ():
784
- warnings .simplefilter ("ignore" )
785
- conn = snowflake .connector .aio .SnowflakeConnection (** conn_params )
786
- await conn .connect ()
787
- assert conn ._autocommit == conn_params ["autocommit" ]
788
- assert conn ._applucation == conn_params ["applucation" ]
789
- assert len (w ) == 0
790
- finally :
791
- await conn .close ()
741
+ with warnings .catch_warnings (record = True ) as warns :
742
+ async with conn_cnx (
743
+ validate_default_parameters = True ,
744
+ autocommit = "True" ,
745
+ applucation = "this is a typo or my own variable" ,
746
+ ) as conn :
747
+ assert conn ._autocommit == "True"
748
+ assert conn ._applucation == "this is a typo or my own variable"
749
+ assert not any (
750
+ "_autocommit" in str (w .message ) or "_applucation" in str (w .message )
751
+ for w in warns
752
+ )
792
753
793
754
794
755
@pytest .mark .skipolddriver
@@ -1059,9 +1020,7 @@ async def test_ocsp_cache_working(conn_cnx):
1059
1020
1060
1021
1061
1022
@pytest .mark .skipolddriver
1062
- async def test_imported_packages_telemetry (
1063
- conn_cnx , capture_sf_telemetry_async , db_parameters
1064
- ):
1023
+ async def test_imported_packages_telemetry (conn_cnx , capture_sf_telemetry_async ):
1065
1024
# these imports are not used but for testing
1066
1025
import html .parser # noqa: F401
1067
1026
import json # noqa: F401
@@ -1102,20 +1061,8 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
1102
1061
1103
1062
# test different application
1104
1063
new_application_name = "PythonSnowpark"
1105
- config = {
1106
- "user" : db_parameters ["user" ],
1107
- "password" : db_parameters ["password" ],
1108
- "host" : db_parameters ["host" ],
1109
- "port" : db_parameters ["port" ],
1110
- "account" : db_parameters ["account" ],
1111
- "schema" : db_parameters ["schema" ],
1112
- "database" : db_parameters ["database" ],
1113
- "protocol" : db_parameters ["protocol" ],
1114
- "timezone" : "UTC" ,
1115
- "application" : new_application_name ,
1116
- }
1117
- async with snowflake .connector .aio .SnowflakeConnection (
1118
- ** config
1064
+ async with conn_cnx (
1065
+ timezone = "UTC" , application = new_application_name
1119
1066
) as conn , capture_sf_telemetry_async .patch_connection (
1120
1067
conn , False
1121
1068
) as telemetry_test :
@@ -1131,9 +1078,10 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
1131
1078
)
1132
1079
1133
1080
# test opt out
1134
- config ["log_imported_packages_in_telemetry" ] = False
1135
- async with snowflake .connector .aio .SnowflakeConnection (
1136
- ** config
1081
+ async with conn_cnx (
1082
+ timezone = "UTC" ,
1083
+ application = new_application_name ,
1084
+ log_imported_packages_in_telemetry = False ,
1137
1085
) as conn , capture_sf_telemetry_async .patch_connection (
1138
1086
conn , False
1139
1087
) as telemetry_test :
0 commit comments