Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions google/cloud/language_v1/services/language_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion samples/snippets/classify_text/requirements.txt
Original file line number Diff line number Diff line change
@@ -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'
82 changes: 79 additions & 3 deletions tests/unit/gapic/language_v1/test_language_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,]
)
Expand Down
Loading