Skip to content

Commit b66d2de

Browse files
authored
Merge pull request #2710 from dhermes/pep8-names-in-tests
Use PEP8 names in test helper methods
2 parents 0741688 + 43a6b5b commit b66d2de

File tree

6 files changed

+91
-85
lines changed

6 files changed

+91
-85
lines changed

packages/google-cloud-speech/unit_tests/test__gax.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
class TestGAPICSpeechAPI(unittest.TestCase):
1919
SAMPLE_RATE = 16000
2020

21-
def _getTargetClass(self):
21+
@staticmethod
22+
def _get_target_class():
2223
from google.cloud.speech._gax import GAPICSpeechAPI
2324

2425
return GAPICSpeechAPI
2526

26-
def _makeOne(self, *args, **kw):
27-
return self._getTargetClass()(*args, **kw)
27+
def _make_one(self, *args, **kw):
28+
return self._get_target_class()(*args, **kw)
2829

2930
def test_use_bytes_instead_of_file_like_object(self):
3031
from google.cloud import speech
@@ -38,7 +39,7 @@ def test_use_bytes_instead_of_file_like_object(self):
3839
sample = Sample(content=b'', encoding=speech.Encoding.FLAC,
3940
sample_rate=self.SAMPLE_RATE)
4041

41-
api = self._makeOne(client)
42+
api = self._make_one(client)
4243
with self.assertRaises(ValueError):
4344
api.streaming_recognize(sample)
4445
self.assertEqual(client.connection._requested, [])
@@ -49,9 +50,9 @@ class TestSpeechGAXMakeRequests(unittest.TestCase):
4950
HINTS = ['hi']
5051
AUDIO_CONTENT = b'/9j/4QNURXhpZgAASUkq'
5152

