6262from google.auth import credentials as ga_credentials
6363from google.auth.exceptions import MutualTLSChannelError
6464from google.cloud.location import locations_pb2
65+
66+ # NOTE: Isolated import block preserves import shielding for service_account
67+ # to prevent ruff/flake8 sorting conflicts between local hooks and CI environments.
6568from google.oauth2 import service_account
6669
6770from google.cloud.secretmanager_v1.services.secret_manager_service import (
@@ -478,13 +481,6 @@ def test_secret_manager_service_client_client_options(
478481
479482
480483def test_secret_manager_service_client_otel_channel_injection_enabled():
481- """Proves that when OpenTelemetry tracing is enabled:
482-
483- 1. SecretManagerServiceClient obtains the channel interceptor via
484- _observability.get_otel_interceptor passing client_options.
485- 2. The interceptor is passed into transport kwargs under 'interceptors',
486- allowing the Transport to apply it via apply_channel_interceptors.
487- """
488484 mock_interceptor = mock.Mock()
489485 mock_obs = mock.Mock()
490486 mock_obs.get_otel_interceptor.return_value = mock_interceptor
@@ -506,11 +502,6 @@ def test_secret_manager_service_client_otel_channel_injection_enabled():
506502
507503
508504def test_secret_manager_service_client_otel_channel_injection_disabled():
509- """Proves that when OpenTelemetry tracing is disabled:
510-
511- 1. SecretManagerServiceClient checks for an OTel interceptor and receives None.
512- 2. No OTel interceptor is added to the transport constructor kwargs.
513- """
514505 mock_obs = mock.Mock()
515506 mock_obs.get_otel_interceptor.return_value = None
516507 with (
@@ -526,33 +517,10 @@ def test_secret_manager_service_client_otel_channel_injection_disabled():
526517
527518 mock_obs.get_otel_interceptor.assert_called_once_with(client._client_options)
528519 called_kwargs = patched_transport_init.call_args.kwargs
529- interceptors = called_kwargs.get("interceptors", [])
530- assert not interceptors
531-
532-
533- def test_secret_manager_service_client_observability_import_error():
534- """Proves that when _observability cannot be imported (older google-api-core),
535- SecretManagerServiceClient instantiates gracefully without error.
536- """
537- with (
538- mock.patch(
539- "google.cloud.secretmanager_v1.services.secret_manager_service.client._observability",
540- None,
541- ),
542- mock.patch.object(
543- transports.SecretManagerServiceGrpcTransport, "__init__", return_value=None
544- ) as patched_transport_init,
545- ):
546- SecretManagerServiceClient(transport="grpc")
547- called_kwargs = patched_transport_init.call_args.kwargs
548520 assert not called_kwargs.get("interceptors", [])
549521
550522
551- def test_secret_manager_service_grpc_transport_interceptors():
552- """Proves that SecretManagerServiceGrpcTransport accepts channel interceptors
553- and invokes grpc_helpers.apply_channel_interceptors to apply them to the underlying
554- gRPC channel.
555- """
523+ def test_secret_manager_service_grpc_transport_channel_interceptors():
556524 mock_interceptor = mock.Mock()
557525 mock_channel = mock.Mock()
558526
@@ -562,8 +530,9 @@ def test_secret_manager_service_grpc_transport_interceptors():
562530 "create_channel",
563531 return_value=mock_channel,
564532 ),
565- mock.patch(
566- "google.api_core.grpc_helpers.apply_channel_interceptors",
533+ mock.patch.object(
534+ grpc_helpers,
535+ "apply_channel_interceptors",
567536 return_value=mock_channel,
568537 create=True,
569538 ) as mock_apply_interceptors,
@@ -579,14 +548,12 @@ def test_secret_manager_service_grpc_transport_interceptors():
579548
580549
581550def test_secret_manager_service_grpc_transport_custom_channel_interceptors():
582- """Proves that SecretManagerServiceGrpcTransport wraps explicitly passed custom channels
583- using grpc_helpers.apply_channel_interceptors.
584- """
585551 mock_interceptor = mock.Mock()
586552 mock_custom_channel = mock.Mock(spec=grpc.Channel)
587553
588- with mock.patch(
589- "google.api_core.grpc_helpers.apply_channel_interceptors",
554+ with mock.patch.object(
555+ grpc_helpers,
556+ "apply_channel_interceptors",
590557 return_value=mock_custom_channel,
591558 create=True,
592559 ) as mock_apply_interceptors:
0 commit comments