From 0890f20b1e5b3b4b2ed3448dae89bdf3e323d134 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot <44816363+yoshi-automation@users.noreply.github.com> Date: Fri, 30 Nov 2018 08:35:05 -0800 Subject: [PATCH] Pick up fixes in GAPIC generator. (#6708) Includes fixes from these gapic-generator PRs: - googleapis/gapic-generator#2407 - googleapis/gapic-generator#2396 --- .../gapic/big_query_storage_client.py | 17 ++++-- .../big_query_storage_grpc_transport.py | 11 ++++ .../test_big_query_storage_client_v1beta1.py | 61 +++++++++++++------ 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/google/cloud/bigquery_storage_v1beta1/gapic/big_query_storage_client.py b/google/cloud/bigquery_storage_v1beta1/gapic/big_query_storage_client.py index 5acd7432..9523923c 100644 --- a/google/cloud/bigquery_storage_v1beta1/gapic/big_query_storage_client.py +++ b/google/cloud/bigquery_storage_v1beta1/gapic/big_query_storage_client.py @@ -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. @@ -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 diff --git a/google/cloud/bigquery_storage_v1beta1/gapic/transports/big_query_storage_grpc_transport.py b/google/cloud/bigquery_storage_v1beta1/gapic/transports/big_query_storage_grpc_transport.py index e5d4483b..0d1ef594 100644 --- a/google/cloud/bigquery_storage_v1beta1/gapic/transports/big_query_storage_grpc_transport.py +++ b/google/cloud/bigquery_storage_v1beta1/gapic/transports/big_query_storage_grpc_transport.py @@ -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 = { @@ -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}. diff --git a/tests/unit/gapic/v1beta1/test_big_query_storage_client_v1beta1.py b/tests/unit/gapic/v1beta1/test_big_query_storage_client_v1beta1.py index 699517f4..b8934c89 100644 --- a/tests/unit/gapic/v1beta1/test_big_query_storage_client_v1beta1.py +++ b/tests/unit/gapic/v1beta1/test_big_query_storage_client_v1beta1.py @@ -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 @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {} @@ -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 = {}