Skip to content

Commit fd190d2

Browse files
munkhuushmgldandhlee
authored andcommitted
chore: fix flaky tests (#78)
* chore: fix flaky tests * fixed the lint * removed yaml file
1 parent 538fa9d commit fd190d2

6 files changed

+17
-77
lines changed

translation/samples/snippets/beta_snippets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def batch_translate_text(project_id, input_uri, output_uri):
7777
}
7878
)
7979

80-
result = operation.result(timeout=240)
80+
result = operation.result(timeout=320)
8181

8282
print("Total Characters: {}".format(result.total_characters))
8383
print("Translated Characters: {}".format(result.translated_characters))

translation/samples/snippets/translate_v3_batch_translate_text_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_batch_translate_text(capsys, bucket):
4242
"gs://cloud-samples-data/translation/text.txt",
4343
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
4444
PROJECT_ID,
45-
timeout=240,
45+
timeout=320,
4646
)
4747
out, _ = capsys.readouterr()
4848
assert "Total Characters" in out

translation/samples/snippets/translate_v3_batch_translate_text_with_glossary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def batch_translate_text_with_glossary(
2222
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
2323
project_id="YOUR_PROJECT_ID",
2424
glossary_id="YOUR_GLOSSARY_ID",
25-
timeout=180,
25+
timeout=320,
2626
):
2727
"""Translates a batch of texts on GCS and stores the result in a GCS location.
2828
Glossary is applied for translation."""
Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,38 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Copyright 2019 Google LLC
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.
75
# You may obtain a copy of the License at
86
#
9-
# https://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
108
#
119
# Unless required by applicable law or agreed to in writing, software
1210
# distributed under the License is distributed on an "AS IS" BASIS,
1311
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1412
# See the License for the specific language governing permissions and
1513
# limitations under the License.
1614

17-
# DO NOT EDIT! This is a generated sample ("LongRunningPromise", "translate_v3_batch_translate_text_with_glossary_and_model")
18-
19-
# To install the latest published package dependency, execute the following:
20-
# pip install google-cloud-translate
21-
22-
# sample-metadata
23-
# title: Batch Translate with Glossary and Model
24-
# description: Batch translate text with Glossary using AutoML Translation model
25-
# usage: python3 translate_v3_batch_translate_text_with_glossary_and_model.py [--input_uri "gs://cloud-samples-data/text.txt"] [--output_uri "gs://YOUR_BUCKET_ID/path_to_store_results/"] [--project "[Google Cloud Project ID]"] [--location "us-central1"] [--target_language en] [--source_language de] [--model_id "{your-model-id}"] [--glossary_id "{your-glossary-id}"]
26-
2715
# [START translate_v3_batch_translate_text_with_glossary_and_model]
2816
from google.cloud import translate
2917

3018

31-
def sample_batch_translate_text_with_glossary_and_model(
32-
input_uri,
33-
output_uri,
34-
project_id,
35-
location,
36-
target_language,
37-
source_language,
38-
model_id,
39-
glossary_id,
19+
def batch_translate_text_with_glossary_and_model(
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+
model_id="YOUR_MODEL_ID",
24+
glossary_id="YOUR_GLOSSARY_ID",
4025
):
4126
"""
4227
Batch translate text with Glossary and Translation model
4328
"""
4429

4530
client = translate.TranslationServiceClient()
4631

47-
# TODO(developer): Uncomment and set the following variables
48-
# input_uri = 'gs://cloud-samples-data/text.txt'
49-
# output_uri = 'gs://YOUR_BUCKET_ID/path_to_store_results/'
50-
# project = '[Google Cloud Project ID]'
51-
# location = 'us-central1'
52-
# target_language = 'en'
53-
# source_language = 'de'
54-
# model_id = '{your-model-id}'
55-
# glossary_id = '[YOUR_GLOSSARY_ID]'
56-
target_language_codes = [target_language]
32+
# Supported language codes: https://cloud.google.com/translate/docs/languages
33+
location = "us-central1"
34+
35+
target_language_codes = ["ja"]
5736
gcs_source = {"input_uri": input_uri}
5837

5938
# Optional. Can be "text/plain" or "text/html".
@@ -66,7 +45,7 @@ def sample_batch_translate_text_with_glossary_and_model(
6645
model_path = "projects/{}/locations/{}/models/{}".format(
6746
project_id, "us-central1", model_id
6847
)
69-
models = {target_language: model_path}
48+
models = {"ja": model_path}
7049

7150
glossary_path = client.glossary_path(
7251
project_id, "us-central1", glossary_id # The location of the glossary
@@ -96,39 +75,3 @@ def sample_batch_translate_text_with_glossary_and_model(
9675

9776

9877
# [END translate_v3_batch_translate_text_with_glossary_and_model]
99-
100-
101-
def main():
102-
import argparse
103-
104-
parser = argparse.ArgumentParser()
105-
parser.add_argument(
106-
"--input_uri", type=str, default="gs://cloud-samples-data/text.txt"
107-
)
108-
parser.add_argument(
109-
"--output_uri", type=str, default="gs://YOUR_BUCKET_ID/path_to_store_results/"
110-
)
111-
parser.add_argument("--project_id", type=str, default="[Google Cloud Project ID]")
112-
parser.add_argument("--location", type=str, default="us-central1")
113-
parser.add_argument("--target_language", type=str, default="en")
114-
parser.add_argument("--source_language", type=str, default="de")
115-
parser.add_argument("--model_id", type=str, default="{your-model-id}")
116-
parser.add_argument(
117-
"--glossary_id", type=str, default="[YOUR_GLOSSARY_ID]",
118-
)
119-
args = parser.parse_args()
120-
121-
sample_batch_translate_text_with_glossary_and_model(
122-
args.input_uri,
123-
args.output_uri,
124-
args.project_id,
125-
args.location,
126-
args.target_language,
127-
args.source_language,
128-
args.model_id,
129-
args.glossary_id,
130-
)
131-
132-
133-
if __name__ == "__main__":
134-
main()

translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_and_model_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ def bucket():
5656

5757

5858
def test_batch_translate_text_with_glossary_and_model(capsys, bucket, glossary):
59-
translate_v3_batch_translate_text_with_glossary_and_model.sample_batch_translate_text_with_glossary_and_model(
59+
translate_v3_batch_translate_text_with_glossary_and_model.batch_translate_text_with_glossary_and_model(
6060
"gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt",
6161
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
6262
PROJECT_ID,
63-
"us-central1",
64-
"ja",
65-
"en",
6663
MODEL_ID,
6764
glossary,
6865
)

translation/samples/snippets/translate_v3_batch_translate_text_with_glossary_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +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,
76+
320,
7777
)
7878

7979
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)