52-
def _callFUT(self, sample, language_code, max_alternatives,
53-
profanity_filter, speech_context, single_utterance,
54-
interim_results):
53+
def _call_fut(self, sample, language_code, max_alternatives,
54+
profanity_filter, speech_context, single_utterance,
55+
interim_results):
5556
from google.cloud.speech._gax import _make_streaming_request
5657
return _make_streaming_request(sample=sample,
5758
language_code=language_code,
@@ -83,10 +84,10 @@ def test_ctor(self):
8384
single_utterance = True
8485
interim_results = False
8586

86-
streaming_request = self._callFUT(sample, language_code,
87-
max_alternatives, profanity_filter,
88-
speech_context, single_utterance,
89-
interim_results)
87+
streaming_request = self._call_fut(sample, language_code,
88+
max_alternatives, profanity_filter,
89+
speech_context, single_utterance,
90+
interim_results)
9091
self.assertIsInstance(streaming_request, StreamingRecognizeRequest)
9192

9293
# This isn't set by _make_streaming_request().
@@ -114,9 +115,9 @@ class TestSpeechGAXMakeRequestsStream(unittest.TestCase):
114115
HINTS = ['hi']
115116
AUDIO_CONTENT = b'/9j/4QNURXhpZgAASUkq'
116117

117-
def _callFUT(self, sample, language_code, max_alternatives,
118-
profanity_filter, speech_context, single_utterance,
119-
interim_results):
118+
def _call_fut(self, sample, language_code, max_alternatives,
119+
profanity_filter, speech_context, single_utterance,
120+
interim_results):
120121
from google.cloud.speech._gax import _stream_requests
121122
return _stream_requests(sample=sample,
122123
language_code=language_code,
@@ -144,10 +145,10 @@ def test_stream_requests(self):
144145
speech_context = self.HINTS
145146
single_utterance = True
146147
interim_results = False
147-
streaming_requests = self._callFUT(sample, language_code,
148-
max_alternatives, profanity_filter,
149-
speech_context, single_utterance,
150-
interim_results)
148+
streaming_requests = self._call_fut(sample, language_code,
149+
max_alternatives, profanity_filter,
150+
speech_context, single_utterance,
151+
interim_results)
151152
all_requests = []
152153
for streaming_request in streaming_requests:
153154
self.assertIsInstance(streaming_request, StreamingRecognizeRequest)

packages/google-cloud-speech/unit_tests/test_alternative.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,37 @@
1717

1818
class TestAlternative(unittest.TestCase):
1919

20-
def _getTargetClass(self):
20+
@staticmethod
21+
def _get_target_class():
2122
from google.cloud.speech.alternative import Alternative
2223
return Alternative
2324

24-
def _makeOne(self, *args, **kwargs):
25-
return self._getTargetClass()(*args, **kwargs)
25+
def _make_one(self, *args, **kwargs):
26+
return self._get_target_class()(*args, **kwargs)
2627

2728
def test_constructor(self):
2829
text = 'hello goodbye upstairs'
2930
confidence = 0.5546875
30-
alternative = self._makeOne(text, confidence)
31+
alternative = self._make_one(text, confidence)
3132
self.assertEqual(alternative._transcript, text)
3233
self.assertEqual(alternative._confidence, confidence)
3334

3435
def test_transcript_property(self):
3536
text = 'is this thing on?'
36-
alternative = self._makeOne(text, None)
37+
alternative = self._make_one(text, None)
3738
self.assertEqual(alternative.transcript, text)
3839

3940
def test_confidence_property(self):
4041
confidence = 0.412109375
41-
alternative = self._makeOne(None, confidence)
42+
alternative = self._make_one(None, confidence)
4243
self.assertEqual(alternative.confidence, confidence)
4344

4445
def test_from_api_repr_with_no_confidence(self):
4546
data = {
4647
'transcript': 'testing 1 2 3',
4748
}
4849

49-
klass = self._getTargetClass()
50+
klass = self._get_target_class()
5051
alternative = klass.from_api_repr(data)
5152
self.assertEqual(alternative.transcript, data['transcript'])
5253
self.assertIsNone(alternative.confidence)
@@ -59,7 +60,7 @@ def test_from_pb_with_no_confidence(self):
5960
transcript=text)
6061
self.assertEqual(pb_value.confidence, 0.0)
6162

62-
klass = self._getTargetClass()
63+
klass = self._get_target_class()
6364
alternative = klass.from_pb(pb_value)
6465
self.assertEqual(alternative.transcript, text)
6566
self.assertIsNone(alternative.confidence)

packages/google-cloud-speech/unit_tests/test_client.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,37 @@ class TestClient(unittest.TestCase):
6666
AUDIO_SOURCE_URI = 'gs://sample-bucket/sample-recording.flac'
6767
AUDIO_CONTENT = '/9j/4QNURXhpZgAASUkq'
6868

69-
def _getTargetClass(self):
69+
@staticmethod
70+
def _get_target_class():
7071
from google.cloud.speech.client import Client
7172

7273
return Client
7374

74-
def _makeOne(self, *args, **kw):
75-
return self._getTargetClass()(*args, **kw)
75+
def _make_one(self, *args, **kw):
76+
return self._get_target_class()(*args, **kw)
7677

7778
def test_ctor(self):
7879
from google.cloud.speech.connection import Connection
7980

8081
creds = _Credentials()
8182
http = object()
82-
client = self._makeOne(credentials=creds, http=http)
83+
client = self._make_one(credentials=creds, http=http)
8384
self.assertIsInstance(client.connection, Connection)
8485
self.assertTrue(client.connection.credentials is creds)
8586
self.assertTrue(client.connection.http is http)
8687

8788
def test_ctor_use_gax_preset(self):
8889
creds = _Credentials()
8990
http = object()
90-
client = self._makeOne(credentials=creds, http=http, use_gax=True)
91+
client = self._make_one(credentials=creds, http=http, use_gax=True)
9192
self.assertTrue(client._use_gax)
9293

9394
def test_create_sample_from_client(self):
9495
from google.cloud import speech
9596
from google.cloud.speech.sample import Sample
9697

9798
credentials = _Credentials()
98-
client = self._makeOne(credentials=credentials)
99+
client = self._make_one(credentials=credentials)
99100

100101
sample = client.sample(source_uri=self.AUDIO_SOURCE_URI,
101102
encoding=speech.Encoding.FLAC,
@@ -144,7 +145,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
144145
}
145146
}
146147
credentials = _Credentials()
147-
client = self._makeOne(credentials=credentials, use_gax=False)
148+
client = self._make_one(credentials=credentials, use_gax=False)
148149
client.connection = _Connection(RETURNED)
149150

