@@ -94,10 +94,8 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
94
94
95
95
from google .cloud ._helpers import _bytes_to_unicode
96
96
from google .cloud ._helpers import _to_bytes
97
- from google .cloud ._testing import _Monkey
98
97
99
98
from google .cloud import speech
100
- from google .cloud .speech import client as MUT
101
99
from google .cloud .speech .alternative import Alternative
102
100
from google .cloud .speech .sample import Sample
103
101
from unit_tests ._fixtures import SYNC_RECOGNIZE_RESPONSE
@@ -130,12 +128,12 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
130
128
131
129
sample = Sample (content = self .AUDIO_CONTENT , encoding = encoding ,
132
130
sample_rate = self .SAMPLE_RATE )
133
- with _Monkey ( MUT , _USE_GAX = False ):
134
- response = client .sync_recognize (sample ,
135
- language_code = 'EN' ,
136
- max_alternatives = 2 ,
137
- profanity_filter = True ,
138
- speech_context = self .HINTS )
131
+
132
+ response = client .sync_recognize (sample ,
133
+ language_code = 'EN' ,
134
+ max_alternatives = 2 ,
135
+ profanity_filter = True ,
136
+ speech_context = self .HINTS )
139
137
140
138
self .assertEqual (len (client .connection ._requested ), 1 )
141
139
req = client .connection ._requested [0 ]
@@ -152,10 +150,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
152
150
self .assertEqual (response [0 ].confidence , expected .confidence )
153
151
154
152
def test_sync_recognize_source_uri_without_optional_params_no_gax (self ):
155
- from google .cloud ._testing import _Monkey
156
-
157
153
from google .cloud import speech
158
- from google .cloud .speech import client as MUT
159
154
from google .cloud .speech .alternative import Alternative
160
155
from google .cloud .speech .sample import Sample
161
156
from unit_tests ._fixtures import SYNC_RECOGNIZE_RESPONSE
@@ -178,8 +173,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
178
173
179
174
sample = Sample (source_uri = self .AUDIO_SOURCE_URI , encoding = encoding ,
180
175
sample_rate = self .SAMPLE_RATE )
181
- with _Monkey ( MUT , _USE_GAX = False ):
182
- response = client .sync_recognize (sample )
176
+
177
+ response = client .sync_recognize (sample )
183
178
184
179
self .assertEqual (len (client .connection ._requested ), 1 )
185
180
req = client .connection ._requested [0 ]
@@ -196,23 +191,20 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
196
191
self .assertEqual (response [0 ].confidence , expected .confidence )
197
192
198
193
def test_sync_recognize_with_empty_results_no_gax (self ):
199
- from google .cloud ._testing import _Monkey
200
-
201
194
from google .cloud import speech
202
- from google .cloud .speech import client as MUT
203
195
from google .cloud .speech .sample import Sample
204
196
from unit_tests ._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE
205
197
206
198
credentials = _Credentials ()
207
199
client = self ._makeOne (credentials = credentials , use_gax = False )
208
200
client .connection = _Connection (SYNC_RECOGNIZE_EMPTY_RESPONSE )
209
201
202
+ sample = Sample (source_uri = self .AUDIO_SOURCE_URI ,
203
+ encoding = speech .Encoding .FLAC ,
204
+ sample_rate = self .SAMPLE_RATE )
205
+
210
206
with self .assertRaises (ValueError ):
211
- with _Monkey (MUT , _USE_GAX = False ):
212
- sample = Sample (source_uri = self .AUDIO_SOURCE_URI ,
213
- encoding = speech .Encoding .FLAC ,
214
- sample_rate = self .SAMPLE_RATE )
215
- client .sync_recognize (sample )
207
+ client .sync_recognize (sample )
216
208
217
209
def test_sync_recognize_with_empty_results_gax (self ):
218
210
from google .cloud ._testing import _Monkey
@@ -334,7 +326,11 @@ def test_async_recognize_with_gax(self):
334
326
sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
335
327
encoding = speech .Encoding .LINEAR16 ,
336
328
sample_rate = self .SAMPLE_RATE )
337
- with _Monkey (_gax , SpeechApi = _MockGAPICSpeechAPI ):
329
+
330
+ def speech_api ():
331
+ return _MockGAPICSpeechAPI ()
332
+
333
+ with _Monkey (_gax , SpeechApi = speech_api ):
338
334
operation = client .async_recognize (sample )
339
335
340
336
self .assertIsInstance (operation , Operation )
@@ -349,10 +345,18 @@ def test_speech_api_with_gax(self):
349
345
350
346
creds = _Credentials ()
351
347
client = self ._makeOne (credentials = creds , use_gax = True )
348
+ client .connection = _Connection ()
349
+ client .connection .credentials = creds
350
+
351
+ def speech_api ():
352
+ return _MockGAPICSpeechAPI ()
353
+
354
+ self .assertIsNone (client ._speech_api )
355
+
356
+ with _Monkey (_gax , SpeechApi = speech_api ):
357
+ client ._speech_api = _gax .GAPICSpeechAPI (client )
352
358
353
- with _Monkey (_gax , SpeechApi = _MockGAPICSpeechAPI ):
354
- self .assertIsNone (client ._speech_api )
355
- self .assertIsInstance (client .speech_api , GAPICSpeechAPI )
359
+ self .assertIsInstance (client .speech_api , GAPICSpeechAPI )
356
360
357
361
def test_speech_api_without_gax (self ):
358
362
from google .cloud .connection import Connection
0 commit comments