From 2bc55e386d49368a11673fa7a2fc6ab99310d3ba Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 3 Feb 2022 15:58:59 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.62.1 (#260) - [ ] Regenerate this pull request now. fix: resolve DuplicateCredentialArgs error when using credentials_file committer: parthea PiperOrigin-RevId: 425964861 Source-Link: https://github.com/googleapis/googleapis/commit/84b1a5a4f6fb2d04905be58e586b8a7a4310a8cf Source-Link: https://github.com/googleapis/googleapis-gen/commit/4fb761bbd8506ac156f49bac5f18306aa8eb3aa8 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGZiNzYxYmJkODUwNmFjMTU2ZjQ5YmFjNWYxODMwNmFhOGViM2FhOCJ9 Closes #259 --- .../services/language_service/async_client.py | 12 +-- .../services/language_service/client.py | 12 +-- .../language_service/transports/grpc.py | 5 +- .../transports/grpc_asyncio.py | 5 +- .../services/language_service/async_client.py | 12 +-- .../services/language_service/client.py | 12 +-- .../language_service/transports/grpc.py | 5 +- .../transports/grpc_asyncio.py | 5 +- .../snippets/classify_text/requirements.txt | 1 - .../language_v1/test_language_service.py | 82 ++++++++++++++++++- .../language_v1beta2/test_language_service.py | 82 ++++++++++++++++++- 11 files changed, 198 insertions(+), 35 deletions(-) diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py index e5cf9d94027a..e830dad366f9 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py @@ -242,7 +242,7 @@ async def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -325,7 +325,7 @@ async def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -411,7 +411,7 @@ async def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -493,7 +493,7 @@ async def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -568,7 +568,7 @@ async def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -658,7 +658,7 @@ async def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py index 15f0865176bb..c3bc0fbc6446 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py @@ -425,7 +425,7 @@ def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -498,7 +498,7 @@ def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -574,7 +574,7 @@ def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -646,7 +646,7 @@ def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -711,7 +711,7 @@ def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -791,7 +791,7 @@ def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py index 94941e4e8e88..5657b6a1f6fe 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py @@ -159,8 +159,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py index 681336e2d3da..4490dab821b4 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py @@ -204,8 +204,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py index 28a5b0feada5..a74c38d4b5d4 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py @@ -243,7 +243,7 @@ async def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -326,7 +326,7 @@ async def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -412,7 +412,7 @@ async def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -494,7 +494,7 @@ async def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -569,7 +569,7 @@ async def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -659,7 +659,7 @@ async def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py index b0c932822e06..8b29f11bcbfe 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py @@ -426,7 +426,7 @@ def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -499,7 +499,7 @@ def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -575,7 +575,7 @@ def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -647,7 +647,7 @@ def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -712,7 +712,7 @@ def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -792,7 +792,7 @@ def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py index 2936db357eaa..f962d7dcb95f 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py @@ -159,8 +159,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py index 5e7e6213cc07..ca6b00b3a4df 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py @@ -204,8 +204,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/packages/google-cloud-language/samples/snippets/classify_text/requirements.txt b/packages/google-cloud-language/samples/snippets/classify_text/requirements.txt index 8ebc429c078f..b562bb8631f2 100644 --- a/packages/google-cloud-language/samples/snippets/classify_text/requirements.txt +++ b/packages/google-cloud-language/samples/snippets/classify_text/requirements.txt @@ -1,4 +1,3 @@ google-cloud-language==2.3.1 numpy==1.22.1; python_version > '3.7' numpy==1.21.4; python_version == '3.7' -numpy==1.19.5; python_version <= '3.6' diff --git a/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py b/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py index 996eea97c4b1..e322b5dbe035 100644 --- a/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py +++ b/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py @@ -519,21 +519,28 @@ def test_language_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (LanguageServiceClient, transports.LanguageServiceGrpcTransport, "grpc"), + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( LanguageServiceAsyncClient, transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_language_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. 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) @@ -569,6 +576,75 @@ def test_language_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + LanguageServiceAsyncClient, + transports.LanguageServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_language_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + 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) + 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, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "language.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-language", + "https://www.googleapis.com/auth/cloud-platform", + ), + scopes=None, + default_host="language.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [language_service.AnalyzeSentimentRequest, dict,] ) diff --git a/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py b/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py index 17ed8c277f3f..d3462f233a0b 100644 --- a/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py +++ b/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py @@ -521,21 +521,28 @@ def test_language_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (LanguageServiceClient, transports.LanguageServiceGrpcTransport, "grpc"), + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( LanguageServiceAsyncClient, transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_language_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. 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) @@ -571,6 +578,75 @@ def test_language_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + LanguageServiceAsyncClient, + transports.LanguageServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_language_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + 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) + 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, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "language.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-language", + "https://www.googleapis.com/auth/cloud-platform", + ), + scopes=None, + default_host="language.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [language_service.AnalyzeSentimentRequest, dict,] )