Skip to content

Commit

Permalink
Pick up fixes in GAPIC generator. (#6708)
Browse files Browse the repository at this point in the history

Includes fixes from these gapic-generator PRs:

- googleapis/gapic-generator#2407
- googleapis/gapic-generator#2396
  • Loading branch information
yoshi-automation authored and tseaver committed Nov 30, 2018
1 parent 0590be6 commit 0890f20
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=big_query_storage_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -112,13 +112,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = big_query_storage_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -95,6 +97,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def create_read_session(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
61 changes: 41 additions & 20 deletions tests/unit/gapic/v1beta1/test_big_query_storage_client_v1beta1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.cloud.bigquery_storage_v1beta1.gapic import big_query_storage_client # noqa
Expand Down Expand Up @@ -77,8 +78,10 @@ def test_create_read_session(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup Request
table_reference = {}
Expand All @@ -96,8 +99,10 @@ def test_create_read_session(self):
def test_create_read_session_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup request
table_reference = {}
Expand All @@ -113,8 +118,10 @@ def test_read_rows(self):

# Mock the API response
channel = ChannelStub(responses=[iter([expected_response])])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup Request
read_position = {}
Expand All @@ -133,8 +140,10 @@ def test_read_rows(self):
def test_read_rows_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup request
read_position = {}
Expand All @@ -150,8 +159,10 @@ def test_batch_create_read_session_streams(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup Request
session = {}
Expand All @@ -170,8 +181,10 @@ def test_batch_create_read_session_streams(self):
def test_batch_create_read_session_streams_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup request
session = {}
Expand All @@ -183,8 +196,10 @@ def test_batch_create_read_session_streams_exception(self):

def test_finalize_stream(self):
channel = ChannelStub()
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup Request
stream = {}
Expand All @@ -199,8 +214,10 @@ def test_finalize_stream(self):
def test_finalize_stream_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup request
stream = {}
Expand All @@ -216,8 +233,10 @@ def test_split_read_stream(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup Request
original_stream = {}
Expand All @@ -234,8 +253,10 @@ def test_split_read_stream(self):
def test_split_read_stream_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = big_query_storage_client.BigQueryStorageClient(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = big_query_storage_client.BigQueryStorageClient()

# Setup request
original_stream = {}
Expand Down

0 comments on commit 0890f20

Please sign in to comment.