Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing(translate): parameterize the timeout #4247

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions translate/cloud-client/translate_v3_batch_translate_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@


def batch_translate_text(
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
project_id="YOUR_PROJECT_ID"
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
project_id="YOUR_PROJECT_ID",
timeout=180,
):
"""Translates a batch of texts on GCS and stores the result in a GCS location."""

Expand All @@ -46,7 +47,7 @@ def batch_translate_text(
output_config=output_config)

print(u"Waiting for operation to complete...")
response = operation.result(180)
response = operation.result(timeout)
tmatsuo marked this conversation as resolved.
Show resolved Hide resolved

print(u"Total Characters: {}".format(response.total_characters))
print(u"Translated Characters: {}".format(response.translated_characters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@


def batch_translate_text_with_glossary(
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
project_id="YOUR_PROJECT_ID",
glossary_id="YOUR_GLOSSARY_ID",
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
project_id="YOUR_PROJECT_ID",
glossary_id="YOUR_GLOSSARY_ID",
timeout=180,
):
"""Translates a batch of texts on GCS and stores the result in a GCS location.
Glossary is applied for translation."""
Expand Down Expand Up @@ -65,7 +66,7 @@ def batch_translate_text_with_glossary(
)

print(u"Waiting for operation to complete...")
response = operation.result(180)
response = operation.result(timeout)
tmatsuo marked this conversation as resolved.
Show resolved Hide resolved

print(u"Total Characters: {}".format(response.total_characters))
print(u"Translated Characters: {}".format(response.translated_characters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_batch_translate_text_with_glossary(capsys, bucket, glossary):
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
PROJECT_ID,
glossary,
240
)

out, _ = capsys.readouterr()
Expand Down
9 changes: 5 additions & 4 deletions translate/cloud-client/translate_v3_create_glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@


def create_glossary(
project_id="YOUR_PROJECT_ID",
input_uri="YOUR_INPUT_URI",
glossary_id="YOUR_GLOSSARY_ID",
project_id="YOUR_PROJECT_ID",
input_uri="YOUR_INPUT_URI",
glossary_id="YOUR_GLOSSARY_ID",
timeout=180,
):
"""
Create a equivalent term sets glossary. Glossary can be words or
Expand Down Expand Up @@ -51,7 +52,7 @@ def create_glossary(
# to translate the domain-specific terminology.
operation = client.create_glossary(parent=parent, glossary=glossary)

result = operation.result(timeout=180)
result = operation.result(timeout)
tmatsuo marked this conversation as resolved.
Show resolved Hide resolved
print("Created: {}".format(result.name))
print("Input Uri: {}".format(result.input_config.gcs_source.input_uri))

Expand Down
6 changes: 4 additions & 2 deletions translate/cloud-client/translate_v3_delete_glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@


def delete_glossary(
project_id="YOUR_PROJECT_ID", glossary_id="YOUR_GLOSSARY_ID"
project_id="YOUR_PROJECT_ID",
glossary_id="YOUR_GLOSSARY_ID",
timeout=180,
):
"""Delete a specific glossary based on the glossary ID."""
client = translate.TranslationServiceClient()

parent = client.glossary_path(project_id, "us-central1", glossary_id)

operation = client.delete_glossary(parent)
result = operation.result(timeout=180)
result = operation.result(timeout)
tmatsuo marked this conversation as resolved.
Show resolved Hide resolved
print("Deleted: {}".format(result.name))


Expand Down