From c2cb9f67eab41b38c0fc00d8b7849b200058bb93 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Mon, 6 Jul 2020 15:41:37 -0700 Subject: [PATCH] testing(translate): parameterize the timeout [(#4247)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4247) fixes #4239 (by specifying a longer timeout) --- .../snippets/translate_v3_batch_translate_text.py | 9 +++++---- ...translate_v3_batch_translate_text_with_glossary.py | 11 ++++++----- ...late_v3_batch_translate_text_with_glossary_test.py | 1 + .../samples/snippets/translate_v3_create_glossary.py | 9 +++++---- .../samples/snippets/translate_v3_delete_glossary.py | 6 ++++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/translation/samples/snippets/translate_v3_batch_translate_text.py b/translation/samples/snippets/translate_v3_batch_translate_text.py index 6c67d2c22dc6..4454afb40746 100644 --- a/translation/samples/snippets/translate_v3_batch_translate_text.py +++ b/translation/samples/snippets/translate_v3_batch_translate_text.py @@ -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.""" @@ -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)) diff --git a/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary.py b/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary.py index d72c31860b8c..97845e2a8e2b 100644 --- a/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary.py +++ b/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary.py @@ -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.""" @@ -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)) diff --git a/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_test.py b/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_test.py index 1a1850ac562e..23aa6691f1ee 100644 --- a/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_test.py +++ b/translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_test.py @@ -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() diff --git a/translation/samples/snippets/translate_v3_create_glossary.py b/translation/samples/snippets/translate_v3_create_glossary.py index a94e488eb4a5..603cb4cc5681 100644 --- a/translation/samples/snippets/translate_v3_create_glossary.py +++ b/translation/samples/snippets/translate_v3_create_glossary.py @@ -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 @@ -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)) diff --git a/translation/samples/snippets/translate_v3_delete_glossary.py b/translation/samples/snippets/translate_v3_delete_glossary.py index f3f897532149..e8acf76c31f4 100644 --- a/translation/samples/snippets/translate_v3_delete_glossary.py +++ b/translation/samples/snippets/translate_v3_delete_glossary.py @@ -17,7 +17,9 @@ 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() @@ -25,7 +27,7 @@ def delete_glossary( 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))