diff --git a/automl/google/cloud/automl_v1beta1/gapic/auto_ml_client.py b/automl/google/cloud/automl_v1beta1/gapic/auto_ml_client.py index f4e0ea503938..72cecb1b0047 100644 --- a/automl/google/cloud/automl_v1beta1/gapic/auto_ml_client.py +++ b/automl/google/cloud/automl_v1beta1/gapic/auto_ml_client.py @@ -135,7 +135,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=auto_ml_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -168,13 +168,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 = auto_ml_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/automl/google/cloud/automl_v1beta1/gapic/prediction_service_client.py b/automl/google/cloud/automl_v1beta1/gapic/prediction_service_client.py index b1d8e0a21cb9..bc5ff579ec7f 100644 --- a/automl/google/cloud/automl_v1beta1/gapic/prediction_service_client.py +++ b/automl/google/cloud/automl_v1beta1/gapic/prediction_service_client.py @@ -82,7 +82,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=prediction_service_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -115,13 +115,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 = prediction_service_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/automl/google/cloud/automl_v1beta1/gapic/transports/auto_ml_grpc_transport.py b/automl/google/cloud/automl_v1beta1/gapic/transports/auto_ml_grpc_transport.py index a6b5e777c4b5..3f197157afad 100644 --- a/automl/google/cloud/automl_v1beta1/gapic/transports/auto_ml_grpc_transport.py +++ b/automl/google/cloud/automl_v1beta1/gapic/transports/auto_ml_grpc_transport.py @@ -63,6 +63,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 = { @@ -98,6 +100,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_dataset(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/automl/google/cloud/automl_v1beta1/gapic/transports/prediction_service_grpc_transport.py b/automl/google/cloud/automl_v1beta1/gapic/transports/prediction_service_grpc_transport.py index 9ed3ac835890..e837dc2bc03b 100644 --- a/automl/google/cloud/automl_v1beta1/gapic/transports/prediction_service_grpc_transport.py +++ b/automl/google/cloud/automl_v1beta1/gapic/transports/prediction_service_grpc_transport.py @@ -62,6 +62,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 = { @@ -92,6 +94,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 predict(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/automl/tests/unit/gapic/v1beta1/test_auto_ml_client_v1beta1.py b/automl/tests/unit/gapic/v1beta1/test_auto_ml_client_v1beta1.py index e70a8356c373..b3c3e7d573cb 100644 --- a/automl/tests/unit/gapic/v1beta1/test_auto_ml_client_v1beta1.py +++ b/automl/tests/unit/gapic/v1beta1/test_auto_ml_client_v1beta1.py @@ -15,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.rpc import status_pb2 @@ -83,7 +84,10 @@ def test_create_dataset(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -101,7 +105,10 @@ def test_create_dataset(self): def test_create_dataset_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -124,7 +131,10 @@ def test_get_dataset(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -140,7 +150,10 @@ def test_get_dataset(self): def test_get_dataset_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -162,7 +175,10 @@ def test_list_datasets(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -180,7 +196,10 @@ def test_list_datasets(self): def test_list_datasets_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -199,7 +218,10 @@ def test_delete_dataset(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -222,7 +244,10 @@ def test_delete_dataset_exception(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -241,7 +266,10 @@ def test_import_data(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -266,7 +294,10 @@ def test_import_data_exception(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -286,7 +317,10 @@ def test_export_data(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -311,7 +345,10 @@ def test_export_data_exception(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.dataset_path('[PROJECT]', '[LOCATION]', '[DATASET]') @@ -338,7 +375,10 @@ def test_create_model(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -363,7 +403,10 @@ def test_create_model_exception(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -387,7 +430,10 @@ def test_get_model(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -403,7 +449,10 @@ def test_get_model(self): def test_get_model_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -424,7 +473,10 @@ def test_list_models(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -442,7 +494,10 @@ def test_list_models(self): def test_list_models_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -461,7 +516,10 @@ def test_delete_model(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -484,7 +542,10 @@ def test_delete_model_exception(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -502,7 +563,10 @@ def test_deploy_model(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -518,7 +582,10 @@ def test_deploy_model(self): def test_deploy_model_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -535,7 +602,10 @@ def test_undeploy_model(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -551,7 +621,10 @@ def test_undeploy_model(self): def test_undeploy_model_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -574,7 +647,10 @@ def test_get_model_evaluation(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request name = client.model_evaluation_path('[PROJECT]', '[LOCATION]', @@ -591,7 +667,10 @@ def test_get_model_evaluation(self): def test_get_model_evaluation_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request name = client.model_evaluation_path('[PROJECT]', '[LOCATION]', @@ -614,7 +693,10 @@ def test_list_model_evaluations(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup Request parent = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -633,7 +715,10 @@ def test_list_model_evaluations(self): def test_list_model_evaluations_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.AutoMlClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.AutoMlClient() # Setup request parent = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') diff --git a/automl/tests/unit/gapic/v1beta1/test_prediction_service_client_v1beta1.py b/automl/tests/unit/gapic/v1beta1/test_prediction_service_client_v1beta1.py index d46e94b0f063..f591f8d4257f 100644 --- a/automl/tests/unit/gapic/v1beta1/test_prediction_service_client_v1beta1.py +++ b/automl/tests/unit/gapic/v1beta1/test_prediction_service_client_v1beta1.py @@ -15,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.cloud import automl_v1beta1 @@ -70,7 +71,10 @@ def test_predict(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = automl_v1beta1.PredictionServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.PredictionServiceClient() # Setup Request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]') @@ -88,7 +92,10 @@ def test_predict(self): def test_predict_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = automl_v1beta1.PredictionServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = automl_v1beta1.PredictionServiceClient() # Setup request name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')