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

translate: fix glossary leak issue #3572

Merged
merged 14 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def glossary():

yield glossary_id

try:
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
except Exception:
pass
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
munkhuushmgl marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture(scope="function")
Expand Down
6 changes: 1 addition & 5 deletions translate/cloud-client/translate_v3_create_glossary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ def test_create_glossary(capsys):
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
finally:
# clean up after use
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except Exception:
pass
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
2 changes: 1 addition & 1 deletion translate/cloud-client/translate_v3_detect_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from google.cloud import translate


def sample_detect_language(project_id="YOUR_PROJECT_ID"):
def detect_language(project_id="YOUR_PROJECT_ID"):
tmatsuo marked this conversation as resolved.
Show resolved Hide resolved
"""Detecting the language of a text string."""

client = translate.TranslationServiceClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@


def test_detect_language(capsys):
translate_v3_detect_language.sample_detect_language(PROJECT_ID)
translate_v3_detect_language.detect_language(PROJECT_ID)
out, _ = capsys.readouterr()
assert "en" in out
5 changes: 1 addition & 4 deletions translate/cloud-client/translate_v3_get_glossary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def glossary():

yield glossary_id

try:
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
except Exception:
pass
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)


def test_get_glossary(capsys, glossary):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from google.cloud import translate


def sample_get_supported_languages(project_id="YOUR_PROJECT_ID"):
def get_supported_languages(project_id="YOUR_PROJECT_ID"):
"""Getting a list of supported language codes."""

client = translate.TranslationServiceClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@


def test_list_languages(capsys):
translate_v3_get_supported_languages.sample_get_supported_languages(PROJECT_ID)
translate_v3_get_supported_languages.get_supported_languages(PROJECT_ID)
out, _ = capsys.readouterr()
assert "zh-CN" in out
2 changes: 1 addition & 1 deletion translate/cloud-client/translate_v3_list_glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from google.cloud import translate


def sample_list_glossaries(project_id="YOUR_PROJECT_ID"):
def list_glossaries(project_id="YOUR_PROJECT_ID"):
"""List Glossaries."""

client = translate.TranslationServiceClient()
Expand Down
8 changes: 3 additions & 5 deletions translate/cloud-client/translate_v3_list_glossary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ def glossary():

yield glossary_id

try:
translate_v3_delete_glossary.sample_delete_glossary(PROJECT_ID, glossary_id)
except Exception:
pass
# clean up
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)


def test_list_glossary(capsys, glossary):
translate_v3_list_glossary.sample_list_glossaries(PROJECT_ID)
translate_v3_list_glossary.list_glossaries(PROJECT_ID)
out, _ = capsys.readouterr()
assert glossary in out
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
2 changes: 1 addition & 1 deletion translate/cloud-client/translate_v3_translate_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from google.cloud import translate


def sample_translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
"""Translating Text."""

client = translate.TranslationServiceClient()
Expand Down
2 changes: 1 addition & 1 deletion translate/cloud-client/translate_v3_translate_text_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def test_translate_text(capsys):
translate_v3_translate_text.sample_translate_text(
translate_v3_translate_text.translate_text(
"Hello World!", PROJECT_ID)
out, _ = capsys.readouterr()
assert "Bonjour le monde" in out
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def glossary():

yield glossary_id

try:
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
except Exception:
pass
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)


def test_translate_text_with_glossary(capsys, glossary):
Expand Down