Skip to content

Commit 3be0b8f

Browse files
busunkim96danoscarmike
authored andcommitted
[translate] fix hybrid glossaries tests [(#3936)](#3936)
1 parent 334da61 commit 3be0b8f

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

translation/samples/snippets/hybrid_glossaries/hybrid_tutorial.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,28 @@ def text_to_speech(text, outfile):
193193
client = texttospeech.TextToSpeechClient()
194194

195195
# Sets the text input to be synthesized
196-
synthesis_input = texttospeech.types.SynthesisInput(ssml=ssml)
196+
synthesis_input = texttospeech.SynthesisInput(ssml=ssml)
197197

198198
# Builds the voice request, selects the language code ("en-US") and
199199
# the SSML voice gender ("MALE")
200-
voice = texttospeech.types.VoiceSelectionParams(
200+
voice = texttospeech.VoiceSelectionParams(
201201
language_code='en-US',
202-
ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE)
202+
ssml_gender=texttospeech.SsmlVoiceGender.MALE)
203203

204204
# Selects the type of audio file to return
205-
audio_config = texttospeech.types.AudioConfig(
206-
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
205+
audio_config = texttospeech.AudioConfig(
206+
audio_encoding=texttospeech.AudioEncoding.MP3)
207207

208208
# Performs the text-to-speech request on the text input with the selected
209209
# voice parameters and audio file type
210-
response = client.synthesize_speech(synthesis_input, voice, audio_config)
210+
211+
request = texttospeech.SynthesizeSpeechRequest(
212+
input=synthesis_input,
213+
voice=voice,
214+
audio_config=audio_config
215+
)
216+
217+
response = client.synthesize_speech(request=request)
211218

212219
# Writes the synthetic audio to the output file.
213220
with open(outfile, 'wb') as out:

translation/samples/snippets/hybrid_glossaries/hybrid_tutorial_tests.py renamed to translation/samples/snippets/hybrid_glossaries/hybrid_tutorial_test.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# limitations under the License.
1414

1515
import os
16+
import re
1617
import sys
18+
import uuid
1719

1820
from hybrid_tutorial import create_glossary
1921
from hybrid_tutorial import pic_to_text
@@ -28,14 +30,10 @@
2830

2931

3032
def test_vision_standard_format():
31-
32-
expected_text = 'This is\na test!\n'
33-
alt_expected_text = 'This\nis\na test!\n'
34-
3533
# Generate text using Vision API
3634
text = pic_to_text('resources/standard_format.jpeg')
3735

38-
assert (text == expected_text) or (text == alt_expected_text)
36+
assert re.match(r"This\s?is\s?a\s?test!\s?", text)
3937

4038

4139
def test_vision_non_standard_format():
@@ -58,7 +56,7 @@ def test_create_and_delete_glossary():
5856
from beta_snippets import delete_glossary
5957

6058
languages = ['fr', 'en']
61-
glossary_name = 'test-glossary'
59+
glossary_name = f'test-glossary-{uuid.uuid4()}'
6260
glossary_uri = 'gs://cloud-samples-data/translation/bistro_glossary.csv'
6361

6462
# create_glossary will raise an exception if creation fails
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
google-cloud-translate==2.0.1
22
google-cloud-vision==1.0.0
3-
google-cloud-texttospeech==1.0.1
3+
google-cloud-texttospeech==2.0.0

translation/samples/snippets/hybrid_glossaries/resources/non_standard_format.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ $10
1919
Firebase Fruit Salad
2020
watermelon, honeydew melon,
2121
and pineapple
22+
$6
2223
Compute Engine Burger
2324
quarter-pound burger with
2425
cheddar cheese
2526
$10
26-
$6
2727
BigQuery BLT
2828
bacon, lettuce, and tomato
2929
sandwich
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
# don't recurse into hybrid_glossaries directory
3+
norecursedirs = *

0 commit comments

Comments
 (0)