@@ -207,6 +207,37 @@ def test_platform_detection_timeout(conn_cnx):
207207 assert cnx .platform_detection_timeout_seconds == 2.5
208208
209209
210+ @pytest .mark .skipolddriver
211+ def test_platform_detection_zero_timeout (conn_cnx ):
212+ """Tests platform detection with timeout set to zero.
213+
214+ The expectation is that it mustn't do diagnostic requests at all.
215+ """
216+ with (
217+ mock .patch (
218+ "snowflake.connector.platform_detection.is_ec2_instance"
219+ ) as is_ec2_instance ,
220+ mock .patch (
221+ "snowflake.connector.platform_detection.has_aws_identity"
222+ ) as has_aws_identity ,
223+ mock .patch ("snowflake.connector.platform_detection.is_azure_vm" ) as is_azure_vm ,
224+ mock .patch (
225+ "snowflake.connector.platform_detection.has_azure_managed_identity"
226+ ) as has_azure_managed_identity ,
227+ mock .patch ("snowflake.connector.platform_detection.is_gce_vm" ) as is_gce_vm ,
228+ mock .patch (
229+ "snowflake.connector.platform_detection.has_gcp_identity"
230+ ) as has_gcp_identity ,
231+ ):
232+ with conn_cnx (platform_detection_timeout_seconds = 0 ):
233+ assert not is_ec2_instance .called
234+ assert not has_aws_identity .called
235+ assert not is_azure_vm .called
236+ assert not has_azure_managed_identity .called
237+ assert not is_gce_vm .called
238+ assert not has_gcp_identity .called
239+
240+
210241def test_bad_db (conn_cnx ):
211242 """Attempts to use a bad DB."""
212243 with conn_cnx (database = "baddb" ) as cnx :
@@ -1145,9 +1176,10 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
11451176 "math" ,
11461177 ]
11471178
1148- with conn_cnx () as conn , capture_sf_telemetry .patch_connection (
1149- conn , False
1150- ) as telemetry_test :
1179+ with (
1180+ conn_cnx () as conn ,
1181+ capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test ,
1182+ ):
11511183 conn ._log_telemetry_imported_packages ()
11521184 assert len (telemetry_test .records ) > 0
11531185 assert any (
@@ -1162,10 +1194,13 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
11621194
11631195 # test different application
11641196 new_application_name = "PythonSnowpark"
1165- with conn_cnx (
1166- timezone = "UTC" ,
1167- application = new_application_name ,
1168- ) as conn , capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test :
1197+ with (
1198+ conn_cnx (
1199+ timezone = "UTC" ,
1200+ application = new_application_name ,
1201+ ) as conn ,
1202+ capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test ,
1203+ ):
11691204 conn ._log_telemetry_imported_packages ()
11701205 assert len (telemetry_test .records ) > 0
11711206 assert any (
@@ -1178,11 +1213,14 @@ def check_packages(message: str, expected_packages: list[str]) -> bool:
11781213 )
11791214
11801215 # test opt out
1181- with conn_cnx (
1182- timezone = "UTC" ,
1183- application = new_application_name ,
1184- log_imported_packages_in_telemetry = False ,
1185- ) as conn , capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test :
1216+ with (
1217+ conn_cnx (
1218+ timezone = "UTC" ,
1219+ application = new_application_name ,
1220+ log_imported_packages_in_telemetry = False ,
1221+ ) as conn ,
1222+ capture_sf_telemetry .patch_connection (conn , False ) as telemetry_test ,
1223+ ):
11861224 conn ._log_telemetry_imported_packages ()
11871225 assert len (telemetry_test .records ) == 0
11881226
@@ -1318,9 +1356,10 @@ def test_ocsp_mode_insecure_mode_and_disable_ocsp_checks_match(
13181356 conn_cnx , is_public_test , is_local_dev_setup , caplog
13191357):
13201358 caplog .set_level (logging .DEBUG , "snowflake.connector.ocsp_snowflake" )
1321- with conn_cnx (
1322- insecure_mode = True , disable_ocsp_checks = True
1323- ) as conn , conn .cursor () as cur :
1359+ with (
1360+ conn_cnx (insecure_mode = True , disable_ocsp_checks = True ) as conn ,
1361+ conn .cursor () as cur ,
1362+ ):
13241363 assert cur .execute ("select 1" ).fetchall () == [(1 ,)]
13251364 assert "snowflake.connector.ocsp_snowflake" not in caplog .text
13261365 if is_public_test or is_local_dev_setup :
@@ -1336,9 +1375,10 @@ def test_ocsp_mode_insecure_mode_and_disable_ocsp_checks_mismatch_ocsp_disabled(
13361375 conn_cnx , is_public_test , is_local_dev_setup , caplog
13371376):
13381377 caplog .set_level (logging .DEBUG , "snowflake.connector.ocsp_snowflake" )
1339- with conn_cnx (
1340- insecure_mode = False , disable_ocsp_checks = True
1341- ) as conn , conn .cursor () as cur :
1378+ with (
1379+ conn_cnx (insecure_mode = False , disable_ocsp_checks = True ) as conn ,
1380+ conn .cursor () as cur ,
1381+ ):
13421382 assert cur .execute ("select 1" ).fetchall () == [(1 ,)]
13431383 assert "snowflake.connector.ocsp_snowflake" not in caplog .text
13441384 if is_public_test or is_local_dev_setup :
@@ -1524,9 +1564,10 @@ def test_ocsp_mode_insecure_mode_and_disable_ocsp_checks_mismatch_ocsp_enabled(
15241564 conn_cnx , is_public_test , is_local_dev_setup , caplog
15251565):
15261566 caplog .set_level (logging .DEBUG , "snowflake.connector.ocsp_snowflake" )
1527- with conn_cnx (
1528- insecure_mode = True , disable_ocsp_checks = False
1529- ) as conn , conn .cursor () as cur :
1567+ with (
1568+ conn_cnx (insecure_mode = True , disable_ocsp_checks = False ) as conn ,
1569+ conn .cursor () as cur ,
1570+ ):
15301571 assert cur .execute ("select 1" ).fetchall () == [(1 ,)]
15311572 if is_public_test or is_local_dev_setup :
15321573 assert "snowflake.connector.ocsp_snowflake" in caplog .text
@@ -1625,9 +1666,10 @@ def test_disable_telemetry(conn_cnx, caplog):
16251666
16261667 # set session parameters to false
16271668 with caplog .at_level (logging .DEBUG ):
1628- with conn_cnx (
1629- session_parameters = {"CLIENT_TELEMETRY_ENABLED" : False }
1630- ) as conn , conn .cursor () as cur :
1669+ with (
1670+ conn_cnx (session_parameters = {"CLIENT_TELEMETRY_ENABLED" : False }) as conn ,
1671+ conn .cursor () as cur ,
1672+ ):
16311673 cur .execute ("select 1" ).fetchall ()
16321674 assert not conn .telemetry_enabled and not conn ._telemetry ._log_batch
16331675 # this enable won't work as the session parameter is set to false
0 commit comments