diff --git a/packages/google-cloud-speech/unit_tests/test__gax.py b/packages/google-cloud-speech/unit_tests/test__gax.py index 2b208cbf553a..4fed73c629b0 100644 --- a/packages/google-cloud-speech/unit_tests/test__gax.py +++ b/packages/google-cloud-speech/unit_tests/test__gax.py @@ -18,13 +18,14 @@ class TestGAPICSpeechAPI(unittest.TestCase): SAMPLE_RATE = 16000 - def _getTargetClass(self): + @staticmethod + def _get_target_class(): from google.cloud.speech._gax import GAPICSpeechAPI return GAPICSpeechAPI - def _makeOne(self, *args, **kw): - return self._getTargetClass()(*args, **kw) + def _make_one(self, *args, **kw): + return self._get_target_class()(*args, **kw) def test_use_bytes_instead_of_file_like_object(self): from google.cloud import speech @@ -38,7 +39,7 @@ def test_use_bytes_instead_of_file_like_object(self): sample = Sample(content=b'', encoding=speech.Encoding.FLAC, sample_rate=self.SAMPLE_RATE) - api = self._makeOne(client) + api = self._make_one(client) with self.assertRaises(ValueError): api.streaming_recognize(sample) self.assertEqual(client.connection._requested, []) @@ -49,9 +50,9 @@ class TestSpeechGAXMakeRequests(unittest.TestCase): HINTS = ['hi'] AUDIO_CONTENT = b'/9j/4QNURXhpZgAASUkq' - def _callFUT(self, sample, language_code, max_alternatives, - profanity_filter, speech_context, single_utterance, - interim_results): + def _call_fut(self, sample, language_code, max_alternatives, + profanity_filter, speech_context, single_utterance, + interim_results): from google.cloud.speech._gax import _make_streaming_request return _make_streaming_request(sample=sample, language_code=language_code, @@ -83,10 +84,10 @@ def test_ctor(self): single_utterance = True interim_results = False - streaming_request = self._callFUT(sample, language_code, - max_alternatives, profanity_filter, - speech_context, single_utterance, - interim_results) + streaming_request = self._call_fut(sample, language_code, + max_alternatives, profanity_filter, + speech_context, single_utterance, + interim_results) self.assertIsInstance(streaming_request, StreamingRecognizeRequest) # This isn't set by _make_streaming_request(). @@ -114,9 +115,9 @@ class TestSpeechGAXMakeRequestsStream(unittest.TestCase): HINTS = ['hi'] AUDIO_CONTENT = b'/9j/4QNURXhpZgAASUkq' - def _callFUT(self, sample, language_code, max_alternatives, - profanity_filter, speech_context, single_utterance, - interim_results): + def _call_fut(self, sample, language_code, max_alternatives, + profanity_filter, speech_context, single_utterance, + interim_results): from google.cloud.speech._gax import _stream_requests return _stream_requests(sample=sample, language_code=language_code, @@ -144,10 +145,10 @@ def test_stream_requests(self): speech_context = self.HINTS single_utterance = True interim_results = False - streaming_requests = self._callFUT(sample, language_code, - max_alternatives, profanity_filter, - speech_context, single_utterance, - interim_results) + streaming_requests = self._call_fut(sample, language_code, + max_alternatives, profanity_filter, + speech_context, single_utterance, + interim_results) all_requests = [] for streaming_request in streaming_requests: self.assertIsInstance(streaming_request, StreamingRecognizeRequest) diff --git a/packages/google-cloud-speech/unit_tests/test_alternative.py b/packages/google-cloud-speech/unit_tests/test_alternative.py index ac6d9f56fcfb..c6a8ada6bb8b 100644 --- a/packages/google-cloud-speech/unit_tests/test_alternative.py +++ b/packages/google-cloud-speech/unit_tests/test_alternative.py @@ -17,28 +17,29 @@ class TestAlternative(unittest.TestCase): - def _getTargetClass(self): + @staticmethod + def _get_target_class(): from google.cloud.speech.alternative import Alternative return Alternative - def _makeOne(self, *args, **kwargs): - return self._getTargetClass()(*args, **kwargs) + def _make_one(self, *args, **kwargs): + return self._get_target_class()(*args, **kwargs) def test_constructor(self): text = 'hello goodbye upstairs' confidence = 0.5546875 - alternative = self._makeOne(text, confidence) + alternative = self._make_one(text, confidence) self.assertEqual(alternative._transcript, text) self.assertEqual(alternative._confidence, confidence) def test_transcript_property(self): text = 'is this thing on?' - alternative = self._makeOne(text, None) + alternative = self._make_one(text, None) self.assertEqual(alternative.transcript, text) def test_confidence_property(self): confidence = 0.412109375 - alternative = self._makeOne(None, confidence) + alternative = self._make_one(None, confidence) self.assertEqual(alternative.confidence, confidence) def test_from_api_repr_with_no_confidence(self): @@ -46,7 +47,7 @@ def test_from_api_repr_with_no_confidence(self): 'transcript': 'testing 1 2 3', } - klass = self._getTargetClass() + klass = self._get_target_class() alternative = klass.from_api_repr(data) self.assertEqual(alternative.transcript, data['transcript']) self.assertIsNone(alternative.confidence) @@ -59,7 +60,7 @@ def test_from_pb_with_no_confidence(self): transcript=text) self.assertEqual(pb_value.confidence, 0.0) - klass = self._getTargetClass() + klass = self._get_target_class() alternative = klass.from_pb(pb_value) self.assertEqual(alternative.transcript, text) self.assertIsNone(alternative.confidence) diff --git a/packages/google-cloud-speech/unit_tests/test_client.py b/packages/google-cloud-speech/unit_tests/test_client.py index b108fcaab579..8291540e0e4f 100644 --- a/packages/google-cloud-speech/unit_tests/test_client.py +++ b/packages/google-cloud-speech/unit_tests/test_client.py @@ -66,20 +66,21 @@ class TestClient(unittest.TestCase): AUDIO_SOURCE_URI = 'gs://sample-bucket/sample-recording.flac' AUDIO_CONTENT = '/9j/4QNURXhpZgAASUkq' - def _getTargetClass(self): + @staticmethod + def _get_target_class(): from google.cloud.speech.client import Client return Client - def _makeOne(self, *args, **kw): - return self._getTargetClass()(*args, **kw) + def _make_one(self, *args, **kw): + return self._get_target_class()(*args, **kw) def test_ctor(self): from google.cloud.speech.connection import Connection creds = _Credentials() http = object() - client = self._makeOne(credentials=creds, http=http) + client = self._make_one(credentials=creds, http=http) self.assertIsInstance(client.connection, Connection) self.assertTrue(client.connection.credentials is creds) self.assertTrue(client.connection.http is http) @@ -87,7 +88,7 @@ def test_ctor(self): def test_ctor_use_gax_preset(self): creds = _Credentials() http = object() - client = self._makeOne(credentials=creds, http=http, use_gax=True) + client = self._make_one(credentials=creds, http=http, use_gax=True) self.assertTrue(client._use_gax) def test_create_sample_from_client(self): @@ -95,7 +96,7 @@ def test_create_sample_from_client(self): from google.cloud.speech.sample import Sample credentials = _Credentials() - client = self._makeOne(credentials=credentials) + client = self._make_one(credentials=credentials) sample = client.sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.FLAC, @@ -144,7 +145,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self): } } credentials = _Credentials() - client = self._makeOne(credentials=credentials, use_gax=False) + client = self._make_one(credentials=credentials, use_gax=False) client.connection = _Connection(RETURNED) encoding = speech.Encoding.FLAC @@ -189,7 +190,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self): } } credentials = _Credentials() - client = self._makeOne(credentials=credentials, use_gax=False) + client = self._make_one(credentials=credentials, use_gax=False) client.connection = _Connection(RETURNED) encoding = speech.Encoding.FLAC @@ -219,7 +220,7 @@ def test_sync_recognize_with_empty_results_no_gax(self): from unit_tests._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE credentials = _Credentials() - client = self._makeOne(credentials=credentials, use_gax=False) + client = self._make_one(credentials=credentials, use_gax=False) client.connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE) sample = Sample(source_uri=self.AUDIO_SOURCE_URI, @@ -237,7 +238,7 @@ def test_sync_recognize_with_empty_results_gax(self): from google.cloud.speech.sample import Sample credentials = _Credentials() - client = self._makeOne(credentials=credentials, use_gax=True) + client = self._make_one(credentials=credentials, use_gax=True) client.connection = _Connection() client.connection.credentials = credentials @@ -280,7 +281,7 @@ def test_sync_recognize_with_gax(self): from google.cloud.speech import _gax creds = _Credentials() - client = self._makeOne(credentials=creds, use_gax=True) + client = self._make_one(credentials=creds, use_gax=True) client.connection = _Connection() client.connection.credentials = creds client._speech_api = None @@ -341,7 +342,7 @@ def test_async_supported_encodings(self): from google.cloud.speech.sample import Sample credentials = _Credentials() - client = self._makeOne(credentials=credentials) + client = self._make_one(credentials=credentials) client.connection = _Connection({}) sample = Sample(source_uri=self.AUDIO_SOURCE_URI, @@ -359,7 +360,7 @@ def test_async_recognize_no_gax(self): RETURNED = ASYNC_RECOGNIZE_RESPONSE credentials = _Credentials() - client = self._makeOne(credentials=credentials, use_gax=False) + client = self._make_one(credentials=credentials, use_gax=False) client.connection = _Connection(RETURNED) sample = Sample(source_uri=self.AUDIO_SOURCE_URI, @@ -381,8 +382,8 @@ def test_async_recognize_with_gax(self): from google.cloud.speech.operation import Operation credentials = _Credentials() - client = self._makeOne(credentials=credentials, - use_gax=True) + client = self._make_one(credentials=credentials, + use_gax=True) client.connection = _Connection() client.connection.credentials = credentials @@ -423,7 +424,7 @@ def test_streaming_depends_on_gax(self): from google.cloud._testing import _Monkey credentials = _Credentials() - client = self._makeOne(credentials=credentials, use_gax=False) + client = self._make_one(credentials=credentials, use_gax=False) client.connection = _Connection() with self.assertRaises(EnvironmentError): @@ -439,7 +440,7 @@ def test_streaming_closed_stream(self): stream = BytesIO(b'Some audio data...') credentials = _Credentials() - client = self._makeOne(credentials=credentials) + client = self._make_one(credentials=credentials) client.connection = _Connection() client.connection.credentials = credentials @@ -479,7 +480,7 @@ def test_stream_recognize_interim_results(self): stream = BytesIO(b'Some audio data...') credentials = _Credentials() - client = self._makeOne(credentials=credentials) + client = self._make_one(credentials=credentials) client.connection = _Connection() client.connection.credentials = credentials @@ -541,7 +542,7 @@ def test_stream_recognize(self): stream = BytesIO(b'Some audio data...') credentials = _Credentials() - client = self._makeOne(credentials=credentials) + client = self._make_one(credentials=credentials) client.connection = _Connection() client.connection.credentials = credentials @@ -597,7 +598,7 @@ def test_stream_recognize_no_results(self): stream = BytesIO(b'Some audio data...') credentials = _Credentials() - client = self._makeOne(credentials=credentials) + client = self._make_one(credentials=credentials) client.connection = _Connection() client.connection.credentials = credentials @@ -633,7 +634,7 @@ def test_speech_api_with_gax(self): from google.cloud.speech import _gax creds = _Credentials() - client = self._makeOne(credentials=creds, use_gax=True) + client = self._make_one(credentials=creds, use_gax=True) client.connection = _Connection() client.connection.credentials = creds @@ -666,14 +667,14 @@ def test_speech_api_without_gax(self): from google.cloud.speech.client import _JSONSpeechAPI creds = _Credentials() - client = self._makeOne(credentials=creds, use_gax=False) + client = self._make_one(credentials=creds, use_gax=False) self.assertIsNone(client._speech_api) self.assertIsInstance(client.speech_api, _JSONSpeechAPI) self.assertIsInstance(client.speech_api.connection, Connection) def test_speech_api_preset(self): creds = _Credentials() - client = self._makeOne(credentials=creds) + client = self._make_one(credentials=creds) fake_api = object() client._speech_api = fake_api diff --git a/packages/google-cloud-speech/unit_tests/test_connection.py b/packages/google-cloud-speech/unit_tests/test_connection.py index 0de94cb1d7c1..48b2e8577080 100644 --- a/packages/google-cloud-speech/unit_tests/test_connection.py +++ b/packages/google-cloud-speech/unit_tests/test_connection.py @@ -17,15 +17,16 @@ class TestConnection(unittest.TestCase): - def _getTargetClass(self): + @staticmethod + def _get_target_class(): from google.cloud.speech.connection import Connection return Connection - def _makeOne(self, *args, **kw): - return self._getTargetClass()(*args, **kw) + def _make_one(self, *args, **kw): + return self._get_target_class()(*args, **kw) def test_build_api_url(self): - conn = self._makeOne() + conn = self._make_one() method = 'speech:syncrecognize' uri = '/'.join([ conn.API_BASE_URL, diff --git a/packages/google-cloud-speech/unit_tests/test_operation.py b/packages/google-cloud-speech/unit_tests/test_operation.py index dd0dbd4a1d72..d1388a15f919 100644 --- a/packages/google-cloud-speech/unit_tests/test_operation.py +++ b/packages/google-cloud-speech/unit_tests/test_operation.py @@ -19,16 +19,17 @@ class TestOperation(unittest.TestCase): OPERATION_NAME = '123456789' - def _getTargetClass(self): + @staticmethod + def _get_target_class(): from google.cloud.speech.operation import Operation return Operation - def _makeOne(self, *args, **kwargs): - return self._getTargetClass()(*args, **kwargs) + def _make_one(self, *args, **kwargs): + return self._get_target_class()(*args, **kwargs) def test_constructor(self): client = object() - operation = self._makeOne( + operation = self._make_one( self.OPERATION_NAME, client) self.assertEqual(operation.name, self.OPERATION_NAME) self.assertIs(operation.client, client) @@ -74,7 +75,7 @@ def _make_operation_pb(self, *results): def test__update_state_no_response(self): client = object() - operation = self._makeOne( + operation = self._make_one( self.OPERATION_NAME, client) operation_pb = self._make_operation_pb() @@ -86,7 +87,7 @@ def test__update_state_with_response(self): from google.cloud.speech.alternative import Alternative client = object() - operation = self._makeOne( + operation = self._make_one( self.OPERATION_NAME, client) text = 'hi mom' @@ -104,7 +105,7 @@ def test__update_state_with_response(self): def test__update_state_bad_response(self): client = object() - operation = self._makeOne( + operation = self._make_one( self.OPERATION_NAME, client) result1 = self._make_result('is this ok?', 0.625) diff --git a/packages/google-cloud-speech/unit_tests/test_sample.py b/packages/google-cloud-speech/unit_tests/test_sample.py index 54f23963ceff..15f3604dfffd 100644 --- a/packages/google-cloud-speech/unit_tests/test_sample.py +++ b/packages/google-cloud-speech/unit_tests/test_sample.py @@ -19,59 +19,60 @@ class TestSample(unittest.TestCase): SAMPLE_RATE = 16000 AUDIO_SOURCE_URI = 'gs://sample-bucket/sample-recording.flac' - def _getTargetClass(self): + @staticmethod + def _get_target_class(): from google.cloud.speech.sample import Sample return Sample - def _makeOne(self, *args, **kw): - return self._getTargetClass()(*args, **kw) + def _make_one(self, *args, **kw): + return self._get_target_class()(*args, **kw) def test_initialize_sample(self): from google.cloud.speech.encoding import Encoding - sample = self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - encoding=Encoding.FLAC, - sample_rate=self.SAMPLE_RATE) + sample = self._make_one(source_uri=self.AUDIO_SOURCE_URI, + encoding=Encoding.FLAC, + sample_rate=self.SAMPLE_RATE) self.assertEqual(sample.source_uri, self.AUDIO_SOURCE_URI) self.assertEqual(sample.encoding, Encoding.FLAC) self.assertEqual(sample.sample_rate, self.SAMPLE_RATE) def test_content_and_source_uri(self): with self.assertRaises(ValueError): - self._makeOne(content='awefawagaeragere', - source_uri=self.AUDIO_SOURCE_URI) + self._make_one(content='awefawagaeragere', + source_uri=self.AUDIO_SOURCE_URI) def test_sample_rates(self): from google.cloud.speech.encoding import Encoding with self.assertRaises(ValueError): - self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - sample_rate=7999) + self._make_one(source_uri=self.AUDIO_SOURCE_URI, + sample_rate=7999) with self.assertRaises(ValueError): - self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - sample_rate=48001) + self._make_one(source_uri=self.AUDIO_SOURCE_URI, + sample_rate=48001) - sample = self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - sample_rate=self.SAMPLE_RATE, - encoding=Encoding.FLAC) + sample = self._make_one(source_uri=self.AUDIO_SOURCE_URI, + sample_rate=self.SAMPLE_RATE, + encoding=Encoding.FLAC) self.assertEqual(sample.sample_rate, self.SAMPLE_RATE) self.assertEqual(sample.encoding, Encoding.FLAC) - sample = self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - encoding=Encoding.FLAC) + sample = self._make_one(source_uri=self.AUDIO_SOURCE_URI, + encoding=Encoding.FLAC) self.assertEqual(sample.sample_rate, self.SAMPLE_RATE) def test_encoding(self): from google.cloud.speech.encoding import Encoding with self.assertRaises(ValueError): - self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - sample_rate=self.SAMPLE_RATE, - encoding='OGG') + self._make_one(source_uri=self.AUDIO_SOURCE_URI, + sample_rate=self.SAMPLE_RATE, + encoding='OGG') with self.assertRaises(ValueError): - self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - sample_rate=self.SAMPLE_RATE) - sample = self._makeOne(source_uri=self.AUDIO_SOURCE_URI, - sample_rate=self.SAMPLE_RATE, - encoding=Encoding.FLAC) + self._make_one(source_uri=self.AUDIO_SOURCE_URI, + sample_rate=self.SAMPLE_RATE) + sample = self._make_one(source_uri=self.AUDIO_SOURCE_URI, + sample_rate=self.SAMPLE_RATE, + encoding=Encoding.FLAC) self.assertEqual(sample.encoding, Encoding.FLAC)