diff --git a/pyproject.toml b/pyproject.toml index 0132afe05..037e20b2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,4 +110,10 @@ filterwarnings = [ "ignore:There is no current event loop:DeprecationWarning", # Remove after support for Python 3.7 is dropped "ignore:After January 1, 2024, new releases of this library will drop support for Python 3.7:DeprecationWarning", + # Remove after support for Python 3.10 is dropped + "ignore:.*You are using a.* Python version \\(3\\.10:FutureWarning", + # Remove after support for Python 3.11 is dropped + "ignore:.*You are using a.* Python version \\(3\\.11:FutureWarning", + # Remove after support for Python 3.12 is dropped + "ignore:.*You are using a.* Python version \\(3\\.12:FutureWarning", ] diff --git a/tests/asyncio/gapic/test_method_async.py b/tests/asyncio/gapic/test_method_async.py index 3edf8b6d4..40dd168a0 100644 --- a/tests/asyncio/gapic/test_method_async.py +++ b/tests/asyncio/gapic/test_method_async.py @@ -260,7 +260,7 @@ async def test_wrap_method_with_overriding_timeout_as_a_number(): actual_timeout = method.call_args[1]["timeout"] metadata = method.call_args[1]["metadata"] assert metadata == mock.ANY - assert actual_timeout == pytest.approx(22, abs=0.01) + assert actual_timeout == pytest.approx(22, abs=0.05) @pytest.mark.asyncio diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index aa8d5d10b..3fffd070b 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -522,11 +522,15 @@ def test_create_channel_explicit_with_duplicate_credentials(): target = "example:443" with pytest.raises(exceptions.DuplicateCredentialArgs) as excinfo: - grpc_helpers_async.create_channel( - target, - credentials_file="credentials.json", - credentials=mock.sentinel.credentials, - ) + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + with pytest.warns(DeprecationWarning): + grpc_helpers_async.create_channel( + target, + credentials_file="credentials.json", + credentials=mock.sentinel.credentials, + ) assert "mutually exclusive" in str(excinfo.value) @@ -641,9 +645,13 @@ def test_create_channel_with_credentials_file( credentials_file = "/path/to/credentials/file.json" composite_creds = composite_creds_call.return_value - channel = grpc_helpers_async.create_channel( - target, credentials_file=credentials_file - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + channel = grpc_helpers_async.create_channel( + target, credentials_file=credentials_file + ) google.auth.load_credentials_from_file.assert_called_once_with( credentials_file, scopes=None, default_scopes=None @@ -670,9 +678,13 @@ def test_create_channel_with_credentials_file_and_scopes( credentials_file = "/path/to/credentials/file.json" composite_creds = composite_creds_call.return_value - channel = grpc_helpers_async.create_channel( - target, credentials_file=credentials_file, scopes=scopes - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + channel = grpc_helpers_async.create_channel( + target, credentials_file=credentials_file, scopes=scopes + ) google.auth.load_credentials_from_file.assert_called_once_with( credentials_file, scopes=scopes, default_scopes=None @@ -699,9 +711,13 @@ def test_create_channel_with_credentials_file_and_default_scopes( credentials_file = "/path/to/credentials/file.json" composite_creds = composite_creds_call.return_value - channel = grpc_helpers_async.create_channel( - target, credentials_file=credentials_file, default_scopes=default_scopes - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + channel = grpc_helpers_async.create_channel( + target, credentials_file=credentials_file, default_scopes=default_scopes + ) google.auth.load_credentials_from_file.assert_called_once_with( credentials_file, scopes=None, default_scopes=default_scopes diff --git a/tests/unit/operations_v1/test_operations_rest_client.py b/tests/unit/operations_v1/test_operations_rest_client.py index 4e8ef4073..7fb26e18f 100644 --- a/tests/unit/operations_v1/test_operations_rest_client.py +++ b/tests/unit/operations_v1/test_operations_rest_client.py @@ -369,7 +369,11 @@ def test_operations_client_client_options( ) # Check the case credentials_file is provided - options = client_options.ClientOptions(credentials_file="credentials.json") + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -539,11 +543,25 @@ def test_operations_client_client_options_credentials_file( client_class, transport_class, transport_name ): # Check the case credentials file is provided. - options = client_options.ClientOptions(credentials_file="credentials.json") + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + options = client_options.ClientOptions(credentials_file="credentials.json") if "async" in str(client_class): - # TODO(): Add support for credentials file to async REST transport. - with pytest.raises(core_exceptions.AsyncRestUnsupportedParameterError): - client_class(client_options=options, transport=transport_name) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) else: with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None @@ -570,10 +588,20 @@ def test_operations_client_client_options_credentials_file( return_value=(mock.sentinel.credentials, mock.sentinel.project), ) def test_list_operations_rest(google_auth_default, credentials_file): - sync_transport = transports.rest.OperationsRestTransport( - credentials_file=credentials_file, - http_options=HTTP_OPTIONS, - ) + if credentials_file is not None: + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + sync_transport = transports.rest.OperationsRestTransport( + credentials_file=credentials_file, + http_options=HTTP_OPTIONS, + ) + else: + sync_transport = transports.rest.OperationsRestTransport( + credentials_file=credentials_file, + http_options=HTTP_OPTIONS, + ) client = AbstractOperationsClient(transport=sync_transport) @@ -1130,10 +1158,14 @@ def test_transport_adc(client_class, transport_class, credentials): def test_operations_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transports.OperationsTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + transports.OperationsTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) def test_operations_base_transport(): @@ -1171,10 +1203,14 @@ def test_operations_base_transport_with_credentials_file(): ) as Transport: Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transports.OperationsTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + transports.OperationsTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) load_creds.assert_called_once_with( "credentials.json", scopes=None, diff --git a/tests/unit/test_client_options.py b/tests/unit/test_client_options.py index 396d66271..0dccd9d99 100644 --- a/tests/unit/test_client_options.py +++ b/tests/unit/test_client_options.py @@ -27,19 +27,22 @@ def get_client_encrypted_cert(): def test_constructor(): - - options = client_options.ClientOptions( - api_endpoint="foo.googleapis.com", - client_cert_source=get_client_cert, - quota_project_id="quote-proj", - credentials_file="path/to/credentials.json", - scopes=[ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-platform.read-only", - ], - api_audience="foo2.googleapis.com", - universe_domain="googleapis.com", - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + options = client_options.ClientOptions( + api_endpoint="foo.googleapis.com", + client_cert_source=get_client_cert, + quota_project_id="quote-proj", + credentials_file="path/to/credentials.json", + scopes=[ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ], + api_audience="foo2.googleapis.com", + universe_domain="googleapis.com", + ) assert options.api_endpoint == "foo.googleapis.com" assert options.client_cert_source() == (b"cert", b"key") @@ -102,10 +105,14 @@ def test_constructor_with_api_key(): def test_constructor_with_both_api_key_and_credentials_file(): with pytest.raises(ValueError): - client_options.ClientOptions( - api_key="api-key", - credentials_file="path/to/credentials.json", - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + client_options.ClientOptions( + api_key="api-key", + credentials_file="path/to/credentials.json", + ) def test_from_dict(): diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index 8de9d8c0b..9d7bb9c04 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -581,11 +581,15 @@ def test_create_channel_explicit_with_duplicate_credentials(): target = "example.com:443" with pytest.raises(exceptions.DuplicateCredentialArgs): - grpc_helpers.create_channel( - target, - credentials_file="credentials.json", - credentials=mock.sentinel.credentials, - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + grpc_helpers.create_channel( + target, + credentials_file="credentials.json", + credentials=mock.sentinel.credentials, + ) @mock.patch("grpc.compute_engine_channel_credentials") @@ -710,7 +714,11 @@ def test_create_channel_with_credentials_file( credentials_file = "/path/to/credentials/file.json" composite_creds = composite_creds_call.return_value - channel = grpc_helpers.create_channel(target, credentials_file=credentials_file) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + channel = grpc_helpers.create_channel(target, credentials_file=credentials_file) google.auth.load_credentials_from_file.assert_called_once_with( credentials_file, scopes=None, default_scopes=None @@ -742,9 +750,13 @@ def test_create_channel_with_credentials_file_and_scopes( credentials_file = "/path/to/credentials/file.json" composite_creds = composite_creds_call.return_value - channel = grpc_helpers.create_channel( - target, credentials_file=credentials_file, scopes=scopes - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + channel = grpc_helpers.create_channel( + target, credentials_file=credentials_file, scopes=scopes + ) google.auth.load_credentials_from_file.assert_called_once_with( credentials_file, scopes=scopes, default_scopes=None @@ -776,9 +788,13 @@ def test_create_channel_with_credentials_file_and_default_scopes( credentials_file = "/path/to/credentials/file.json" composite_creds = composite_creds_call.return_value - channel = grpc_helpers.create_channel( - target, credentials_file=credentials_file, default_scopes=default_scopes - ) + with pytest.warns(DeprecationWarning): + # The `credentials_file` argument is deprecated by + # the Google Cloud Auth library (`google-auth`), which is the + # upstream dependency responsible for handling authentication. + channel = grpc_helpers.create_channel( + target, credentials_file=credentials_file, default_scopes=default_scopes + ) load_credentials_from_file.assert_called_once_with( credentials_file, scopes=None, default_scopes=default_scopes