@@ -85,14 +85,11 @@ def _make_one(self, *args, **kw):
85
85
return self ._get_target_class ()(* args , ** kw )
86
86
87
87
def test_ctor (self ):
88
- from google .cloud .speech ._http import Connection
89
-
90
88
creds = _make_credentials ()
91
89
http = object ()
92
90
client = self ._make_one (credentials = creds , http = http )
93
- self .assertIsInstance (client ._connection , Connection )
94
- self .assertTrue (client ._connection .credentials is creds )
95
- self .assertTrue (client ._connection .http is http )
91
+ self .assertTrue (client ._credentials is creds )
92
+ self .assertTrue (client ._http is http )
96
93
97
94
def test_ctor_use_gax_preset (self ):
98
95
creds = _make_credentials ()
@@ -153,7 +150,9 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
153
150
}
154
151
credentials = _make_credentials ()
155
152
client = self ._make_one (credentials = credentials , use_gax = False )
156
- client ._connection = _Connection (RETURNED )
153
+ speech_api = client .speech_api
154
+ connection = _Connection (RETURNED )
155
+ speech_api ._connection = connection
157
156
158
157
encoding = speech .Encoding .FLAC
159
158
@@ -165,8 +164,8 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
165
164
profanity_filter = True ,
166
165
speech_context = self .HINTS )
167
166
168
- self .assertEqual (len (client . _connection ._requested ), 1 )
169
- req = client . _connection ._requested [0 ]
167
+ self .assertEqual (len (connection ._requested ), 1 )
168
+ req = connection ._requested [0 ]
170
169
self .assertEqual (len (req ), 3 )
171
170
self .assertEqual (req ['data' ], REQUEST )
172
171
self .assertEqual (req ['method' ], 'POST' )
@@ -199,7 +198,9 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
199
198
}
200
199
credentials = _make_credentials ()
201
200
client = self ._make_one (credentials = credentials , use_gax = False )
202
- client ._connection = _Connection (RETURNED )
201
+ speech_api = client .speech_api
202
+ connection = _Connection (RETURNED )
203
+ speech_api ._connection = connection
203
204
204
205
encoding = speech .Encoding .FLAC
205
206
@@ -208,8 +209,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
208
209
209
210
response = [i for i in sample .sync_recognize ()]
210
211
211
- self .assertEqual (len (client . _connection ._requested ), 1 )
212
- req = client . _connection ._requested [0 ]
212
+ self .assertEqual (len (connection ._requested ), 1 )
213
+ req = connection ._requested [0 ]
213
214
self .assertEqual (len (req ), 3 )
214
215
self .assertEqual (req ['data' ], REQUEST )
215
216
self .assertEqual (req ['method' ], 'POST' )
@@ -231,7 +232,8 @@ def test_sync_recognize_with_empty_results_no_gax(self):
231
232
232
233
credentials = _make_credentials ()
233
234
client = self ._make_one (credentials = credentials , use_gax = False )
234
- client ._connection = _Connection (SYNC_RECOGNIZE_EMPTY_RESPONSE )
235
+ speech_api = client .speech_api
236
+ speech_api ._connection = _Connection (SYNC_RECOGNIZE_EMPTY_RESPONSE )
235
237
236
238
sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
237
239
encoding = speech .Encoding .FLAC ,
@@ -248,8 +250,7 @@ def test_sync_recognize_with_empty_results_gax(self):
248
250
249
251
credentials = _make_credentials ()
250
252
client = self ._make_one (credentials = credentials , use_gax = True )
251
- client ._connection = _Connection ()
252
- client ._connection .credentials = credentials
253
+ client ._credentials = credentials
253
254
254
255
channel_args = []
255
256
channel_obj = object ()
@@ -291,9 +292,7 @@ def test_sync_recognize_with_gax(self):
291
292
292
293
creds = _make_credentials ()
293
294
client = self ._make_one (credentials = creds , use_gax = True )
294
- client ._connection = _Connection ()
295
- client ._connection .credentials = creds
296
- client ._speech_api = None
295
+ client ._credentials = creds
297
296
298
297
alternatives = [{
299
298
'transcript' : 'testing 1 2 3' ,
@@ -352,8 +351,7 @@ def test_async_supported_encodings(self):
352
351
from google .cloud import speech
353
352
354
353
credentials = _make_credentials ()
355
- client = self ._make_one (credentials = credentials )
356
- client ._connection = _Connection ({})
354
+ client = self ._make_one (credentials = credentials , use_gax = True )
357
355
358
356
sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
359
357
encoding = speech .Encoding .FLAC ,
@@ -370,7 +368,8 @@ def test_async_recognize_no_gax(self):
370
368
371
369
credentials = _make_credentials ()
372
370
client = self ._make_one (credentials = credentials , use_gax = False )
373
- client ._connection = _Connection (RETURNED )
371
+ speech_api = client .speech_api
372
+ speech_api ._connection = _Connection (RETURNED )
374
373
375
374
sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
376
375
encoding = speech .Encoding .LINEAR16 ,
@@ -393,8 +392,7 @@ def test_async_recognize_with_gax(self):
393
392
credentials = _make_credentials ()
394
393
client = self ._make_one (credentials = credentials ,
395
394
use_gax = True )
396
- client ._connection = _Connection ()
397
- client ._connection .credentials = credentials
395
+ client ._credentials = credentials
398
396
399
397
channel_args = []
400
398
channel_obj = object ()
@@ -434,7 +432,6 @@ def test_streaming_depends_on_gax(self):
434
432
435
433
credentials = _make_credentials ()
436
434
client = self ._make_one (credentials = credentials , use_gax = False )
437
- client .connection = _Connection ()
438
435
sample = client .sample (content = self .AUDIO_CONTENT ,
439
436
encoding = speech .Encoding .LINEAR16 ,
440
437
sample_rate = self .SAMPLE_RATE )
@@ -453,8 +450,7 @@ def test_streaming_closed_stream(self):
453
450
stream = BytesIO (b'Some audio data...' )
454
451
credentials = _make_credentials ()
455
452
client = self ._make_one (credentials = credentials )
456
- client .connection = _Connection ()
457
- client .connection .credentials = credentials
453
+ client ._credentials = credentials
458
454
459
455
channel_args = []
460
456
channel_obj = object ()
@@ -495,8 +491,7 @@ def test_stream_recognize_interim_results(self):
495
491
stream = BytesIO (b'Some audio data...' )
496
492
credentials = _make_credentials ()
497
493
client = self ._make_one (credentials = credentials )
498
- client .connection = _Connection ()
499
- client .connection .credentials = credentials
494
+ client ._credentials = credentials
500
495
501
496
alternatives = [{
502
497
'transcript' : 'testing streaming 1 2 3' ,
@@ -576,8 +571,7 @@ def test_stream_recognize(self):
576
571
stream = BytesIO (b'Some audio data...' )
577
572
credentials = _make_credentials ()
578
573
client = self ._make_one (credentials = credentials )
579
- client .connection = _Connection ()
580
- client .connection .credentials = credentials
574
+ client ._credentials = credentials
581
575
582
576
alternatives = [{
583
577
'transcript' : 'testing streaming 1 2 3' ,
@@ -633,8 +627,7 @@ def test_stream_recognize_no_results(self):
633
627
stream = BytesIO (b'Some audio data...' )
634
628
credentials = _make_credentials ()
635
629
client = self ._make_one (credentials = credentials )
636
- client .connection = _Connection ()
637
- client .connection .credentials = credentials
630
+ client ._credentials = credentials
638
631
639
632
responses = [_make_streaming_response ()]
640
633
@@ -670,8 +663,7 @@ def test_speech_api_with_gax(self):
670
663
671
664
creds = _make_credentials ()
672
665
client = self ._make_one (credentials = creds , use_gax = True )
673
- client ._connection = _Connection ()
674
- client ._connection .credentials = creds
666
+ client ._credentials = creds
675
667
676
668
channel_args = []
677
669
channel_obj = object ()
0 commit comments