150151
encoding = speech.Encoding.FLAC
@@ -189,7 +190,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
189190
}
190191
}
191192
credentials = _Credentials()
192-
client = self._makeOne(credentials=credentials, use_gax=False)
193+
client = self._make_one(credentials=credentials, use_gax=False)
193194
client.connection = _Connection(RETURNED)
194195

195196
encoding = speech.Encoding.FLAC
@@ -219,7 +220,7 @@ def test_sync_recognize_with_empty_results_no_gax(self):
219220
from unit_tests._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE
220221

221222
credentials = _Credentials()
222-
client = self._makeOne(credentials=credentials, use_gax=False)
223+
client = self._make_one(credentials=credentials, use_gax=False)
223224
client.connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)
224225

225226
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
@@ -237,7 +238,7 @@ def test_sync_recognize_with_empty_results_gax(self):
237238
from google.cloud.speech.sample import Sample
238239

239240
credentials = _Credentials()
240-
client = self._makeOne(credentials=credentials, use_gax=True)
241+
client = self._make_one(credentials=credentials, use_gax=True)
241242
client.connection = _Connection()
242243
client.connection.credentials = credentials
243244

@@ -280,7 +281,7 @@ def test_sync_recognize_with_gax(self):
280281
from google.cloud.speech import _gax
281282

282283
creds = _Credentials()
283-
client = self._makeOne(credentials=creds, use_gax=True)
284+
client = self._make_one(credentials=creds, use_gax=True)
284285
client.connection = _Connection()
285286
client.connection.credentials = creds
286287
client._speech_api = None
@@ -341,7 +342,7 @@ def test_async_supported_encodings(self):
341342
from google.cloud.speech.sample import Sample
342343

343344
credentials = _Credentials()
344-
client = self._makeOne(credentials=credentials)
345+
client = self._make_one(credentials=credentials)
345346
client.connection = _Connection({})
346347

347348
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
@@ -359,7 +360,7 @@ def test_async_recognize_no_gax(self):
359360
RETURNED = ASYNC_RECOGNIZE_RESPONSE
360361

361362
credentials = _Credentials()
362-
client = self._makeOne(credentials=credentials, use_gax=False)
363+
client = self._make_one(credentials=credentials, use_gax=False)
363364
client.connection = _Connection(RETURNED)
364365

365366
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
@@ -381,8 +382,8 @@ def test_async_recognize_with_gax(self):
381382
from google.cloud.speech.operation import Operation
382383

383384
credentials = _Credentials()
384-
client = self._makeOne(credentials=credentials,
385-
use_gax=True)
385+
client = self._make_one(credentials=credentials,
386+
use_gax=True)
386387
client.connection = _Connection()
387388
client.connection.credentials = credentials
388389

@@ -423,7 +424,7 @@ def test_streaming_depends_on_gax(self):
423424
from google.cloud._testing import _Monkey
424425

425426
credentials = _Credentials()
426-
client = self._makeOne(credentials=credentials, use_gax=False)
427+
client = self._make_one(credentials=credentials, use_gax=False)
427428
client.connection = _Connection()
428429

429430
with self.assertRaises(EnvironmentError):
@@ -439,7 +440,7 @@ def test_streaming_closed_stream(self):
439440

440441
stream = BytesIO(b'Some audio data...')
441442
credentials = _Credentials()
442-
client = self._makeOne(credentials=credentials)
443+
client = self._make_one(credentials=credentials)
443444
client.connection = _Connection()
444445
client.connection.credentials = credentials
445446

@@ -479,7 +480,7 @@ def test_stream_recognize_interim_results(self):
479480

480481
stream = BytesIO(b'Some audio data...')
481482
credentials = _Credentials()
482-
client = self._makeOne(credentials=credentials)
483+
client = self._make_one(credentials=credentials)
483484
client.connection = _Connection()
484485
client.connection.credentials = credentials
485486

@@ -541,7 +542,7 @@ def test_stream_recognize(self):
541542

542543
stream = BytesIO(b'Some audio data...')
543544
credentials = _Credentials()
544-
client = self._makeOne(credentials=credentials)
545+
client = self._make_one(credentials=credentials)
545546
client.connection = _Connection()
546547
client.connection.credentials = credentials
547548

