Skip to content

Commit

Permalink
chore: fix flaky tests (#78)
Browse files Browse the repository at this point in the history
* chore: fix flaky tests

* fixed the lint

* removed yaml file
  • Loading branch information
munkhuushmgl authored Oct 29, 2020
1 parent e832681 commit e3d767b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 77 deletions.
2 changes: 1 addition & 1 deletion translation/samples/snippets/beta_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def batch_translate_text(project_id, input_uri, output_uri):
}
)

result = operation.result(timeout=240)
result = operation.result(timeout=320)

print("Total Characters: {}".format(result.total_characters))
print("Translated Characters: {}".format(result.translated_characters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_batch_translate_text(capsys, bucket):
"gs://cloud-samples-data/translation/text.txt",
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
PROJECT_ID,
timeout=240,
timeout=320,
)
out, _ = capsys.readouterr()
assert "Total Characters" in out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def batch_translate_text_with_glossary(
output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/",
project_id="YOUR_PROJECT_ID",
glossary_id="YOUR_GLOSSARY_ID",
timeout=180,
timeout=320,
):
"""Translates a batch of texts on GCS and stores the result in a GCS location.
Glossary is applied for translation."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,38 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# DO NOT EDIT! This is a generated sample ("LongRunningPromise", "translate_v3_batch_translate_text_with_glossary_and_model")

# To install the latest published package dependency, execute the following:
# pip install google-cloud-translate

# sample-metadata
# title: Batch Translate with Glossary and Model
# description: Batch translate text with Glossary using AutoML Translation model
# 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}"]

# [START translate_v3_batch_translate_text_with_glossary_and_model]
from google.cloud import translate


def sample_batch_translate_text_with_glossary_and_model(
input_uri,
output_uri,
project_id,
location,
target_language,
source_language,
model_id,
glossary_id,
def batch_translate_text_with_glossary_and_model(
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",
model_id="YOUR_MODEL_ID",
glossary_id="YOUR_GLOSSARY_ID",
):
"""
Batch translate text with Glossary and Translation model
"""

client = translate.TranslationServiceClient()

# TODO(developer): Uncomment and set the following variables
# 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]'
target_language_codes = [target_language]
# Supported language codes: https://cloud.google.com/translate/docs/languages
location = "us-central1"

target_language_codes = ["ja"]
gcs_source = {"input_uri": input_uri}

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

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


# [END translate_v3_batch_translate_text_with_glossary_and_model]


def main():
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
"--input_uri", type=str, default="gs://cloud-samples-data/text.txt"
)
parser.add_argument(
"--output_uri", type=str, default="gs://YOUR_BUCKET_ID/path_to_store_results/"
)
parser.add_argument("--project_id", type=str, default="[Google Cloud Project ID]")
parser.add_argument("--location", type=str, default="us-central1")
parser.add_argument("--target_language", type=str, default="en")
parser.add_argument("--source_language", type=str, default="de")
parser.add_argument("--model_id", type=str, default="{your-model-id}")
parser.add_argument(
"--glossary_id", type=str, default="[YOUR_GLOSSARY_ID]",
)
args = parser.parse_args()

sample_batch_translate_text_with_glossary_and_model(
args.input_uri,
args.output_uri,
args.project_id,
args.location,
args.target_language,
args.source_language,
args.model_id,
args.glossary_id,
)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ def bucket():


def test_batch_translate_text_with_glossary_and_model(capsys, bucket, glossary):
translate_v3_batch_translate_text_with_glossary_and_model.sample_batch_translate_text_with_glossary_and_model(
translate_v3_batch_translate_text_with_glossary_and_model.batch_translate_text_with_glossary_and_model(
"gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt",
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
PROJECT_ID,
"us-central1",
"ja",
"en",
MODEL_ID,
glossary,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_batch_translate_text_with_glossary(capsys, bucket, glossary):
"gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name),
PROJECT_ID,
glossary,
240,
320,
)

out, _ = capsys.readouterr()
Expand Down

0 comments on commit e3d767b

Please sign in to comment.