GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Speech unit tests cleanup. by daspecster · Pull Request #2676 · googleapis/google-cloud-python

Speech unit tests cleanup. #2676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
dhermes merged 1 commit into googleapis:master from daspecster:update-speech-unit-tests
Nov 4, 2016

Uh oh!

There was an error while loading. Please reload this page.

Merged

Speech unit tests cleanup. #2676

Changes from all commits
Commits
Show all changes
1 commit
Select commit
3186072
Speech unit tests cleanup.
daspecster Nov 3, 2016
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

54 changes: 29 additions & 25 deletions 54 speech/unit_tests/test_client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):

from google.cloud._helpers import _bytes_to_unicode
from google.cloud._helpers import _to_bytes
from google.cloud._testing import _Monkey

from google.cloud import speech
from google.cloud.speech import client as MUT
from google.cloud.speech.alternative import Alternative
from google.cloud.speech.sample import Sample
from unit_tests._fixtures import SYNC_RECOGNIZE_RESPONSE
Expand Down Expand Up @@ -130,12 +128,12 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):

sample = Sample(content=self.AUDIO_CONTENT, encoding=encoding,
sample_rate=self.SAMPLE_RATE)
with _Monkey(MUT, _USE_GAX=False):
response = client.sync_recognize(sample,
language_code='EN',
max_alternatives=2,
profanity_filter=True,
speech_context=self.HINTS)

response = client.sync_recognize(sample,
language_code='EN',
max_alternatives=2,
profanity_filter=True,
speech_context=self.HINTS)

self.assertEqual(len(client.connection._requested), 1)
req = client.connection._requested[0]
Expand All @@ -152,10 +150,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
self.assertEqual(response[0].confidence, expected.confidence)

def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
from google.cloud._testing import _Monkey

from google.cloud import speech
from google.cloud.speech import client as MUT
from google.cloud.speech.alternative import Alternative
from google.cloud.speech.sample import Sample
from unit_tests._fixtures import SYNC_RECOGNIZE_RESPONSE
Expand All @@ -178,8 +173,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):

sample = Sample(source_uri=self.AUDIO_SOURCE_URI, encoding=encoding,
sample_rate=self.SAMPLE_RATE)
with _Monkey(MUT, _USE_GAX=False):
response = client.sync_recognize(sample)

response = client.sync_recognize(sample)

self.assertEqual(len(client.connection._requested), 1)
req = client.connection._requested[0]
Expand All @@ -196,23 +191,20 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
self.assertEqual(response[0].confidence, expected.confidence)

def test_sync_recognize_with_empty_results_no_gax(self):
from google.cloud._testing import _Monkey

from google.cloud import speech
from google.cloud.speech import client as MUT
from google.cloud.speech.sample import Sample
from unit_tests._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE

credentials = _Credentials()
client = self._makeOne(credentials=credentials, use_gax=False)
client.connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)

sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
encoding=speech.Encoding.FLAC,
sample_rate=self.SAMPLE_RATE)

with self.assertRaises(ValueError):
with _Monkey(MUT, _USE_GAX=False):
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
encoding=speech.Encoding.FLAC,
sample_rate=self.SAMPLE_RATE)
client.sync_recognize(sample)
client.sync_recognize(sample)

def test_sync_recognize_with_empty_results_gax(self):
from google.cloud._testing import _Monkey
Expand Down Expand Up @@ -334,7 +326,11 @@ def test_async_recognize_with_gax(self):
sample = client.sample(source_uri=self.AUDIO_SOURCE_URI,
encoding=speech.Encoding.LINEAR16,
sample_rate=self.SAMPLE_RATE)
with _Monkey(_gax, SpeechApi=_MockGAPICSpeechAPI):

def speech_api():
return _MockGAPICSpeechAPI()

with _Monkey(_gax, SpeechApi=speech_api):
operation = client.async_recognize(sample)

self.assertIsInstance(operation, Operation)
Expand All @@ -349,10 +345,18 @@ def test_speech_api_with_gax(self):

creds = _Credentials()
client = self._makeOne(credentials=creds, use_gax=True)
client.connection = _Connection()
client.connection.credentials = creds

def speech_api():
return _MockGAPICSpeechAPI()

self.assertIsNone(client._speech_api)

with _Monkey(_gax, SpeechApi=speech_api):
client._speech_api = _gax.GAPICSpeechAPI(client)

with _Monkey(_gax, SpeechApi=_MockGAPICSpeechAPI):
self.assertIsNone(client._speech_api)
self.assertIsInstance(client.speech_api, GAPICSpeechAPI)
self.assertIsInstance(client.speech_api, GAPICSpeechAPI)

def test_speech_api_without_gax(self):
from google.cloud.connection import Connection
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.