Skip to content

Commit

Permalink
testing(translate): parameterize the timeout [(#4247)](GoogleCloudPla…
Browse files Browse the repository at this point in the history
…tform/python-docs-samples#4247)

fixes #4239
(by specifying a longer timeout)
  • Loading branch information
Takashi Matsuo authored and danoscarmike committed Jul 31, 2020
1 parent 4a45305 commit 7af4c99
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
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)

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)

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
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)
print("Created: {}".format(result.name))
print("Input Uri: {}".format(result.input_config.gcs_source.input_uri))

Expand Down
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)
print("Deleted: {}".format(result.name))


Expand Down

0 comments on commit 7af4c99

Please sign in to comment.