@@ -597,7 +598,7 @@ def test_stream_recognize_no_results(self):
597598

598599
stream = BytesIO(b'Some audio data...')
599600
credentials = _Credentials()
600-
client = self._makeOne(credentials=credentials)
601+
client = self._make_one(credentials=credentials)
601602
client.connection = _Connection()
602603
client.connection.credentials = credentials
603604

@@ -633,7 +634,7 @@ def test_speech_api_with_gax(self):
633634
from google.cloud.speech import _gax
634635

635636
creds = _Credentials()
636-
client = self._makeOne(credentials=creds, use_gax=True)
637+
client = self._make_one(credentials=creds, use_gax=True)
637638
client.connection = _Connection()
638639
client.connection.credentials = creds
639640

@@ -666,14 +667,14 @@ def test_speech_api_without_gax(self):
666667
from google.cloud.speech.client import _JSONSpeechAPI
667668

668669
creds = _Credentials()
669-
client = self._makeOne(credentials=creds, use_gax=False)
670+
client = self._make_one(credentials=creds, use_gax=False)
670671
self.assertIsNone(client._speech_api)
671672
self.assertIsInstance(client.speech_api, _JSONSpeechAPI)
672673
self.assertIsInstance(client.speech_api.connection, Connection)
673674

674675
def test_speech_api_preset(self):
675676
creds = _Credentials()
676-
client = self._makeOne(credentials=creds)
677+
client = self._make_one(credentials=creds)
677678
fake_api = object()
678679
client._speech_api = fake_api
679680

packages/google-cloud-speech/unit_tests/test_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818
class TestConnection(unittest.TestCase):
1919

20-
def _getTargetClass(self):
20+
@staticmethod
21+
def _get_target_class():
2122
from google.cloud.speech.connection import Connection
2223
return Connection
2324

24-
def _makeOne(self, *args, **kw):
25-
return self._getTargetClass()(*args, **kw)
25+
def _make_one(self, *args, **kw):
26+
return self._get_target_class()(*args, **kw)
2627

2728
def test_build_api_url(self):
28-
conn = self._makeOne()
29+
conn = self._make_one()
2930
method = 'speech:syncrecognize'
3031
uri = '/'.join([
3132
conn.API_BASE_URL,

packages/google-cloud-speech/unit_tests/test_operation.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ class TestOperation(unittest.TestCase):
1919

2020
OPERATION_NAME = '123456789'
2121

22-
def _getTargetClass(self):
22+
@staticmethod
23+
def _get_target_class():
2324
from google.cloud.speech.operation import Operation
2425
return Operation
2526

26-
def _makeOne(self, *args, **kwargs):
27-
return self._getTargetClass()(*args, **kwargs)
27+
def _make_one(self, *args, **kwargs):
28+
return self._get_target_class()(*args, **kwargs)
2829

2930
def test_constructor(self):
3031
client = object()
31-
operation = self._makeOne(
32+
operation = self._make_one(
3233
self.OPERATION_NAME, client)
3334
self.assertEqual(operation.name, self.OPERATION_NAME)
3435
self.assertIs(operation.client, client)
@@ -74,7 +75,7 @@ def _make_operation_pb(self, *results):
7475

7576
def test__update_state_no_response(self):
7677
client = object()
77-
operation = self._makeOne(
78+
operation = self._make_one(
7879
self.OPERATION_NAME, client)
7980

8081
operation_pb = self._make_operation_pb()
@@ -86,7 +87,7 @@ def test__update_state_with_response(self):
8687
from google.cloud.speech.alternative import Alternative
8788

8889
client = object()
89-
operation = self._makeOne(
90+
operation = self._make_one(
9091
self.OPERATION_NAME, client)
9192

9293
text = 'hi mom'
@@ -104,7 +105,7 @@ def test__update_state_with_response(self):
104105

105106
def test__update_state_bad_response(self):
106107
client = object()
107-
operation = self._makeOne(
108+
operation = self._make_one(
108109
self.OPERATION_NAME, client)
109110

110111
result1 = self._make_result('is this ok?', 0.625)

0 commit comments

Comments
 (0)