Skip to content

Commit 6b0db5f

Browse files
munkhuushmgldandhlee
authored andcommitted
chore: fixed wrong method name (#100)
Due to wrong method usage one method, it led to glossary max [1000] from not deleting glossary in the teardown. Fixes #95, #96, #97, #98 🦕
1 parent 53bd9c9 commit 6b0db5f

3 files changed

+20
-7
lines changed

translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_and_model_test.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import os
1616
import uuid
1717

18+
import backoff
19+
from google.api_core.exceptions import DeadlineExceeded, GoogleAPICallError
1820
from google.cloud import storage
21+
from google.cloud.exceptions import NotFound
1922
import pytest
2023

2124
import translate_v3_batch_translate_text_with_glossary_and_model
@@ -37,16 +40,24 @@ def glossary():
3740

3841
yield glossary_id
3942

40-
try:
41-
translate_v3_delete_glossary.sample_delete_glossary(PROJECT_ID, glossary_id)
42-
except Exception:
43-
pass
43+
# clean up
44+
@backoff.on_exception(
45+
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
46+
)
47+
def delete_glossary():
48+
try:
49+
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
50+
except NotFound as e:
51+
# Ignoring this case.
52+
print("Got NotFound, detail: {}".format(str(e)))
53+
54+
delete_glossary()
4455

4556

4657
@pytest.fixture(scope="function")
4758
def bucket():
4859
"""Create a temporary bucket to store annotation output."""
49-
bucket_name = "mike-test-delete-" + str(uuid.uuid1())
60+
bucket_name = "test-bucket-for-glossary-" + str(uuid.uuid1())
5061
storage_client = storage.Client()
5162
bucket = storage_client.create_bucket(bucket_name)
5263

translation/samples/snippets/translate_v3_batch_translate_text_with_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def batch_translate_text_with_model(
2424
model_id="YOUR_MODEL_ID",
2525
):
2626
"""Batch translate text using Translation model.
27-
Model can be AutoML or General[built-in] model. """
27+
Model can be AutoML or General[built-in] model."""
2828

2929
client = translate.TranslationServiceClient()
3030

translation/samples/snippets/translate_v3_delete_glossary.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818

1919
def delete_glossary(
20-
project_id="YOUR_PROJECT_ID", glossary_id="YOUR_GLOSSARY_ID", timeout=180,
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()

0 commit comments

Comments
 (0)