File tree Expand file tree Collapse file tree 2 files changed +43
-4
lines changed
translation/samples/snippets Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -27,16 +27,15 @@ def run_quickstart():
2727 translate_client = translate .Client (api_key )
2828
2929 # The text to translate
30- text = 'Hello, world!'
30+ text = u 'Hello, world!'
3131 # The target language
3232 target = 'ru'
3333
3434 # Translates some text into Russian
3535 translation = translate_client .translate (text , target_language = target )
3636
37- print ('Text: {}' .format (text ))
38- print ('Translation: {}' .format (
39- translation ['translatedText' ].encode ('utf-8' )))
37+ print (u'Text: {}' .format (text ))
38+ print (u'Translation: {}' .format (translation ['translatedText' ]))
4039 # [END translate_quickstart]
4140
4241
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ # Copyright 2016 Google Inc. All Rights Reserved.
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ #
8+ # http://www.apache.org/licenses/LICENSE-2.0
9+ #
10+ # Unless required by applicable law or agreed to in writing, software
11+ # distributed under the License is distributed on an "AS IS" BASIS,
12+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ # See the License for the specific language governing permissions and
14+ # limitations under the License.
15+
16+ from google .cloud import translate
17+ import mock
18+ import pytest
19+
20+ import quickstart
21+
22+
23+ @pytest .fixture
24+ def mock_client (cloud_config ):
25+ original_client_ctor = translate .Client
26+
27+ def new_client_ctor (api_key ):
28+ # Strip api_key argument and replace with our api key.
29+ return original_client_ctor (cloud_config .api_key )
30+
31+ with mock .patch (
32+ 'google.cloud.translate.Client' ,
33+ side_effect = new_client_ctor ):
34+ yield
35+
36+
37+ def test_quickstart (mock_client , capsys ):
38+ quickstart .run_quickstart ()
39+ out , _ = capsys .readouterr ()
40+ assert u'Привет мир!' in out
You can’t perform that action at this time.
0 commit comments