Skip to content
This repository was archived by the owner on Mar 20, 2018. It is now read-only.

Commit d59635e

Browse files
authored
Make _CallSettings private (#125)
This allows any future renaming/revision not to be a breaking change.
1 parent e8f6daa commit d59635e

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

google/gax/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
settings."""
4949

5050

51-
class CallSettings(object):
51+
class _CallSettings(object):
5252
"""Encapsulates the call settings for an API call."""
5353
# pylint: disable=too-few-public-methods
5454
def __init__(self, timeout=30, retry=None, page_descriptor=None,
@@ -94,10 +94,10 @@ def flatten_pages(self):
9494
return self.page_token is None
9595

9696
def merge(self, options):
97-
"""Returns a new CallSettings merged from this and a CallOptions object.
97+
"""Returns new _CallSettings merged from this and a CallOptions object.
9898
9999
Note that passing if the CallOptions instance specifies a page_token,
100-
the merged CallSettings will have ``flatten_pages`` disabled. This
100+
the merged _CallSettings will have ``flatten_pages`` disabled. This
101101
permits toggling per-resource/per-page page streaming.
102102
103103
Args:
@@ -106,10 +106,10 @@ def merge(self, options):
106106
object
107107
108108
Returns:
109-
A :class:`CallSettings` object.
109+
A :class:`_CallSettings` object.
110110
"""
111111
if not options:
112-
return CallSettings(
112+
return _CallSettings(
113113
timeout=self.timeout, retry=self.retry,
114114
page_descriptor=self.page_descriptor,
115115
page_token=self.page_token,
@@ -142,7 +142,7 @@ def merge(self, options):
142142
kwargs = self.kwargs.copy()
143143
kwargs.update(options.kwargs)
144144

145-
return CallSettings(
145+
return _CallSettings(
146146
timeout=timeout, retry=retry,
147147
page_descriptor=self.page_descriptor, page_token=page_token,
148148
bundler=bundler, bundle_descriptor=self.bundle_descriptor,

google/gax/api_callable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from future import utils
3737

38-
from . import (BackoffSettings, BundleOptions, bundling, CallSettings, config,
38+
from . import (BackoffSettings, BundleOptions, bundling, _CallSettings, config,
3939
PageIterator, ResourceIterator, RetryOptions)
4040
from .errors import GaxError, RetryError
4141

@@ -301,7 +301,7 @@ def construct_settings(
301301
service_name, client_config, config_override,
302302
retry_names, bundle_descriptors=None, page_descriptors=None,
303303
kwargs=None):
304-
"""Constructs a dictionary mapping method names to CallSettings.
304+
"""Constructs a dictionary mapping method names to _CallSettings.
305305
306306
The ``client_config`` parameter is parsed from a client configuration JSON
307307
file of the form:
@@ -406,7 +406,7 @@ def construct_settings(
406406
_construct_retry(overriding_method, overrides.get('retry_codes'),
407407
overrides.get('retry_params'), retry_names))
408408

409-
defaults[snake_name] = CallSettings(
409+
defaults[snake_name] = _CallSettings(
410410
timeout=timeout, retry=retry,
411411
page_descriptor=page_descriptors.get(snake_name),
412412
bundler=bundler, bundle_descriptor=bundle_descriptor,
@@ -452,7 +452,7 @@ def create_api_call(func, settings):
452452
453453
Args:
454454
func (callable[[object], object]): is used to make a bare rpc call
455-
settings (:class:`CallSettings`): provides the settings for this call
455+
settings (:class:`_CallSettings`): provides the settings for this call
456456
457457
Returns:
458458
func (callable[[object], object]): a bound method on a request stub used

test/test_api_callable.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from google.gax import (
3838
api_callable, bundling, BackoffSettings, BundleDescriptor, BundleOptions,
39-
CallSettings, CallOptions, INITIAL_PAGE, PageDescriptor, RetryOptions)
39+
_CallSettings, CallOptions, INITIAL_PAGE, PageDescriptor, RetryOptions)
4040
from google.gax.errors import GaxError, RetryError
4141

4242

@@ -116,19 +116,19 @@ class AnotherException(Exception):
116116
class TestCreateApiCallable(unittest2.TestCase):
117117

118118
def test_call_api_call(self):
119-
settings = CallSettings()
119+
settings = _CallSettings()
120120
my_callable = api_callable.create_api_call(
121121
lambda _req, _timeout: 42, settings)
122122
self.assertEqual(my_callable(None), 42)
123123

124124
def test_call_override(self):
125-
settings = CallSettings(timeout=10)
125+
settings = _CallSettings(timeout=10)
126126
my_callable = api_callable.create_api_call(
127127
lambda _req, timeout: timeout, settings)
128128
self.assertEqual(my_callable(None, CallOptions(timeout=20)), 20)
129129

130130
def test_call_kwargs(self):
131-
settings = CallSettings(kwargs={'key': 'value'})
131+
settings = _CallSettings(kwargs={'key': 'value'})
132132
my_callable = api_callable.create_api_call(
133133
lambda _req, _timeout, **kwargs: kwargs['key'], settings)
134134
self.assertEqual(my_callable(None), 'value')
@@ -150,7 +150,7 @@ def test_retry(self, mock_exc_to_code, mock_time):
150150
(to_attempt - 1) + [mock.DEFAULT])
151151
mock_call.return_value = 1729
152152
mock_time.return_value = 0
153-
settings = CallSettings(timeout=0, retry=retry)
153+
settings = _CallSettings(timeout=0, retry=retry)
154154
my_callable = api_callable.create_api_call(mock_call, settings)
155155
self.assertEqual(my_callable(None), 1729)
156156
self.assertEqual(mock_call.call_count, to_attempt)
@@ -163,7 +163,7 @@ def test_no_retry_if_no_codes(self, mock_time):
163163
mock_call.side_effect = CustomException('', _FAKE_STATUS_CODE_1)
164164
mock_time.return_value = 0
165165

166-
settings = CallSettings(timeout=0, retry=retry)
166+
settings = _CallSettings(timeout=0, retry=retry)
167167
my_callable = api_callable.create_api_call(mock_call, settings)
168168
self.assertRaises(CustomException, my_callable, None)
169169
self.assertEqual(mock_call.call_count, 1)
@@ -179,7 +179,7 @@ def fake_call(dummy_request, dummy_timeout):
179179
BackoffSettings(0, 0, 0, 0, 0, 0, 1))
180180
mock_time.side_effect = [0, 2]
181181
mock_exc_to_code.side_effect = lambda e: e.code
182-
settings = CallSettings(timeout=0, retry=retry)
182+
settings = _CallSettings(timeout=0, retry=retry)
183183
my_callable = api_callable.create_api_call(fake_call, settings)
184184

185185
try:
@@ -198,7 +198,7 @@ def test_retry_times_out_simple(self, mock_exc_to_code, mock_time):
198198
mock_call = mock.Mock()
199199
mock_call.side_effect = CustomException('', _FAKE_STATUS_CODE_1)
200200
mock_time.side_effect = ([0] * to_attempt + [2])
201-
settings = CallSettings(timeout=0, retry=retry)
201+
settings = _CallSettings(timeout=0, retry=retry)
202202
my_callable = api_callable.create_api_call(mock_call, settings)
203203

204204
try:
@@ -219,7 +219,7 @@ def test_retry_aborts_on_unexpected_exception(
219219
mock_call = mock.Mock()
220220
mock_call.side_effect = CustomException('', _FAKE_STATUS_CODE_2)
221221
mock_time.return_value = 0
222-
settings = CallSettings(timeout=0, retry=retry)
222+
settings = _CallSettings(timeout=0, retry=retry)
223223
my_callable = api_callable.create_api_call(mock_call, settings)
224224
self.assertRaises(Exception, my_callable, None)
225225
self.assertEqual(mock_call.call_count, 1)
@@ -230,7 +230,7 @@ def test_retry_times_out_no_response(self, mock_time):
230230
retry = RetryOptions(
231231
[_FAKE_STATUS_CODE_1],
232232
BackoffSettings(0, 0, 0, 0, 0, 0, 0))
233-
settings = CallSettings(timeout=0, retry=retry)
233+
settings = _CallSettings(timeout=0, retry=retry)
234234
my_callable = api_callable.create_api_call(lambda: None, settings)
235235

236236
self.assertRaises(RetryError, my_callable, None)
@@ -258,7 +258,7 @@ def api_call(dummy_request, timeout, **dummy_kwargs):
258258

259259
params = BackoffSettings(3, 2, 24, 5, 2, 80, 2500)
260260
retry = RetryOptions([_FAKE_STATUS_CODE_1], params)
261-
settings = CallSettings(timeout=0, retry=retry)
261+
settings = _CallSettings(timeout=0, retry=retry)
262262
my_callable = api_callable.create_api_call(mock_call, settings)
263263

264264
try:
@@ -315,7 +315,7 @@ def grpc_return_value(request, *dummy_args, **dummy_kwargs):
315315

316316
with mock.patch('grpc.UnaryUnaryMultiCallable') as mock_grpc:
317317
mock_grpc.side_effect = grpc_return_value
318-
settings = CallSettings(
318+
settings = _CallSettings(
319319
page_descriptor=fake_grpc_func_descriptor, timeout=0)
320320
my_callable = api_callable.create_api_call(
321321
mock_grpc, settings=settings)
@@ -344,7 +344,7 @@ def grpc_return_value(request, *dummy_args, **dummy_kwargs):
344344
expected)
345345

346346
def test_bundling_page_streaming_error(self):
347-
settings = CallSettings(
347+
settings = _CallSettings(
348348
page_descriptor=object(), bundle_descriptor=object(),
349349
bundler=object())
350350
with self.assertRaises(ValueError):
@@ -362,7 +362,7 @@ def __init__(self, elements=None):
362362
def my_func(request, dummy_timeout):
363363
return len(request.elements)
364364

365-
settings = CallSettings(
365+
settings = _CallSettings(
366366
bundler=bundler, bundle_descriptor=fake_grpc_func_descriptor,
367367
timeout=0)
368368
my_callable = api_callable.create_api_call(my_func, settings)
@@ -478,9 +478,9 @@ def other_error_func(*dummy_args, **dummy_kwargs):
478478
raise AnotherException
479479

480480
gax_error_callable = api_callable.create_api_call(
481-
abortion_error_func, CallSettings())
481+
abortion_error_func, _CallSettings())
482482
self.assertRaises(GaxError, gax_error_callable, None)
483483

484484
other_error_callable = api_callable.create_api_call(
485-
other_error_func, CallSettings())
485+
other_error_func, _CallSettings())
486486
self.assertRaises(AnotherException, other_error_callable, None)

test/test_gax.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import unittest2
3636

3737
from google.gax import (
38-
BundleOptions, CallOptions, CallSettings, INITIAL_PAGE, OPTION_INHERIT,
38+
BundleOptions, CallOptions, _CallSettings, INITIAL_PAGE, OPTION_INHERIT,
3939
RetryOptions)
4040

4141

@@ -72,7 +72,7 @@ def test_cannot_construct_bad_options(self):
7272

7373
def test_settings_merge_options1(self):
7474
options = CallOptions(timeout=46)
75-
settings = CallSettings(timeout=9, page_descriptor=None, retry=None)
75+
settings = _CallSettings(timeout=9, page_descriptor=None, retry=None)
7676
final = settings.merge(options)
7777
self.assertEqual(final.timeout, 46)
7878
self.assertIsNone(final.retry)
@@ -81,7 +81,7 @@ def test_settings_merge_options1(self):
8181
def test_settings_merge_options2(self):
8282
retry = RetryOptions(None, None)
8383
options = CallOptions(retry=retry)
84-
settings = CallSettings(
84+
settings = _CallSettings(
8585
timeout=9, page_descriptor=None, retry=RetryOptions(None, None))
8686
final = settings.merge(options)
8787
self.assertEqual(final.timeout, 9)
@@ -92,8 +92,8 @@ def test_settings_merge_options_page_streaming(self):
9292
retry = RetryOptions(None, None)
9393
page_descriptor = object()
9494
options = CallOptions(timeout=46, page_token=INITIAL_PAGE)
95-
settings = CallSettings(timeout=9, retry=retry,
96-
page_descriptor=page_descriptor)
95+
settings = _CallSettings(timeout=9, retry=retry,
96+
page_descriptor=page_descriptor)
9797
final = settings.merge(options)
9898
self.assertEqual(final.timeout, 46)
9999
self.assertEqual(final.page_descriptor, page_descriptor)
@@ -102,7 +102,7 @@ def test_settings_merge_options_page_streaming(self):
102102
self.assertEqual(final.retry, retry)
103103

104104
def test_settings_merge_none(self):
105-
settings = CallSettings(
105+
settings = _CallSettings(
106106
timeout=23, page_descriptor=object(), bundler=object(),
107107
retry=object())
108108
final = settings.merge(None)

0 commit comments

Comments
 (0)