Skip to content

Commit c2cb9f6

Browse files
Takashi Matsuodanoscarmike
Takashi Matsuo
authored andcommitted
testing(translate): parameterize the timeout [(#4247)](#4247)
fixes #4239 (by specifying a longer timeout)
1 parent e9cce11 commit c2cb9f6

5 files changed

+21
-15
lines changed

translation/samples/snippets/translate_v3_batch_translate_text.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818

1919
def batch_translate_text(
20-
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
21-
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
22-
project_id="YOUR_PROJECT_ID"
20+
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
21+
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
22+
project_id="YOUR_PROJECT_ID",
23+
timeout=180,
2324
):
2425
"""Translates a batch of texts on GCS and stores the result in a GCS location."""
2526

@@ -46,7 +47,7 @@ def batch_translate_text(
4647
output_config=output_config)
4748

4849
print(u"Waiting for operation to complete...")
49-
response = operation.result(180)
50+
response = operation.result(timeout)
5051

5152
print(u"Total Characters: {}".format(response.total_characters))
5253
print(u"Translated Characters: {}".format(response.translated_characters))

translation/samples/snippets/translate_v3_batch_translate_text_with_glossary.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919

2020
def batch_translate_text_with_glossary(
21-
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
22-
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
23-
project_id="YOUR_PROJECT_ID",
24-
glossary_id="YOUR_GLOSSARY_ID",
21+
input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt",
22+
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
23+
project_id="YOUR_PROJECT_ID",
24+
glossary_id="YOUR_GLOSSARY_ID",
25+
timeout=180,
2526
):
2627
"""Translates a batch of texts on GCS and stores the result in a GCS location.
2728
Glossary is applied for translation."""
@@ -65,7 +66,7 @@ def batch_translate_text_with_glossary(
6566
)
6667

6768
print(u"Waiting for operation to complete...")
68-
response = operation.result(180)
69+
response = operation.result(timeout)
6970

7071
print(u"Total Characters: {}".format(response.total_characters))
7172
print(u"Translated Characters: {}".format(response.translated_characters))

translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_batch_translate_text_with_glossary(capsys, bucket, glossary):
7373
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
7474
PROJECT_ID,
7575
glossary,
76+
240
7677
)
7778

7879
out, _ = capsys.readouterr()

translation/samples/snippets/translate_v3_create_glossary.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818

1919
def create_glossary(
20-
project_id="YOUR_PROJECT_ID",
21-
input_uri="YOUR_INPUT_URI",
22-
glossary_id="YOUR_GLOSSARY_ID",
20+
project_id="YOUR_PROJECT_ID",
21+
input_uri="YOUR_INPUT_URI",
22+
glossary_id="YOUR_GLOSSARY_ID",
23+
timeout=180,
2324
):
2425
"""
2526
Create a equivalent term sets glossary. Glossary can be words or
@@ -51,7 +52,7 @@ def create_glossary(
5152
# to translate the domain-specific terminology.
5253
operation = client.create_glossary(parent=parent, glossary=glossary)
5354

54-
result = operation.result(timeout=180)
55+
result = operation.result(timeout)
5556
print("Created: {}".format(result.name))
5657
print("Input Uri: {}".format(result.input_config.gcs_source.input_uri))
5758

translation/samples/snippets/translate_v3_delete_glossary.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717

1818

1919
def delete_glossary(
20-
project_id="YOUR_PROJECT_ID", glossary_id="YOUR_GLOSSARY_ID"
20+
project_id="YOUR_PROJECT_ID",
21+
glossary_id="YOUR_GLOSSARY_ID",
22+
timeout=180,
2123
):
2224
"""Delete a specific glossary based on the glossary ID."""
2325
client = translate.TranslationServiceClient()
2426

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

2729
operation = client.delete_glossary(parent)
28-
result = operation.result(timeout=180)
30+
result = operation.result(timeout)
2931
print("Deleted: {}".format(result.name))
3032

3133

0 commit comments

Comments
 (0)