Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix: translate test [(#2671)](GoogleCloudPlatform/python-docs-samples…
Browse files Browse the repository at this point in the history
…#2671)

* fix: translate test

* Add unicode formatting
  • Loading branch information
leahecole authored and danoscarmike committed Jul 31, 2020
1 parent a065930 commit a3d9f80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
39 changes: 20 additions & 19 deletions samples/snippets/beta_snippets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -34,7 +35,7 @@ def translate_text(project_id, text):
target_language_code='sr-Latn')

for translation in response.translations:
print('Translated Text: {}'.format(translation))
print(u'Translated Text: {}'.format(translation))
# [END translate_translate_text_beta]


Expand Down Expand Up @@ -71,8 +72,8 @@ def batch_translate_text(project_id, input_uri, output_uri):

result = operation.result(90)

print('Total Characters: {}'.format(result.total_characters))
print('Translated Characters: {}'.format(result.translated_characters))
print(u'Total Characters: {}'.format(result.total_characters))
print(u'Translated Characters: {}'.format(result.translated_characters))
# [END translate_batch_translate_text_beta]


Expand All @@ -93,7 +94,7 @@ def detect_language(project_id, text):
mime_type='text/plain') # mime types: text/plain, text/html

for language in response.languages:
print('Language Code: {} (Confidence: {})'.format(
print(u'Language Code: {} (Confidence: {})'.format(
language.language_code,
language.confidence))
# [END translate_detect_language_beta]
Expand All @@ -113,7 +114,7 @@ def list_languages(project_id):

print('Supported Languages:')
for language in response.languages:
print('Language Code: {}'.format(language.language_code))
print(u'Language Code: {}'.format(language.language_code))
# [END translate_list_codes_beta]


Expand All @@ -134,8 +135,8 @@ def list_languages_with_target(project_id, display_language_code):

print('Supported Languages:')
for language in response.languages:
print('Language Code: {}'.format(language.language_code))
print('Display Name: {}\n'.format(language.display_name))
print(u'Language Code: {}'.format(language.language_code))
print(u'Display Name: {}\n'.format(language.display_name))
# [END translate_list_language_names_beta]


Expand Down Expand Up @@ -172,8 +173,8 @@ def create_glossary(project_id, glossary_id):
operation = client.create_glossary(parent=parent, glossary=glossary)

result = operation.result(timeout=90)
print('Created: {}'.format(result.name))
print('Input Uri: {}'.format(result.input_config.gcs_source.input_uri))
print(u'Created: {}'.format(result.name))
print(u'Input Uri: {}'.format(result.input_config.gcs_source.input_uri))
# [END translate_create_glossary_beta]


Expand All @@ -188,12 +189,12 @@ def list_glossaries(project_id):
parent = client.location_path(project_id, location)

for glossary in client.list_glossaries(parent):
print('Name: {}'.format(glossary.name))
print('Entry count: {}'.format(glossary.entry_count))
print('Input uri: {}'.format(
print(u'Name: {}'.format(glossary.name))
print(u'Entry count: {}'.format(glossary.entry_count))
print(u'Input uri: {}'.format(
glossary.input_config.gcs_source.input_uri))
for language_code in glossary.language_codes_set.language_codes:
print('Language code: {}'.format(language_code))
print(u'Language code: {}'.format(language_code))
# [END translate_list_glossary_beta]


Expand All @@ -211,13 +212,13 @@ def get_glossary(project_id, glossary_id):
glossary_id)

response = client.get_glossary(parent)
print('Name: {}'.format(response.name))
print('Language Pair:')
print('\tSource Language Code: {}'.format(
print(u'Name: {}'.format(response.name))
print(u'Language Pair:')
print(u'\tSource Language Code: {}'.format(
response.language_pair.source_language_code))
print('\tTarget Language Code: {}'.format(
print(u'\tTarget Language Code: {}'.format(
response.language_pair.target_language_code))
print('Input Uri: {}'.format(
print(u'Input Uri: {}'.format(
response.input_config.gcs_source.input_uri))
# [END translate_get_glossary_beta]

Expand All @@ -237,7 +238,7 @@ def delete_glossary(project_id, glossary_id):

operation = client.delete_glossary(parent)
result = operation.result(timeout=90)
print('Deleted: {}'.format(result.name))
print(u'Deleted: {}'.format(result.name))
# [END translate_delete_glossary_beta]


Expand Down
5 changes: 3 additions & 2 deletions samples/snippets/beta_snippets_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -63,7 +64,7 @@ def unique_glossary_id():
def test_translate_text(capsys):
beta_snippets.translate_text(PROJECT_ID, 'Hello world')
out, _ = capsys.readouterr()
assert 'Zdravo svet' in out or 'Pozdrav svijetu' in out
assert 'Zdravo svijete' in out or 'Pozdrav svijetu' in out


def test_batch_translate_text(capsys, bucket):
Expand All @@ -77,7 +78,7 @@ def test_batch_translate_text(capsys, bucket):


def test_detect_language(capsys):
beta_snippets.detect_language(PROJECT_ID, 'Hæ sæta')
beta_snippets.detect_language(PROJECT_ID, u'Hæ sæta')
out, _ = capsys.readouterr()
assert 'is' in out

Expand Down

0 comments on commit a3d9f80

Please sign in to comment.