@@ -204,6 +204,37 @@ def test_platform_detection_timeout(conn_cnx):
204204 assert cnx .platform_detection_timeout_seconds == 2.5
205205
206206
207+ @pytest .mark .skipolddriver
208+ def test_platform_detection_zero_timeout (conn_cnx ):
209+ """Tests platform detection with timeout set to zero.
210+
211+ The expectation is that it mustn't do diagnostic requests at all.
212+ """
213+ with (
214+ mock .patch (
215+ "snowflake.connector.platform_detection.is_ec2_instance"
216+ ) as is_ec2_instance ,
217+ mock .patch (
218+ "snowflake.connector.platform_detection.has_aws_identity"
219+ ) as has_aws_identity ,
220+ mock .patch ("snowflake.connector.platform_detection.is_azure_vm" ) as is_azure_vm ,
221+ mock .patch (
222+ "snowflake.connector.platform_detection.has_azure_managed_identity"
223+ ) as has_azure_managed_identity ,
224+ mock .patch ("snowflake.connector.platform_detection.is_gce_vm" ) as is_gce_vm ,
225+ mock .patch (
226+ "snowflake.connector.platform_detection.has_gcp_identity"
227+ ) as has_gcp_identity ,
228+ ):
229+ with conn_cnx (platform_detection_timeout_seconds = 0 ):
230+ assert not is_ec2_instance .called
231+ assert not has_aws_identity .called
232+ assert not is_azure_vm .called
233+ assert not has_azure_managed_identity .called
234+ assert not is_gce_vm .called
235+ assert not has_gcp_identity .called
236+
237+
207238def test_bad_db (conn_cnx ):
208239 """Attempts to use a bad DB."""
209240 with conn_cnx (database = "baddb" ) as cnx :
@@ -1119,9 +1150,10 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
11191150 "math" ,
11201151 ]
11211152
1122- with conn_cnx () as conn , capture_sf_telemetry .patch_connection (
1123- conn , False
1124- ) as telemetry_test :
1153+ with (
1154+ conn_cnx () as conn ,
1155+ capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test ,
1156+ ):
11251157 conn ._log_telemetry_imported_packages ()
11261158 assert len (telemetry_test .records ) > 0
11271159 assert any (
@@ -1136,10 +1168,13 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
11361168
11371169 # test different application
11381170 new_application_name = "PythonSnowpark"
1139- with conn_cnx (
1140- timezone = "UTC" ,
1141- application = new_application_name ,
1142- ) as conn , capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test :
1171+ with (
1172+ conn_cnx (
1173+ timezone = "UTC" ,
1174+ application = new_application_name ,
1175+ ) as conn ,
1176+ capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test ,
1177+ ):
11431178 conn ._log_telemetry_imported_packages ()
11441179 assert len (telemetry_test .records ) > 0
11451180 assert any (
@@ -1152,11 +1187,14 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
11521187 )
11531188
11541189 # test opt out
1155- with conn_cnx (
1156- timezone = "UTC" ,
1157- application = new_application_name ,
1158- log_imported_packages_in_telemetry = False ,
1159- ) as conn , capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test :
1190+ with (
1191+ conn_cnx (
1192+ timezone = "UTC" ,
1193+ application = new_application_name ,
1194+ log_imported_packages_in_telemetry = False ,
1195+ ) as conn ,
1196+ capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test ,
1197+ ):
11601198 conn ._log_telemetry_imported_packages ()
11611199 assert len (telemetry_test .records ) == 0
11621200
@@ -1293,9 +1331,10 @@ def test_ocsp_mode_insecure_mode_and_disable_ocsp_checks_match(
12931331 conn_cnx , is_public_test , is_local_dev_setup , caplog
12941332):
12951333 caplog .set_level (logging .DEBUG , "snowflake.connector.ocsp_snowflake" )
1296- with conn_cnx (
1297- insecure_mode = True , disable_ocsp_checks = True
1298- ) as conn , conn .cursor () as cur :
1334+ with (
1335+ conn_cnx (insecure_mode = True , disable_ocsp_checks = True ) as conn ,
1336+ conn .cursor () as cur ,
1337+ ):
12991338 assert cur .execute ("select 1" ).fetchall () == [(1 ,)]
13001339 assert "snowflake.connector.ocsp_snowflake" not in caplog .text
13011340 if is_public_test or is_local_dev_setup :
@@ -1311,9 +1350,10 @@ def test_ocsp_mode_insecure_mode_and_disable_ocsp_checks_mismatch_ocsp_disabled(
13111350 conn_cnx , is_public_test , is_local_dev_setup , caplog
13121351):
13131352 caplog .set_level (logging .DEBUG , "snowflake.connector.ocsp_snowflake" )
1314- with conn_cnx (
1315- insecure_mode = False , disable_ocsp_checks = True
1316- ) as conn , conn .cursor () as cur :
1353+ with (
1354+ conn_cnx (insecure_mode = False , disable_ocsp_checks = True ) as conn ,
1355+ conn .cursor () as cur ,
1356+ ):
13171357 assert cur .execute ("select 1" ).fetchall () == [(1 ,)]
13181358 assert "snowflake.connector.ocsp_snowflake" not in caplog .text
13191359 if is_public_test or is_local_dev_setup :
@@ -1329,9 +1369,10 @@ def test_ocsp_mode_insecure_mode_and_disable_ocsp_checks_mismatch_ocsp_enabled(
13291369 conn_cnx , is_public_test , is_local_dev_setup , caplog
13301370):
13311371 caplog .set_level (logging .DEBUG , "snowflake.connector.ocsp_snowflake" )
1332- with conn_cnx (
1333- insecure_mode = True , disable_ocsp_checks = False
1334- ) as conn , conn .cursor () as cur :
1372+ with (
1373+ conn_cnx (insecure_mode = True , disable_ocsp_checks = False ) as conn ,
1374+ conn .cursor () as cur ,
1375+ ):
13351376 assert cur .execute ("select 1" ).fetchall () == [(1 ,)]
13361377 if is_public_test or is_local_dev_setup :
13371378 assert "snowflake.connector.ocsp_snowflake" in caplog .text
@@ -1430,9 +1471,10 @@ def test_disable_telemetry(conn_cnx, caplog):
14301471
14311472 # set session parameters to false
14321473 with caplog .at_level (logging .DEBUG ):
1433- with conn_cnx (
1434- session_parameters = {"CLIENT_TELEMETRY_ENABLED" : False }
1435- ) as conn , conn .cursor () as cur :
1474+ with (
1475+ conn_cnx (session_parameters = {"CLIENT_TELEMETRY_ENABLED" : False }) as conn ,
1476+ conn .cursor () as cur ,
1477+ ):
14361478 cur .execute ("select 1" ).fetchall ()
14371479 assert not conn .telemetry_enabled and not conn ._telemetry ._log_batch
14381480 # this enable won't work as the session parameter is set to false
0 commit comments