diff --git a/docs/automl_v1/auto_ml.rst b/docs/automl_v1/auto_ml.rst index 224ff9cc..c8994a59 100644 --- a/docs/automl_v1/auto_ml.rst +++ b/docs/automl_v1/auto_ml.rst @@ -5,7 +5,6 @@ AutoMl :members: :inherited-members: - .. automodule:: google.cloud.automl_v1.services.auto_ml.pagers :members: :inherited-members: diff --git a/docs/automl_v1beta1/auto_ml.rst b/docs/automl_v1beta1/auto_ml.rst index 80a90a4e..ddb02f63 100644 --- a/docs/automl_v1beta1/auto_ml.rst +++ b/docs/automl_v1beta1/auto_ml.rst @@ -5,7 +5,6 @@ AutoMl :members: :inherited-members: - .. automodule:: google.cloud.automl_v1beta1.services.auto_ml.pagers :members: :inherited-members: diff --git a/google/cloud/automl/__init__.py b/google/cloud/automl/__init__.py index e6e6a762..f542820a 100644 --- a/google/cloud/automl/__init__.py +++ b/google/cloud/automl/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +14,15 @@ # limitations under the License. # -from google.cloud.automl_v1.services.auto_ml.async_client import AutoMlAsyncClient from google.cloud.automl_v1.services.auto_ml.client import AutoMlClient -from google.cloud.automl_v1.services.prediction_service.async_client import ( - PredictionServiceAsyncClient, -) +from google.cloud.automl_v1.services.auto_ml.async_client import AutoMlAsyncClient from google.cloud.automl_v1.services.prediction_service.client import ( PredictionServiceClient, ) +from google.cloud.automl_v1.services.prediction_service.async_client import ( + PredictionServiceAsyncClient, +) + from google.cloud.automl_v1.types.annotation_payload import AnnotationPayload from google.cloud.automl_v1.types.annotation_spec import AnnotationSpec from google.cloud.automl_v1.types.classification import ClassificationAnnotation @@ -111,90 +111,90 @@ from google.cloud.automl_v1.types.translation import TranslationModelMetadata __all__ = ( + "AutoMlClient", + "AutoMlAsyncClient", + "PredictionServiceClient", + "PredictionServiceAsyncClient", "AnnotationPayload", "AnnotationSpec", - "AutoMlAsyncClient", - "AutoMlClient", - "BatchPredictInputConfig", - "BatchPredictOperationMetadata", - "BatchPredictOutputConfig", - "BatchPredictRequest", - "BatchPredictResult", - "BoundingBoxMetricsEntry", - "BoundingPoly", "ClassificationAnnotation", "ClassificationEvaluationMetrics", "ClassificationType", + "Document", + "DocumentDimensions", + "ExamplePayload", + "Image", + "TextSnippet", + "Dataset", + "BoundingBoxMetricsEntry", + "ImageObjectDetectionAnnotation", + "ImageObjectDetectionEvaluationMetrics", + "BoundingPoly", + "NormalizedVertex", + "ImageClassificationDatasetMetadata", + "ImageClassificationModelDeploymentMetadata", + "ImageClassificationModelMetadata", + "ImageObjectDetectionDatasetMetadata", + "ImageObjectDetectionModelDeploymentMetadata", + "ImageObjectDetectionModelMetadata", + "BatchPredictInputConfig", + "BatchPredictOutputConfig", + "DocumentInputConfig", + "GcsDestination", + "GcsSource", + "InputConfig", + "ModelExportOutputConfig", + "OutputConfig", + "Model", + "ModelEvaluation", + "BatchPredictOperationMetadata", "CreateDatasetOperationMetadata", - "CreateDatasetRequest", "CreateModelOperationMetadata", + "DeleteOperationMetadata", + "DeployModelOperationMetadata", + "ExportDataOperationMetadata", + "ExportModelOperationMetadata", + "ImportDataOperationMetadata", + "OperationMetadata", + "UndeployModelOperationMetadata", + "BatchPredictRequest", + "BatchPredictResult", + "PredictRequest", + "PredictResponse", + "CreateDatasetRequest", "CreateModelRequest", - "Dataset", "DeleteDatasetRequest", "DeleteModelRequest", - "DeleteOperationMetadata", - "DeployModelOperationMetadata", "DeployModelRequest", - "Document", - "DocumentDimensions", - "DocumentInputConfig", - "ExamplePayload", - "ExportDataOperationMetadata", "ExportDataRequest", - "ExportModelOperationMetadata", "ExportModelRequest", - "GcsDestination", - "GcsSource", "GetAnnotationSpecRequest", "GetDatasetRequest", "GetModelEvaluationRequest", "GetModelRequest", - "Image", - "ImageClassificationDatasetMetadata", - "ImageClassificationModelDeploymentMetadata", - "ImageClassificationModelMetadata", - "ImageObjectDetectionAnnotation", - "ImageObjectDetectionDatasetMetadata", - "ImageObjectDetectionEvaluationMetrics", - "ImageObjectDetectionModelDeploymentMetadata", - "ImageObjectDetectionModelMetadata", - "ImportDataOperationMetadata", "ImportDataRequest", - "InputConfig", "ListDatasetsRequest", "ListDatasetsResponse", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", "ListModelsRequest", "ListModelsResponse", - "Model", - "ModelEvaluation", - "ModelExportOutputConfig", - "NormalizedVertex", - "OperationMetadata", - "OutputConfig", - "PredictRequest", - "PredictResponse", - "PredictionServiceAsyncClient", - "PredictionServiceClient", + "UndeployModelRequest", + "UpdateDatasetRequest", + "UpdateModelRequest", "TextClassificationDatasetMetadata", "TextClassificationModelMetadata", - "TextExtractionAnnotation", "TextExtractionDatasetMetadata", - "TextExtractionEvaluationMetrics", "TextExtractionModelMetadata", + "TextSentimentDatasetMetadata", + "TextSentimentModelMetadata", + "TextExtractionAnnotation", + "TextExtractionEvaluationMetrics", "TextSegment", "TextSentimentAnnotation", - "TextSentimentDatasetMetadata", "TextSentimentEvaluationMetrics", - "TextSentimentModelMetadata", - "TextSnippet", "TranslationAnnotation", "TranslationDatasetMetadata", "TranslationEvaluationMetrics", "TranslationModelMetadata", - "UndeployModelOperationMetadata", - "UndeployModelRequest", - "UpdateDatasetRequest", - "UpdateModelRequest", ) diff --git a/google/cloud/automl_v1/__init__.py b/google/cloud/automl_v1/__init__.py index b5f76f81..3890b5ab 100644 --- a/google/cloud/automl_v1/__init__.py +++ b/google/cloud/automl_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,10 @@ # from .services.auto_ml import AutoMlClient +from .services.auto_ml import AutoMlAsyncClient from .services.prediction_service import PredictionServiceClient +from .services.prediction_service import PredictionServiceAsyncClient + from .types.annotation_payload import AnnotationPayload from .types.annotation_spec import AnnotationSpec from .types.classification import ClassificationAnnotation @@ -100,10 +102,12 @@ from .types.translation import TranslationEvaluationMetrics from .types.translation import TranslationModelMetadata - __all__ = ( + "AutoMlAsyncClient", + "PredictionServiceAsyncClient", "AnnotationPayload", "AnnotationSpec", + "AutoMlClient", "BatchPredictInputConfig", "BatchPredictOperationMetadata", "BatchPredictOutputConfig", @@ -185,5 +189,4 @@ "UndeployModelRequest", "UpdateDatasetRequest", "UpdateModelRequest", - "AutoMlClient", ) diff --git a/google/cloud/automl_v1/gapic_metadata.json b/google/cloud/automl_v1/gapic_metadata.json new file mode 100644 index 00000000..44cf25ba --- /dev/null +++ b/google/cloud/automl_v1/gapic_metadata.json @@ -0,0 +1,237 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.automl_v1", + "protoPackage": "google.cloud.automl.v1", + "schema": "1.0", + "services": { + "AutoMl": { + "clients": { + "grpc": { + "libraryClient": "AutoMlClient", + "rpcs": { + "CreateDataset": { + "methods": [ + "create_dataset" + ] + }, + "CreateModel": { + "methods": [ + "create_model" + ] + }, + "DeleteDataset": { + "methods": [ + "delete_dataset" + ] + }, + "DeleteModel": { + "methods": [ + "delete_model" + ] + }, + "DeployModel": { + "methods": [ + "deploy_model" + ] + }, + "ExportData": { + "methods": [ + "export_data" + ] + }, + "ExportModel": { + "methods": [ + "export_model" + ] + }, + "GetAnnotationSpec": { + "methods": [ + "get_annotation_spec" + ] + }, + "GetDataset": { + "methods": [ + "get_dataset" + ] + }, + "GetModel": { + "methods": [ + "get_model" + ] + }, + "GetModelEvaluation": { + "methods": [ + "get_model_evaluation" + ] + }, + "ImportData": { + "methods": [ + "import_data" + ] + }, + "ListDatasets": { + "methods": [ + "list_datasets" + ] + }, + "ListModelEvaluations": { + "methods": [ + "list_model_evaluations" + ] + }, + "ListModels": { + "methods": [ + "list_models" + ] + }, + "UndeployModel": { + "methods": [ + "undeploy_model" + ] + }, + "UpdateDataset": { + "methods": [ + "update_dataset" + ] + }, + "UpdateModel": { + "methods": [ + "update_model" + ] + } + } + }, + "grpc-async": { + "libraryClient": "AutoMlAsyncClient", + "rpcs": { + "CreateDataset": { + "methods": [ + "create_dataset" + ] + }, + "CreateModel": { + "methods": [ + "create_model" + ] + }, + "DeleteDataset": { + "methods": [ + "delete_dataset" + ] + }, + "DeleteModel": { + "methods": [ + "delete_model" + ] + }, + "DeployModel": { + "methods": [ + "deploy_model" + ] + }, + "ExportData": { + "methods": [ + "export_data" + ] + }, + "ExportModel": { + "methods": [ + "export_model" + ] + }, + "GetAnnotationSpec": { + "methods": [ + "get_annotation_spec" + ] + }, + "GetDataset": { + "methods": [ + "get_dataset" + ] + }, + "GetModel": { + "methods": [ + "get_model" + ] + }, + "GetModelEvaluation": { + "methods": [ + "get_model_evaluation" + ] + }, + "ImportData": { + "methods": [ + "import_data" + ] + }, + "ListDatasets": { + "methods": [ + "list_datasets" + ] + }, + "ListModelEvaluations": { + "methods": [ + "list_model_evaluations" + ] + }, + "ListModels": { + "methods": [ + "list_models" + ] + }, + "UndeployModel": { + "methods": [ + "undeploy_model" + ] + }, + "UpdateDataset": { + "methods": [ + "update_dataset" + ] + }, + "UpdateModel": { + "methods": [ + "update_model" + ] + } + } + } + } + }, + "PredictionService": { + "clients": { + "grpc": { + "libraryClient": "PredictionServiceClient", + "rpcs": { + "BatchPredict": { + "methods": [ + "batch_predict" + ] + }, + "Predict": { + "methods": [ + "predict" + ] + } + } + }, + "grpc-async": { + "libraryClient": "PredictionServiceAsyncClient", + "rpcs": { + "BatchPredict": { + "methods": [ + "batch_predict" + ] + }, + "Predict": { + "methods": [ + "predict" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/automl_v1/services/__init__.py b/google/cloud/automl_v1/services/__init__.py index 42ffdf2b..4de65971 100644 --- a/google/cloud/automl_v1/services/__init__.py +++ b/google/cloud/automl_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/automl_v1/services/auto_ml/__init__.py b/google/cloud/automl_v1/services/auto_ml/__init__.py index 3324f01a..bc398205 100644 --- a/google/cloud/automl_v1/services/auto_ml/__init__.py +++ b/google/cloud/automl_v1/services/auto_ml/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import AutoMlClient from .async_client import AutoMlAsyncClient diff --git a/google/cloud/automl_v1/services/auto_ml/async_client.py b/google/cloud/automl_v1/services/auto_ml/async_client.py index 85829e6b..a36438fa 100644 --- a/google/cloud/automl_v1/services/auto_ml/async_client.py +++ b/google/cloud/automl_v1/services/auto_ml/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -47,10 +45,9 @@ from google.cloud.automl_v1.types import text_extraction from google.cloud.automl_v1.types import text_sentiment from google.cloud.automl_v1.types import translation -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import AutoMlTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AutoMlGrpcAsyncIOTransport from .client import AutoMlClient @@ -87,29 +84,25 @@ class AutoMlAsyncClient: parse_model_path = staticmethod(AutoMlClient.parse_model_path) model_evaluation_path = staticmethod(AutoMlClient.model_evaluation_path) parse_model_evaluation_path = staticmethod(AutoMlClient.parse_model_evaluation_path) - common_billing_account_path = staticmethod(AutoMlClient.common_billing_account_path) parse_common_billing_account_path = staticmethod( AutoMlClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(AutoMlClient.common_folder_path) parse_common_folder_path = staticmethod(AutoMlClient.parse_common_folder_path) - common_organization_path = staticmethod(AutoMlClient.common_organization_path) parse_common_organization_path = staticmethod( AutoMlClient.parse_common_organization_path ) - common_project_path = staticmethod(AutoMlClient.common_project_path) parse_common_project_path = staticmethod(AutoMlClient.parse_common_project_path) - common_location_path = staticmethod(AutoMlClient.common_location_path) parse_common_location_path = staticmethod(AutoMlClient.parse_common_location_path) @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -124,7 +117,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -141,7 +134,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AutoMlTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: AutoMlTransport: The transport used by the client instance. @@ -155,12 +148,12 @@ def transport(self) -> AutoMlTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, AutoMlTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the auto ml client. + """Instantiates the auto ml client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -192,7 +185,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = AutoMlClient( credentials=credentials, transport=transport, @@ -228,7 +220,6 @@ async def create_dataset( This corresponds to the ``dataset`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -257,7 +248,6 @@ async def create_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if dataset is not None: @@ -313,7 +303,6 @@ async def get_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -342,7 +331,6 @@ async def get_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -355,7 +343,8 @@ async def get_dataset( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -397,7 +386,6 @@ async def list_datasets( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -427,7 +415,6 @@ async def list_datasets( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -440,7 +427,8 @@ async def list_datasets( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -471,7 +459,7 @@ async def update_dataset( request: service.UpdateDatasetRequest = None, *, dataset: gca_dataset.Dataset = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -496,7 +484,6 @@ async def update_dataset( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -525,7 +512,6 @@ async def update_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if dataset is not None: request.dataset = dataset if update_mask is not None: @@ -579,7 +565,6 @@ async def delete_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -619,7 +604,6 @@ async def delete_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -632,7 +616,8 @@ async def delete_dataset( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -653,7 +638,7 @@ async def delete_dataset( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -701,7 +686,6 @@ async def import_data( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -741,7 +725,6 @@ async def import_data( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -768,7 +751,7 @@ async def import_data( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -808,7 +791,6 @@ async def export_data( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -848,7 +830,6 @@ async def export_data( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -875,7 +856,7 @@ async def export_data( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -904,7 +885,6 @@ async def get_annotation_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -929,7 +909,6 @@ async def get_annotation_spec( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -942,7 +921,8 @@ async def get_annotation_spec( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -995,7 +975,6 @@ async def create_model( This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1025,7 +1004,6 @@ async def create_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if model is not None: @@ -1079,7 +1057,6 @@ async def get_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1106,7 +1083,6 @@ async def get_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1119,7 +1095,8 @@ async def get_model( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1161,7 +1138,6 @@ async def list_models( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1191,7 +1167,6 @@ async def list_models( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1204,7 +1179,8 @@ async def list_models( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1255,7 +1231,6 @@ async def delete_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1295,7 +1270,6 @@ async def delete_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1308,7 +1282,8 @@ async def delete_model( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1329,7 +1304,7 @@ async def delete_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1341,7 +1316,7 @@ async def update_model( request: service.UpdateModelRequest = None, *, model: gca_model.Model = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -1366,7 +1341,6 @@ async def update_model( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1393,7 +1367,6 @@ async def update_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if model is not None: request.model = model if update_mask is not None: @@ -1457,7 +1430,6 @@ async def deploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1497,7 +1469,6 @@ async def deploy_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1522,7 +1493,7 @@ async def deploy_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1559,7 +1530,6 @@ async def undeploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1599,7 +1569,6 @@ async def undeploy_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1624,7 +1593,7 @@ async def undeploy_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1670,7 +1639,6 @@ async def export_model( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1710,7 +1678,6 @@ async def export_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -1737,7 +1704,7 @@ async def export_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1766,7 +1733,6 @@ async def get_model_evaluation( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1791,7 +1757,6 @@ async def get_model_evaluation( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1804,7 +1769,8 @@ async def get_model_evaluation( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1868,7 +1834,6 @@ async def list_model_evaluations( This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1898,7 +1863,6 @@ async def list_model_evaluations( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if filter is not None: @@ -1913,7 +1877,8 @@ async def list_model_evaluations( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), diff --git a/google/cloud/automl_v1/services/auto_ml/client.py b/google/cloud/automl_v1/services/auto_ml/client.py index faebcf8f..5aa1029b 100644 --- a/google/cloud/automl_v1/services/auto_ml/client.py +++ b/google/cloud/automl_v1/services/auto_ml/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -51,10 +49,9 @@ from google.cloud.automl_v1.types import text_extraction from google.cloud.automl_v1.types import text_sentiment from google.cloud.automl_v1.types import translation -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import AutoMlTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AutoMlGrpcTransport from .transports.grpc_asyncio import AutoMlGrpcAsyncIOTransport @@ -73,7 +70,7 @@ class AutoMlClientMeta(type): _transport_registry["grpc_asyncio"] = AutoMlGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[AutoMlTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -111,7 +108,8 @@ class AutoMlClient(metaclass=AutoMlClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -145,7 +143,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -162,7 +161,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -181,10 +180,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AutoMlTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - AutoMlTransport: The transport used by the client instance. + AutoMlTransport: The transport used by the client + instance. """ return self._transport @@ -192,7 +192,7 @@ def transport(self) -> AutoMlTransport: def annotation_spec_path( project: str, location: str, dataset: str, annotation_spec: str, ) -> str: - """Return a fully-qualified annotation_spec string.""" + """Returns a fully-qualified annotation_spec string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}".format( project=project, location=location, @@ -202,7 +202,7 @@ def annotation_spec_path( @staticmethod def parse_annotation_spec_path(path: str) -> Dict[str, str]: - """Parse a annotation_spec path into its component segments.""" + """Parses a annotation_spec path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/annotationSpecs/(?P.+?)$", path, @@ -211,14 +211,14 @@ def parse_annotation_spec_path(path: str) -> Dict[str, str]: @staticmethod def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( project=project, location=location, dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -227,14 +227,14 @@ def parse_dataset_path(path: str) -> Dict[str, str]: @staticmethod def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -245,7 +245,7 @@ def parse_model_path(path: str) -> Dict[str, str]: def model_evaluation_path( project: str, location: str, model: str, model_evaluation: str, ) -> str: - """Return a fully-qualified model_evaluation string.""" + """Returns a fully-qualified model_evaluation string.""" return "projects/{project}/locations/{location}/models/{model}/modelEvaluations/{model_evaluation}".format( project=project, location=location, @@ -255,7 +255,7 @@ def model_evaluation_path( @staticmethod def parse_model_evaluation_path(path: str) -> Dict[str, str]: - """Parse a model_evaluation path into its component segments.""" + """Parses a model_evaluation path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)/modelEvaluations/(?P.+?)$", path, @@ -264,7 +264,7 @@ def parse_model_evaluation_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -277,7 +277,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -288,7 +288,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -299,7 +299,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -310,7 +310,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -324,12 +324,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, AutoMlTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the auto ml client. + """Instantiates the auto ml client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -384,9 +384,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -398,12 +399,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -418,8 +421,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -462,7 +465,6 @@ def create_dataset( This corresponds to the ``dataset`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -493,10 +495,8 @@ def create_dataset( # there are no flattened fields. if not isinstance(request, service.CreateDatasetRequest): request = service.CreateDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if dataset is not None: @@ -548,7 +548,6 @@ def get_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -579,10 +578,8 @@ def get_dataset( # there are no flattened fields. if not isinstance(request, service.GetDatasetRequest): request = service.GetDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -624,7 +621,6 @@ def list_datasets( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -656,10 +652,8 @@ def list_datasets( # there are no flattened fields. if not isinstance(request, service.ListDatasetsRequest): request = service.ListDatasetsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -690,7 +684,7 @@ def update_dataset( request: service.UpdateDatasetRequest = None, *, dataset: gca_dataset.Dataset = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -715,7 +709,6 @@ def update_dataset( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -746,10 +739,8 @@ def update_dataset( # there are no flattened fields. if not isinstance(request, service.UpdateDatasetRequest): request = service.UpdateDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if dataset is not None: request.dataset = dataset if update_mask is not None: @@ -799,7 +790,6 @@ def delete_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -841,10 +831,8 @@ def delete_dataset( # there are no flattened fields. if not isinstance(request, service.DeleteDatasetRequest): request = service.DeleteDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -865,7 +853,7 @@ def delete_dataset( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -913,7 +901,6 @@ def import_data( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -955,10 +942,8 @@ def import_data( # there are no flattened fields. if not isinstance(request, service.ImportDataRequest): request = service.ImportDataRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -981,7 +966,7 @@ def import_data( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1021,7 +1006,6 @@ def export_data( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1063,10 +1047,8 @@ def export_data( # there are no flattened fields. if not isinstance(request, service.ExportDataRequest): request = service.ExportDataRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -1089,7 +1071,7 @@ def export_data( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1118,7 +1100,6 @@ def get_annotation_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1145,10 +1126,8 @@ def get_annotation_spec( # there are no flattened fields. if not isinstance(request, service.GetAnnotationSpecRequest): request = service.GetAnnotationSpecRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1201,7 +1180,6 @@ def create_model( This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1233,10 +1211,8 @@ def create_model( # there are no flattened fields. if not isinstance(request, service.CreateModelRequest): request = service.CreateModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if model is not None: @@ -1286,7 +1262,6 @@ def get_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1315,10 +1290,8 @@ def get_model( # there are no flattened fields. if not isinstance(request, service.GetModelRequest): request = service.GetModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1360,7 +1333,6 @@ def list_models( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1392,10 +1364,8 @@ def list_models( # there are no flattened fields. if not isinstance(request, service.ListModelsRequest): request = service.ListModelsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1446,7 +1416,6 @@ def delete_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1488,10 +1457,8 @@ def delete_model( # there are no flattened fields. if not isinstance(request, service.DeleteModelRequest): request = service.DeleteModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1512,7 +1479,7 @@ def delete_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1524,7 +1491,7 @@ def update_model( request: service.UpdateModelRequest = None, *, model: gca_model.Model = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -1549,7 +1516,6 @@ def update_model( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1578,10 +1544,8 @@ def update_model( # there are no flattened fields. if not isinstance(request, service.UpdateModelRequest): request = service.UpdateModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if model is not None: request.model = model if update_mask is not None: @@ -1641,7 +1605,6 @@ def deploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1683,10 +1646,8 @@ def deploy_model( # there are no flattened fields. if not isinstance(request, service.DeployModelRequest): request = service.DeployModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1707,7 +1668,7 @@ def deploy_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1744,7 +1705,6 @@ def undeploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1786,10 +1746,8 @@ def undeploy_model( # there are no flattened fields. if not isinstance(request, service.UndeployModelRequest): request = service.UndeployModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1810,7 +1768,7 @@ def undeploy_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1856,7 +1814,6 @@ def export_model( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1898,10 +1855,8 @@ def export_model( # there are no flattened fields. if not isinstance(request, service.ExportModelRequest): request = service.ExportModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -1924,7 +1879,7 @@ def export_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1953,7 +1908,6 @@ def get_model_evaluation( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1980,10 +1934,8 @@ def get_model_evaluation( # there are no flattened fields. if not isinstance(request, service.GetModelEvaluationRequest): request = service.GetModelEvaluationRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2047,7 +1999,6 @@ def list_model_evaluations( This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2079,10 +2030,8 @@ def list_model_evaluations( # there are no flattened fields. if not isinstance(request, service.ListModelEvaluationsRequest): request = service.ListModelEvaluationsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if filter is not None: diff --git a/google/cloud/automl_v1/services/auto_ml/pagers.py b/google/cloud/automl_v1/services/auto_ml/pagers.py index 73a0d958..10f14633 100644 --- a/google/cloud/automl_v1/services/auto_ml/pagers.py +++ b/google/cloud/automl_v1/services/auto_ml/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -120,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -248,7 +246,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -376,7 +374,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/automl_v1/services/auto_ml/transports/__init__.py b/google/cloud/automl_v1/services/auto_ml/transports/__init__.py index 946bdb5f..f0c466d9 100644 --- a/google/cloud/automl_v1/services/auto_ml/transports/__init__.py +++ b/google/cloud/automl_v1/services/auto_ml/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/automl_v1/services/auto_ml/transports/base.py b/google/cloud/automl_v1/services/auto_ml/transports/base.py index 19b87223..9b1bde08 100644 --- a/google/cloud/automl_v1/services/auto_ml/transports/base.py +++ b/google/cloud/automl_v1/services/auto_ml/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,17 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.automl_v1.types import annotation_spec from google.cloud.automl_v1.types import dataset @@ -33,8 +33,7 @@ from google.cloud.automl_v1.types import model as gca_model from google.cloud.automl_v1.types import model_evaluation from google.cloud.automl_v1.types import service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -43,27 +42,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class AutoMlTransport(abc.ABC): """Abstract transport class for AutoMl.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "automl.googleapis.com" + def __init__( self, *, - host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -72,7 +85,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -86,29 +99,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -122,7 +182,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -136,7 +197,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -153,7 +215,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -173,7 +236,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -190,7 +254,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -204,7 +269,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -218,7 +284,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -244,7 +311,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -258,7 +326,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -275,76 +344,72 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def create_dataset( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateDatasetRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_dataset( self, - ) -> typing.Callable[ - [service.GetDatasetRequest], - typing.Union[dataset.Dataset, typing.Awaitable[dataset.Dataset]], + ) -> Callable[ + [service.GetDatasetRequest], Union[dataset.Dataset, Awaitable[dataset.Dataset]] ]: raise NotImplementedError() @property def list_datasets( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListDatasetsRequest], - typing.Union[ - service.ListDatasetsResponse, typing.Awaitable[service.ListDatasetsResponse] - ], + Union[service.ListDatasetsResponse, Awaitable[service.ListDatasetsResponse]], ]: raise NotImplementedError() @property def update_dataset( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdateDatasetRequest], - typing.Union[gca_dataset.Dataset, typing.Awaitable[gca_dataset.Dataset]], + Union[gca_dataset.Dataset, Awaitable[gca_dataset.Dataset]], ]: raise NotImplementedError() @property def delete_dataset( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteDatasetRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def import_data( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ImportDataRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_data( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ExportDataRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_annotation_spec( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetAnnotationSpecRequest], - typing.Union[ - annotation_spec.AnnotationSpec, - typing.Awaitable[annotation_spec.AnnotationSpec], + Union[ + annotation_spec.AnnotationSpec, Awaitable[annotation_spec.AnnotationSpec] ], ]: raise NotImplementedError() @@ -352,85 +417,81 @@ def get_annotation_spec( @property def create_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_model( self, - ) -> typing.Callable[ - [service.GetModelRequest], - typing.Union[model.Model, typing.Awaitable[model.Model]], + ) -> Callable[ + [service.GetModelRequest], Union[model.Model, Awaitable[model.Model]] ]: raise NotImplementedError() @property def list_models( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListModelsRequest], - typing.Union[ - service.ListModelsResponse, typing.Awaitable[service.ListModelsResponse] - ], + Union[service.ListModelsResponse, Awaitable[service.ListModelsResponse]], ]: raise NotImplementedError() @property def delete_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_model( self, - ) -> typing.Callable[ - [service.UpdateModelRequest], - typing.Union[gca_model.Model, typing.Awaitable[gca_model.Model]], + ) -> Callable[ + [service.UpdateModelRequest], Union[gca_model.Model, Awaitable[gca_model.Model]] ]: raise NotImplementedError() @property def deploy_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeployModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def undeploy_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UndeployModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ExportModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_model_evaluation( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetModelEvaluationRequest], - typing.Union[ + Union[ model_evaluation.ModelEvaluation, - typing.Awaitable[model_evaluation.ModelEvaluation], + Awaitable[model_evaluation.ModelEvaluation], ], ]: raise NotImplementedError() @@ -438,11 +499,11 @@ def get_model_evaluation( @property def list_model_evaluations( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListModelEvaluationsRequest], - typing.Union[ + Union[ service.ListModelEvaluationsResponse, - typing.Awaitable[service.ListModelEvaluationsResponse], + Awaitable[service.ListModelEvaluationsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/automl_v1/services/auto_ml/transports/grpc.py b/google/cloud/automl_v1/services/auto_ml/transports/grpc.py index e2f36ade..2d9d00de 100644 --- a/google/cloud/automl_v1/services/auto_ml/transports/grpc.py +++ b/google/cloud/automl_v1/services/auto_ml/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore @@ -34,8 +32,7 @@ from google.cloud.automl_v1.types import model as gca_model from google.cloud.automl_v1.types import model_evaluation from google.cloud.automl_v1.types import service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import AutoMlTransport, DEFAULT_CLIENT_INFO @@ -72,7 +69,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -86,7 +83,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -197,7 +195,7 @@ def __init__( def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -228,13 +226,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -261,7 +261,7 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def create_dataset( self, - ) -> Callable[[service.CreateDatasetRequest], operations.Operation]: + ) -> Callable[[service.CreateDatasetRequest], operations_pb2.Operation]: r"""Return a callable for the create dataset method over gRPC. Creates a dataset. @@ -280,7 +280,7 @@ def create_dataset( self._stubs["create_dataset"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/CreateDataset", request_serializer=service.CreateDatasetRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_dataset"] @@ -363,7 +363,7 @@ def update_dataset( @property def delete_dataset( self, - ) -> Callable[[service.DeleteDatasetRequest], operations.Operation]: + ) -> Callable[[service.DeleteDatasetRequest], operations_pb2.Operation]: r"""Return a callable for the delete dataset method over gRPC. Deletes a dataset and all of its contents. Returns empty @@ -386,14 +386,14 @@ def delete_dataset( self._stubs["delete_dataset"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/DeleteDataset", request_serializer=service.DeleteDatasetRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_dataset"] @property def import_data( self, - ) -> Callable[[service.ImportDataRequest], operations.Operation]: + ) -> Callable[[service.ImportDataRequest], operations_pb2.Operation]: r"""Return a callable for the import data method over gRPC. Imports data into a dataset. For Tables this method can only be @@ -421,14 +421,14 @@ def import_data( self._stubs["import_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/ImportData", request_serializer=service.ImportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_data"] @property def export_data( self, - ) -> Callable[[service.ExportDataRequest], operations.Operation]: + ) -> Callable[[service.ExportDataRequest], operations_pb2.Operation]: r"""Return a callable for the export data method over gRPC. Exports dataset's data to the provided output location. Returns @@ -450,7 +450,7 @@ def export_data( self._stubs["export_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/ExportData", request_serializer=service.ExportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_data"] @@ -483,7 +483,7 @@ def get_annotation_spec( @property def create_model( self, - ) -> Callable[[service.CreateModelRequest], operations.Operation]: + ) -> Callable[[service.CreateModelRequest], operations_pb2.Operation]: r"""Return a callable for the create model method over gRPC. Creates a model. Returns a Model in the @@ -506,7 +506,7 @@ def create_model( self._stubs["create_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/CreateModel", request_serializer=service.CreateModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_model"] @@ -563,7 +563,7 @@ def list_models( @property def delete_model( self, - ) -> Callable[[service.DeleteModelRequest], operations.Operation]: + ) -> Callable[[service.DeleteModelRequest], operations_pb2.Operation]: r"""Return a callable for the delete model method over gRPC. Deletes a model. Returns ``google.protobuf.Empty`` in the @@ -585,7 +585,7 @@ def delete_model( self._stubs["delete_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/DeleteModel", request_serializer=service.DeleteModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_model"] @@ -616,7 +616,7 @@ def update_model(self) -> Callable[[service.UpdateModelRequest], gca_model.Model @property def deploy_model( self, - ) -> Callable[[service.DeployModelRequest], operations.Operation]: + ) -> Callable[[service.DeployModelRequest], operations_pb2.Operation]: r"""Return a callable for the deploy model method over gRPC. Deploys a model. If a model is already deployed, deploying it @@ -649,14 +649,14 @@ def deploy_model( self._stubs["deploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/DeployModel", request_serializer=service.DeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["deploy_model"] @property def undeploy_model( self, - ) -> Callable[[service.UndeployModelRequest], operations.Operation]: + ) -> Callable[[service.UndeployModelRequest], operations_pb2.Operation]: r"""Return a callable for the undeploy model method over gRPC. Undeploys a model. If the model is not deployed this method has @@ -683,14 +683,14 @@ def undeploy_model( self._stubs["undeploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/UndeployModel", request_serializer=service.UndeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["undeploy_model"] @property def export_model( self, - ) -> Callable[[service.ExportModelRequest], operations.Operation]: + ) -> Callable[[service.ExportModelRequest], operations_pb2.Operation]: r"""Return a callable for the export model method over gRPC. Exports a trained, "export-able", model to a user specified @@ -716,7 +716,7 @@ def export_model( self._stubs["export_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/ExportModel", request_serializer=service.ExportModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_model"] diff --git a/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py b/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py index 46144f01..cdc11fe7 100644 --- a/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py +++ b/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -35,8 +33,7 @@ from google.cloud.automl_v1.types import model as gca_model from google.cloud.automl_v1.types import model_evaluation from google.cloud.automl_v1.types import service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import AutoMlTransport, DEFAULT_CLIENT_INFO from .grpc import AutoMlGrpcTransport @@ -75,7 +72,7 @@ class AutoMlGrpcAsyncIOTransport(AutoMlTransport): def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -102,13 +99,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -116,7 +115,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -130,7 +129,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -189,7 +189,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -267,7 +266,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: @property def create_dataset( self, - ) -> Callable[[service.CreateDatasetRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.CreateDatasetRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the create dataset method over gRPC. Creates a dataset. @@ -286,7 +285,7 @@ def create_dataset( self._stubs["create_dataset"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/CreateDataset", request_serializer=service.CreateDatasetRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_dataset"] @@ -373,7 +372,7 @@ def update_dataset( @property def delete_dataset( self, - ) -> Callable[[service.DeleteDatasetRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeleteDatasetRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete dataset method over gRPC. Deletes a dataset and all of its contents. Returns empty @@ -396,14 +395,14 @@ def delete_dataset( self._stubs["delete_dataset"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/DeleteDataset", request_serializer=service.DeleteDatasetRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_dataset"] @property def import_data( self, - ) -> Callable[[service.ImportDataRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ImportDataRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the import data method over gRPC. Imports data into a dataset. For Tables this method can only be @@ -431,14 +430,14 @@ def import_data( self._stubs["import_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/ImportData", request_serializer=service.ImportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_data"] @property def export_data( self, - ) -> Callable[[service.ExportDataRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ExportDataRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the export data method over gRPC. Exports dataset's data to the provided output location. Returns @@ -460,7 +459,7 @@ def export_data( self._stubs["export_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/ExportData", request_serializer=service.ExportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_data"] @@ -495,7 +494,7 @@ def get_annotation_spec( @property def create_model( self, - ) -> Callable[[service.CreateModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.CreateModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the create model method over gRPC. Creates a model. Returns a Model in the @@ -518,7 +517,7 @@ def create_model( self._stubs["create_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/CreateModel", request_serializer=service.CreateModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_model"] @@ -575,7 +574,7 @@ def list_models( @property def delete_model( self, - ) -> Callable[[service.DeleteModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeleteModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete model method over gRPC. Deletes a model. Returns ``google.protobuf.Empty`` in the @@ -597,7 +596,7 @@ def delete_model( self._stubs["delete_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/DeleteModel", request_serializer=service.DeleteModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_model"] @@ -630,7 +629,7 @@ def update_model( @property def deploy_model( self, - ) -> Callable[[service.DeployModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeployModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the deploy model method over gRPC. Deploys a model. If a model is already deployed, deploying it @@ -663,14 +662,14 @@ def deploy_model( self._stubs["deploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/DeployModel", request_serializer=service.DeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["deploy_model"] @property def undeploy_model( self, - ) -> Callable[[service.UndeployModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.UndeployModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the undeploy model method over gRPC. Undeploys a model. If the model is not deployed this method has @@ -697,14 +696,14 @@ def undeploy_model( self._stubs["undeploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/UndeployModel", request_serializer=service.UndeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["undeploy_model"] @property def export_model( self, - ) -> Callable[[service.ExportModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ExportModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the export model method over gRPC. Exports a trained, "export-able", model to a user specified @@ -730,7 +729,7 @@ def export_model( self._stubs["export_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.AutoMl/ExportModel", request_serializer=service.ExportModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_model"] diff --git a/google/cloud/automl_v1/services/prediction_service/__init__.py b/google/cloud/automl_v1/services/prediction_service/__init__.py index 0c847693..12491bb1 100644 --- a/google/cloud/automl_v1/services/prediction_service/__init__.py +++ b/google/cloud/automl_v1/services/prediction_service/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import PredictionServiceClient from .async_client import PredictionServiceAsyncClient diff --git a/google/cloud/automl_v1/services/prediction_service/async_client.py b/google/cloud/automl_v1/services/prediction_service/async_client.py index f420199a..4229ce13 100644 --- a/google/cloud/automl_v1/services/prediction_service/async_client.py +++ b/google/cloud/automl_v1/services/prediction_service/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -35,7 +33,6 @@ from google.cloud.automl_v1.types import io from google.cloud.automl_v1.types import operations from google.cloud.automl_v1.types import prediction_service - from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport from .client import PredictionServiceClient @@ -55,31 +52,26 @@ class PredictionServiceAsyncClient: model_path = staticmethod(PredictionServiceClient.model_path) parse_model_path = staticmethod(PredictionServiceClient.parse_model_path) - common_billing_account_path = staticmethod( PredictionServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( PredictionServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(PredictionServiceClient.common_folder_path) parse_common_folder_path = staticmethod( PredictionServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( PredictionServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( PredictionServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(PredictionServiceClient.common_project_path) parse_common_project_path = staticmethod( PredictionServiceClient.parse_common_project_path ) - common_location_path = staticmethod(PredictionServiceClient.common_location_path) parse_common_location_path = staticmethod( PredictionServiceClient.parse_common_location_path @@ -87,7 +79,8 @@ class PredictionServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -102,7 +95,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -119,7 +112,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: PredictionServiceTransport: The transport used by the client instance. @@ -133,12 +126,12 @@ def transport(self) -> PredictionServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, PredictionServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -170,7 +163,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = PredictionServiceClient( credentials=credentials, transport=transport, @@ -282,7 +274,6 @@ async def predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -309,7 +300,6 @@ async def predict( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if payload is not None: @@ -486,7 +476,6 @@ async def batch_predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -517,7 +506,6 @@ async def batch_predict( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: diff --git a/google/cloud/automl_v1/services/prediction_service/client.py b/google/cloud/automl_v1/services/prediction_service/client.py index 5f5fc44b..fdb7e73c 100644 --- a/google/cloud/automl_v1/services/prediction_service/client.py +++ b/google/cloud/automl_v1/services/prediction_service/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -39,7 +37,6 @@ from google.cloud.automl_v1.types import io from google.cloud.automl_v1.types import operations from google.cloud.automl_v1.types import prediction_service - from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import PredictionServiceGrpcTransport from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport @@ -62,7 +59,7 @@ class PredictionServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[PredictionServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -89,7 +86,8 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -123,7 +121,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -140,7 +139,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -159,23 +158,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - PredictionServiceTransport: The transport used by the client instance. + PredictionServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -184,7 +184,7 @@ def parse_model_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -197,7 +197,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -208,7 +208,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -219,7 +219,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -230,7 +230,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -244,12 +244,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, PredictionServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -304,9 +304,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -318,12 +319,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -338,8 +341,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -458,7 +461,6 @@ def predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -487,10 +489,8 @@ def predict( # there are no flattened fields. if not isinstance(request, prediction_service.PredictRequest): request = prediction_service.PredictRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if payload is not None: @@ -662,7 +662,6 @@ def batch_predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -695,10 +694,8 @@ def batch_predict( # there are no flattened fields. if not isinstance(request, prediction_service.BatchPredictRequest): request = prediction_service.BatchPredictRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: diff --git a/google/cloud/automl_v1/services/prediction_service/transports/__init__.py b/google/cloud/automl_v1/services/prediction_service/transports/__init__.py index 9ec1369a..86d2e8a7 100644 --- a/google/cloud/automl_v1/services/prediction_service/transports/__init__.py +++ b/google/cloud/automl_v1/services/prediction_service/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/automl_v1/services/prediction_service/transports/base.py b/google/cloud/automl_v1/services/prediction_service/transports/base.py index 148e1307..b8900a14 100644 --- a/google/cloud/automl_v1/services/prediction_service/transports/base.py +++ b/google/cloud/automl_v1/services/prediction_service/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.automl_v1.types import prediction_service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class PredictionServiceTransport(abc.ABC): """Abstract transport class for PredictionService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "automl.googleapis.com" + def __init__( self, *, - host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -66,7 +79,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -80,29 +93,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -122,11 +182,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def predict( self, - ) -> typing.Callable[ + ) -> Callable[ [prediction_service.PredictRequest], - typing.Union[ + Union[ prediction_service.PredictResponse, - typing.Awaitable[prediction_service.PredictResponse], + Awaitable[prediction_service.PredictResponse], ], ]: raise NotImplementedError() @@ -134,9 +194,9 @@ def predict( @property def batch_predict( self, - ) -> typing.Callable[ + ) -> Callable[ [prediction_service.BatchPredictRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/automl_v1/services/prediction_service/transports/grpc.py b/google/cloud/automl_v1/services/prediction_service/transports/grpc.py index cc2f2a2e..0fc228e9 100644 --- a/google/cloud/automl_v1/services/prediction_service/transports/grpc.py +++ b/google/cloud/automl_v1/services/prediction_service/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.automl_v1.types import prediction_service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO @@ -55,7 +52,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -69,7 +66,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -180,7 +178,7 @@ def __init__( def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -211,13 +209,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -308,7 +308,7 @@ def predict( @property def batch_predict( self, - ) -> Callable[[prediction_service.BatchPredictRequest], operations.Operation]: + ) -> Callable[[prediction_service.BatchPredictRequest], operations_pb2.Operation]: r"""Return a callable for the batch predict method over gRPC. Perform a batch prediction. Unlike the online @@ -346,7 +346,7 @@ def batch_predict( self._stubs["batch_predict"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.PredictionService/BatchPredict", request_serializer=prediction_service.BatchPredictRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["batch_predict"] diff --git a/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py b/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py index 70f8ddf7..a5da4a8c 100644 --- a/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py +++ b/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.automl_v1.types import prediction_service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .grpc import PredictionServiceGrpcTransport @@ -58,7 +55,7 @@ class PredictionServiceGrpcAsyncIOTransport(PredictionServiceTransport): def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -85,13 +82,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -99,7 +98,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -113,7 +112,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -172,7 +172,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -316,7 +315,7 @@ def predict( def batch_predict( self, ) -> Callable[ - [prediction_service.BatchPredictRequest], Awaitable[operations.Operation] + [prediction_service.BatchPredictRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the batch predict method over gRPC. @@ -355,7 +354,7 @@ def batch_predict( self._stubs["batch_predict"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1.PredictionService/BatchPredict", request_serializer=prediction_service.BatchPredictRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["batch_predict"] diff --git a/google/cloud/automl_v1/types/__init__.py b/google/cloud/automl_v1/types/__init__.py index 3d40bbce..162d09e0 100644 --- a/google/cloud/automl_v1/types/__init__.py +++ b/google/cloud/automl_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .annotation_payload import AnnotationPayload from .annotation_spec import AnnotationSpec from .classification import ( diff --git a/google/cloud/automl_v1/types/annotation_payload.py b/google/cloud/automl_v1/types/annotation_payload.py index d3106429..e1297261 100644 --- a/google/cloud/automl_v1/types/annotation_payload.py +++ b/google/cloud/automl_v1/types/annotation_payload.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import classification as gca_classification from google.cloud.automl_v1.types import detection from google.cloud.automl_v1.types import text_extraction as gca_text_extraction @@ -32,7 +29,6 @@ class AnnotationPayload(proto.Message): r"""Contains annotation information that is relevant to AutoML. - Attributes: translation (google.cloud.automl_v1.types.TranslationAnnotation): Annotation details for translation. @@ -68,38 +64,32 @@ class AnnotationPayload(proto.Message): oneof="detail", message=gca_translation.TranslationAnnotation, ) - classification = proto.Field( proto.MESSAGE, number=3, oneof="detail", message=gca_classification.ClassificationAnnotation, ) - image_object_detection = proto.Field( proto.MESSAGE, number=4, oneof="detail", message=detection.ImageObjectDetectionAnnotation, ) - text_extraction = proto.Field( proto.MESSAGE, number=6, oneof="detail", message=gca_text_extraction.TextExtractionAnnotation, ) - text_sentiment = proto.Field( proto.MESSAGE, number=7, oneof="detail", message=gca_text_sentiment.TextSentimentAnnotation, ) - - annotation_spec_id = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=5) + annotation_spec_id = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/annotation_spec.py b/google/cloud/automl_v1/types/annotation_spec.py index 9d13be8d..95294100 100644 --- a/google/cloud/automl_v1/types/annotation_spec.py +++ b/google/cloud/automl_v1/types/annotation_spec.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -25,7 +23,6 @@ class AnnotationSpec(proto.Message): r"""A definition of an annotation spec. - Attributes: name (str): Output only. Resource name of the annotation spec. Form: @@ -40,11 +37,9 @@ class AnnotationSpec(proto.Message): parent dataset labeled by the annotation spec. """ - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - example_count = proto.Field(proto.INT32, number=9) + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + example_count = proto.Field(proto.INT32, number=9,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/classification.py b/google/cloud/automl_v1/types/classification.py index 873c7501..6e1461fa 100644 --- a/google/cloud/automl_v1/types/classification.py +++ b/google/cloud/automl_v1/types/classification.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -37,7 +35,6 @@ class ClassificationType(proto.Enum): class ClassificationAnnotation(proto.Message): r"""Contains annotation details specific to classification. - Attributes: score (float): Output only. A confidence estimate between @@ -49,7 +46,7 @@ class ClassificationAnnotation(proto.Message): negative or 1 for positive. """ - score = proto.Field(proto.FLOAT, number=1) + score = proto.Field(proto.FLOAT, number=1,) class ClassificationEvaluationMetrics(proto.Message): @@ -90,7 +87,6 @@ class ClassificationEvaluationMetrics(proto.Message): class ConfidenceMetricsEntry(proto.Message): r"""Metrics for a single confidence threshold. - Attributes: confidence_threshold (float): Output only. Metrics are computed with an @@ -149,37 +145,23 @@ class ConfidenceMetricsEntry(proto.Message): they would not match a ground truth label. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1) - - position_threshold = proto.Field(proto.INT32, number=14) - - recall = proto.Field(proto.FLOAT, number=2) - - precision = proto.Field(proto.FLOAT, number=3) - - false_positive_rate = proto.Field(proto.FLOAT, number=8) - - f1_score = proto.Field(proto.FLOAT, number=4) - - recall_at1 = proto.Field(proto.FLOAT, number=5) - - precision_at1 = proto.Field(proto.FLOAT, number=6) - - false_positive_rate_at1 = proto.Field(proto.FLOAT, number=9) - - f1_score_at1 = proto.Field(proto.FLOAT, number=7) - - true_positive_count = proto.Field(proto.INT64, number=10) - - false_positive_count = proto.Field(proto.INT64, number=11) - - false_negative_count = proto.Field(proto.INT64, number=12) - - true_negative_count = proto.Field(proto.INT64, number=13) + confidence_threshold = proto.Field(proto.FLOAT, number=1,) + position_threshold = proto.Field(proto.INT32, number=14,) + recall = proto.Field(proto.FLOAT, number=2,) + precision = proto.Field(proto.FLOAT, number=3,) + false_positive_rate = proto.Field(proto.FLOAT, number=8,) + f1_score = proto.Field(proto.FLOAT, number=4,) + recall_at1 = proto.Field(proto.FLOAT, number=5,) + precision_at1 = proto.Field(proto.FLOAT, number=6,) + false_positive_rate_at1 = proto.Field(proto.FLOAT, number=9,) + f1_score_at1 = proto.Field(proto.FLOAT, number=7,) + true_positive_count = proto.Field(proto.INT64, number=10,) + false_positive_count = proto.Field(proto.INT64, number=11,) + false_negative_count = proto.Field(proto.INT64, number=12,) + true_negative_count = proto.Field(proto.INT64, number=13,) class ConfusionMatrix(proto.Message): r"""Confusion matrix of the model running the classification. - Attributes: annotation_spec_id (Sequence[str]): Output only. IDs of the annotation specs used in the @@ -207,7 +189,6 @@ class ConfusionMatrix(proto.Message): class Row(proto.Message): r"""Output only. A row in the confusion matrix. - Attributes: example_count (Sequence[int]): Output only. Value of the specific cell in the confusion @@ -219,31 +200,24 @@ class Row(proto.Message): field. """ - example_count = proto.RepeatedField(proto.INT32, number=1) - - annotation_spec_id = proto.RepeatedField(proto.STRING, number=1) - - display_name = proto.RepeatedField(proto.STRING, number=3) + example_count = proto.RepeatedField(proto.INT32, number=1,) + annotation_spec_id = proto.RepeatedField(proto.STRING, number=1,) + display_name = proto.RepeatedField(proto.STRING, number=3,) row = proto.RepeatedField( proto.MESSAGE, number=2, message="ClassificationEvaluationMetrics.ConfusionMatrix.Row", ) - au_prc = proto.Field(proto.FLOAT, number=1) - - au_roc = proto.Field(proto.FLOAT, number=6) - - log_loss = proto.Field(proto.FLOAT, number=7) - + au_prc = proto.Field(proto.FLOAT, number=1,) + au_roc = proto.Field(proto.FLOAT, number=6,) + log_loss = proto.Field(proto.FLOAT, number=7,) confidence_metrics_entry = proto.RepeatedField( proto.MESSAGE, number=3, message=ConfidenceMetricsEntry, ) - confusion_matrix = proto.Field(proto.MESSAGE, number=4, message=ConfusionMatrix,) - - annotation_spec_id = proto.RepeatedField(proto.STRING, number=5) + annotation_spec_id = proto.RepeatedField(proto.STRING, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/data_items.py b/google/cloud/automl_v1/types/data_items.py index 7b292c86..aef31911 100644 --- a/google/cloud/automl_v1/types/data_items.py +++ b/google/cloud/automl_v1/types/data_items.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import geometry from google.cloud.automl_v1.types import io from google.cloud.automl_v1.types import text_segment as gca_text_segment @@ -48,14 +45,12 @@ class Image(proto.Message): Output only. HTTP URI to the thumbnail image. """ - image_bytes = proto.Field(proto.BYTES, number=1, oneof="data") - - thumbnail_uri = proto.Field(proto.STRING, number=4) + image_bytes = proto.Field(proto.BYTES, number=1, oneof="data",) + thumbnail_uri = proto.Field(proto.STRING, number=4,) class TextSnippet(proto.Message): r"""A representation of a text snippet. - Attributes: content (str): Required. The content of the text snippet as @@ -72,16 +67,13 @@ class TextSnippet(proto.Message): the content. """ - content = proto.Field(proto.STRING, number=1) - - mime_type = proto.Field(proto.STRING, number=2) - - content_uri = proto.Field(proto.STRING, number=4) + content = proto.Field(proto.STRING, number=1,) + mime_type = proto.Field(proto.STRING, number=2,) + content_uri = proto.Field(proto.STRING, number=4,) class DocumentDimensions(proto.Message): r"""Message that describes dimension of a document. - Attributes: unit (google.cloud.automl_v1.types.DocumentDimensions.DocumentDimensionUnit): Unit of the dimension. @@ -101,15 +93,12 @@ class DocumentDimensionUnit(proto.Enum): POINT = 3 unit = proto.Field(proto.ENUM, number=1, enum=DocumentDimensionUnit,) - - width = proto.Field(proto.FLOAT, number=2) - - height = proto.Field(proto.FLOAT, number=3) + width = proto.Field(proto.FLOAT, number=2,) + height = proto.Field(proto.FLOAT, number=3,) class Document(proto.Message): r"""A structured text document e.g. a PDF. - Attributes: input_config (google.cloud.automl_v1.types.DocumentInputConfig): An input config specifying the content of the @@ -173,33 +162,25 @@ class TextSegmentType(proto.Enum): text_segment = proto.Field( proto.MESSAGE, number=1, message=gca_text_segment.TextSegment, ) - - page_number = proto.Field(proto.INT32, number=2) - + page_number = proto.Field(proto.INT32, number=2,) bounding_poly = proto.Field( proto.MESSAGE, number=3, message=geometry.BoundingPoly, ) - text_segment_type = proto.Field( proto.ENUM, number=4, enum="Document.Layout.TextSegmentType", ) input_config = proto.Field(proto.MESSAGE, number=1, message=io.DocumentInputConfig,) - document_text = proto.Field(proto.MESSAGE, number=2, message="TextSnippet",) - layout = proto.RepeatedField(proto.MESSAGE, number=3, message=Layout,) - document_dimensions = proto.Field( proto.MESSAGE, number=4, message="DocumentDimensions", ) - - page_count = proto.Field(proto.INT32, number=5) + page_count = proto.Field(proto.INT32, number=5,) class ExamplePayload(proto.Message): r"""Example data used for training or prediction. - Attributes: image (google.cloud.automl_v1.types.Image): Example image. @@ -210,11 +191,9 @@ class ExamplePayload(proto.Message): """ image = proto.Field(proto.MESSAGE, number=1, oneof="payload", message="Image",) - text_snippet = proto.Field( proto.MESSAGE, number=2, oneof="payload", message="TextSnippet", ) - document = proto.Field( proto.MESSAGE, number=4, oneof="payload", message="Document", ) diff --git a/google/cloud/automl_v1/types/dataset.py b/google/cloud/automl_v1/types/dataset.py index 1cd45c39..bb19f184 100644 --- a/google/cloud/automl_v1/types/dataset.py +++ b/google/cloud/automl_v1/types/dataset.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import image from google.cloud.automl_v1.types import text from google.cloud.automl_v1.types import translation -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module(package="google.cloud.automl.v1", manifest={"Dataset",},) @@ -90,55 +87,45 @@ class Dataset(proto.Message): oneof="dataset_metadata", message=translation.TranslationDatasetMetadata, ) - image_classification_dataset_metadata = proto.Field( proto.MESSAGE, number=24, oneof="dataset_metadata", message=image.ImageClassificationDatasetMetadata, ) - text_classification_dataset_metadata = proto.Field( proto.MESSAGE, number=25, oneof="dataset_metadata", message=text.TextClassificationDatasetMetadata, ) - image_object_detection_dataset_metadata = proto.Field( proto.MESSAGE, number=26, oneof="dataset_metadata", message=image.ImageObjectDetectionDatasetMetadata, ) - text_extraction_dataset_metadata = proto.Field( proto.MESSAGE, number=28, oneof="dataset_metadata", message=text.TextExtractionDatasetMetadata, ) - text_sentiment_dataset_metadata = proto.Field( proto.MESSAGE, number=30, oneof="dataset_metadata", message=text.TextSentimentDatasetMetadata, ) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - description = proto.Field(proto.STRING, number=3) - - example_count = proto.Field(proto.INT32, number=21) - - create_time = proto.Field(proto.MESSAGE, number=14, message=timestamp.Timestamp,) - - etag = proto.Field(proto.STRING, number=17) - - labels = proto.MapField(proto.STRING, proto.STRING, number=39) + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + description = proto.Field(proto.STRING, number=3,) + example_count = proto.Field(proto.INT32, number=21,) + create_time = proto.Field( + proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + ) + etag = proto.Field(proto.STRING, number=17,) + labels = proto.MapField(proto.STRING, proto.STRING, number=39,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/detection.py b/google/cloud/automl_v1/types/detection.py index 85510cd2..92769d15 100644 --- a/google/cloud/automl_v1/types/detection.py +++ b/google/cloud/automl_v1/types/detection.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import geometry @@ -33,7 +30,6 @@ class ImageObjectDetectionAnnotation(proto.Message): r"""Annotation details for image object detection. - Attributes: bounding_box (google.cloud.automl_v1.types.BoundingPoly): Output only. The rectangle representing the @@ -45,8 +41,7 @@ class ImageObjectDetectionAnnotation(proto.Message): """ bounding_box = proto.Field(proto.MESSAGE, number=1, message=geometry.BoundingPoly,) - - score = proto.Field(proto.FLOAT, number=2) + score = proto.Field(proto.FLOAT, number=2,) class BoundingBoxMetricsEntry(proto.Message): @@ -71,7 +66,6 @@ class BoundingBoxMetricsEntry(proto.Message): class ConfidenceMetricsEntry(proto.Message): r"""Metrics for a single confidence threshold. - Attributes: confidence_threshold (float): Output only. The confidence threshold value @@ -87,18 +81,13 @@ class ConfidenceMetricsEntry(proto.Message): precision. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1) - - recall = proto.Field(proto.FLOAT, number=2) - - precision = proto.Field(proto.FLOAT, number=3) - - f1_score = proto.Field(proto.FLOAT, number=4) - - iou_threshold = proto.Field(proto.FLOAT, number=1) - - mean_average_precision = proto.Field(proto.FLOAT, number=2) + confidence_threshold = proto.Field(proto.FLOAT, number=1,) + recall = proto.Field(proto.FLOAT, number=2,) + precision = proto.Field(proto.FLOAT, number=3,) + f1_score = proto.Field(proto.FLOAT, number=4,) + iou_threshold = proto.Field(proto.FLOAT, number=1,) + mean_average_precision = proto.Field(proto.FLOAT, number=2,) confidence_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=3, message=ConfidenceMetricsEntry, ) @@ -125,13 +114,11 @@ class ImageObjectDetectionEvaluationMetrics(proto.Message): bounding_box_metrics_entries. """ - evaluated_bounding_box_count = proto.Field(proto.INT32, number=1) - + evaluated_bounding_box_count = proto.Field(proto.INT32, number=1,) bounding_box_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=2, message="BoundingBoxMetricsEntry", ) - - bounding_box_mean_average_precision = proto.Field(proto.FLOAT, number=3) + bounding_box_mean_average_precision = proto.Field(proto.FLOAT, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/geometry.py b/google/cloud/automl_v1/types/geometry.py index 80b73c89..f41f2ef5 100644 --- a/google/cloud/automl_v1/types/geometry.py +++ b/google/cloud/automl_v1/types/geometry.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -38,9 +36,8 @@ class NormalizedVertex(proto.Message): Required. Vertical coordinate. """ - x = proto.Field(proto.FLOAT, number=1) - - y = proto.Field(proto.FLOAT, number=2) + x = proto.Field(proto.FLOAT, number=1,) + y = proto.Field(proto.FLOAT, number=2,) class BoundingPoly(proto.Message): diff --git a/google/cloud/automl_v1/types/image.py b/google/cloud/automl_v1/types/image.py index 80846e42..797bd185 100644 --- a/google/cloud/automl_v1/types/image.py +++ b/google/cloud/automl_v1/types/image.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import classification @@ -36,7 +33,6 @@ class ImageClassificationDatasetMetadata(proto.Message): r"""Dataset metadata that is specific to image classification. - Attributes: classification_type (google.cloud.automl_v1.types.ClassificationType): Required. Type of the classification problem. @@ -48,12 +44,11 @@ class ImageClassificationDatasetMetadata(proto.Message): class ImageObjectDetectionDatasetMetadata(proto.Message): - r"""Dataset metadata specific to image object detection.""" + r"""Dataset metadata specific to image object detection. """ class ImageClassificationModelMetadata(proto.Message): r"""Model metadata for image classification. - Attributes: base_model_id (str): Optional. The ID of the ``base`` model. If it is specified, @@ -144,24 +139,17 @@ class ImageClassificationModelMetadata(proto.Message): handle online prediction QPS as given in the node_qps field. """ - base_model_id = proto.Field(proto.STRING, number=1) - - train_budget_milli_node_hours = proto.Field(proto.INT64, number=16) - - train_cost_milli_node_hours = proto.Field(proto.INT64, number=17) - - stop_reason = proto.Field(proto.STRING, number=5) - - model_type = proto.Field(proto.STRING, number=7) - - node_qps = proto.Field(proto.DOUBLE, number=13) - - node_count = proto.Field(proto.INT64, number=14) + base_model_id = proto.Field(proto.STRING, number=1,) + train_budget_milli_node_hours = proto.Field(proto.INT64, number=16,) + train_cost_milli_node_hours = proto.Field(proto.INT64, number=17,) + stop_reason = proto.Field(proto.STRING, number=5,) + model_type = proto.Field(proto.STRING, number=7,) + node_qps = proto.Field(proto.DOUBLE, number=13,) + node_count = proto.Field(proto.INT64, number=14,) class ImageObjectDetectionModelMetadata(proto.Message): r"""Model metadata specific to image object detection. - Attributes: model_type (str): Optional. Type of the model. The available values are: @@ -234,22 +222,16 @@ class ImageObjectDetectionModelMetadata(proto.Message): budget. """ - model_type = proto.Field(proto.STRING, number=1) - - node_count = proto.Field(proto.INT64, number=3) - - node_qps = proto.Field(proto.DOUBLE, number=4) - - stop_reason = proto.Field(proto.STRING, number=5) - - train_budget_milli_node_hours = proto.Field(proto.INT64, number=6) - - train_cost_milli_node_hours = proto.Field(proto.INT64, number=7) + model_type = proto.Field(proto.STRING, number=1,) + node_count = proto.Field(proto.INT64, number=3,) + node_qps = proto.Field(proto.DOUBLE, number=4,) + stop_reason = proto.Field(proto.STRING, number=5,) + train_budget_milli_node_hours = proto.Field(proto.INT64, number=6,) + train_cost_milli_node_hours = proto.Field(proto.INT64, number=7,) class ImageClassificationModelDeploymentMetadata(proto.Message): r"""Model deployment metadata specific to Image Classification. - Attributes: node_count (int): Input only. The number of nodes to deploy the model on. A @@ -260,12 +242,11 @@ class ImageClassificationModelDeploymentMetadata(proto.Message): Must be between 1 and 100, inclusive on both ends. """ - node_count = proto.Field(proto.INT64, number=1) + node_count = proto.Field(proto.INT64, number=1,) class ImageObjectDetectionModelDeploymentMetadata(proto.Message): r"""Model deployment metadata specific to Image Object Detection. - Attributes: node_count (int): Input only. The number of nodes to deploy the model on. A @@ -276,7 +257,7 @@ class ImageObjectDetectionModelDeploymentMetadata(proto.Message): Must be between 1 and 100, inclusive on both ends. """ - node_count = proto.Field(proto.INT64, number=1) + node_count = proto.Field(proto.INT64, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/io.py b/google/cloud/automl_v1/types/io.py index 6fad8152..cac0eec7 100644 --- a/google/cloud/automl_v1/types/io.py +++ b/google/cloud/automl_v1/types/io.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -738,8 +736,7 @@ class InputConfig(proto.Message): gcs_source = proto.Field( proto.MESSAGE, number=1, oneof="source", message="GcsSource", ) - - params = proto.MapField(proto.STRING, proto.STRING, number=2) + params = proto.MapField(proto.STRING, proto.STRING, number=2,) class BatchPredictInputConfig(proto.Message): @@ -1449,7 +1446,6 @@ class BatchPredictOutputConfig(proto.Message): class ModelExportOutputConfig(proto.Message): r"""Output configuration for ModelExport Action. - Attributes: gcs_destination (google.cloud.automl_v1.types.GcsDestination): Required. The Google Cloud Storage location where the model @@ -1516,15 +1512,12 @@ class ModelExportOutputConfig(proto.Message): gcs_destination = proto.Field( proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", ) - - model_format = proto.Field(proto.STRING, number=4) - - params = proto.MapField(proto.STRING, proto.STRING, number=2) + model_format = proto.Field(proto.STRING, number=4,) + params = proto.MapField(proto.STRING, proto.STRING, number=2,) class GcsSource(proto.Message): r"""The Google Cloud Storage location for the input content. - Attributes: input_uris (Sequence[str]): Required. Google Cloud Storage URIs to input files, up to @@ -1533,7 +1526,7 @@ class GcsSource(proto.Message): - Full object path, e.g. gs://bucket/directory/object.csv """ - input_uris = proto.RepeatedField(proto.STRING, number=1) + input_uris = proto.RepeatedField(proto.STRING, number=1,) class GcsDestination(proto.Message): @@ -1550,7 +1543,7 @@ class GcsDestination(proto.Message): is created if it doesn't exist. """ - output_uri_prefix = proto.Field(proto.STRING, number=1) + output_uri_prefix = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/model.py b/google/cloud/automl_v1/types/model.py index 6c7a9392..9d399ae7 100644 --- a/google/cloud/automl_v1/types/model.py +++ b/google/cloud/automl_v1/types/model.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import image from google.cloud.automl_v1.types import text from google.cloud.automl_v1.types import translation -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module(package="google.cloud.automl.v1", manifest={"Model",},) @@ -29,7 +26,6 @@ class Model(proto.Message): r"""API proto representing a trained machine learning model. - Attributes: translation_model_metadata (google.cloud.automl_v1.types.TranslationModelMetadata): Metadata for translation models. @@ -95,57 +91,46 @@ class DeploymentState(proto.Enum): oneof="model_metadata", message=translation.TranslationModelMetadata, ) - image_classification_model_metadata = proto.Field( proto.MESSAGE, number=13, oneof="model_metadata", message=image.ImageClassificationModelMetadata, ) - text_classification_model_metadata = proto.Field( proto.MESSAGE, number=14, oneof="model_metadata", message=text.TextClassificationModelMetadata, ) - image_object_detection_model_metadata = proto.Field( proto.MESSAGE, number=20, oneof="model_metadata", message=image.ImageObjectDetectionModelMetadata, ) - text_extraction_model_metadata = proto.Field( proto.MESSAGE, number=19, oneof="model_metadata", message=text.TextExtractionModelMetadata, ) - text_sentiment_model_metadata = proto.Field( proto.MESSAGE, number=22, oneof="model_metadata", message=text.TextSentimentModelMetadata, ) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - dataset_id = proto.Field(proto.STRING, number=3) - - create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=11, message=timestamp.Timestamp,) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + dataset_id = proto.Field(proto.STRING, number=3,) + create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) + update_time = proto.Field( + proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + ) deployment_state = proto.Field(proto.ENUM, number=8, enum=DeploymentState,) - - etag = proto.Field(proto.STRING, number=10) - - labels = proto.MapField(proto.STRING, proto.STRING, number=34) + etag = proto.Field(proto.STRING, number=10,) + labels = proto.MapField(proto.STRING, proto.STRING, number=34,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/model_evaluation.py b/google/cloud/automl_v1/types/model_evaluation.py index 51a5cfe2..94963927 100644 --- a/google/cloud/automl_v1/types/model_evaluation.py +++ b/google/cloud/automl_v1/types/model_evaluation.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import classification from google.cloud.automl_v1.types import detection from google.cloud.automl_v1.types import text_extraction from google.cloud.automl_v1.types import text_sentiment from google.cloud.automl_v1.types import translation -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -33,7 +30,6 @@ class ModelEvaluation(proto.Message): r"""Evaluation results of a model. - Attributes: classification_evaluation_metrics (google.cloud.automl_v1.types.ClassificationEvaluationMetrics): Model evaluation metrics for image, text, @@ -100,44 +96,35 @@ class ModelEvaluation(proto.Message): oneof="metrics", message=classification.ClassificationEvaluationMetrics, ) - translation_evaluation_metrics = proto.Field( proto.MESSAGE, number=9, oneof="metrics", message=translation.TranslationEvaluationMetrics, ) - image_object_detection_evaluation_metrics = proto.Field( proto.MESSAGE, number=12, oneof="metrics", message=detection.ImageObjectDetectionEvaluationMetrics, ) - text_sentiment_evaluation_metrics = proto.Field( proto.MESSAGE, number=11, oneof="metrics", message=text_sentiment.TextSentimentEvaluationMetrics, ) - text_extraction_evaluation_metrics = proto.Field( proto.MESSAGE, number=13, oneof="metrics", message=text_extraction.TextExtractionEvaluationMetrics, ) - - name = proto.Field(proto.STRING, number=1) - - annotation_spec_id = proto.Field(proto.STRING, number=2) - - display_name = proto.Field(proto.STRING, number=15) - - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - evaluated_example_count = proto.Field(proto.INT32, number=6) + name = proto.Field(proto.STRING, number=1,) + annotation_spec_id = proto.Field(proto.STRING, number=2,) + display_name = proto.Field(proto.STRING, number=15,) + create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + evaluated_example_count = proto.Field(proto.INT32, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/operations.py b/google/cloud/automl_v1/types/operations.py index d6aeee12..10d69552 100644 --- a/google/cloud/automl_v1/types/operations.py +++ b/google/cloud/automl_v1/types/operations.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import io -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.rpc import status_pb2 as status # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore __protobuf__ = proto.module( @@ -83,101 +80,88 @@ class OperationMetadata(proto.Message): delete_details = proto.Field( proto.MESSAGE, number=8, oneof="details", message="DeleteOperationMetadata", ) - deploy_model_details = proto.Field( proto.MESSAGE, number=24, oneof="details", message="DeployModelOperationMetadata", ) - undeploy_model_details = proto.Field( proto.MESSAGE, number=25, oneof="details", message="UndeployModelOperationMetadata", ) - create_model_details = proto.Field( proto.MESSAGE, number=10, oneof="details", message="CreateModelOperationMetadata", ) - create_dataset_details = proto.Field( proto.MESSAGE, number=30, oneof="details", message="CreateDatasetOperationMetadata", ) - import_data_details = proto.Field( proto.MESSAGE, number=15, oneof="details", message="ImportDataOperationMetadata", ) - batch_predict_details = proto.Field( proto.MESSAGE, number=16, oneof="details", message="BatchPredictOperationMetadata", ) - export_data_details = proto.Field( proto.MESSAGE, number=21, oneof="details", message="ExportDataOperationMetadata", ) - export_model_details = proto.Field( proto.MESSAGE, number=22, oneof="details", message="ExportModelOperationMetadata", ) - - progress_percent = proto.Field(proto.INT32, number=13) - + progress_percent = proto.Field(proto.INT32, number=13,) partial_failures = proto.RepeatedField( - proto.MESSAGE, number=2, message=status.Status, + proto.MESSAGE, number=2, message=status_pb2.Status, ) - - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) + create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) class DeleteOperationMetadata(proto.Message): - r"""Details of operations that perform deletes of any entities.""" + r"""Details of operations that perform deletes of any entities. """ class DeployModelOperationMetadata(proto.Message): - r"""Details of DeployModel operation.""" + r"""Details of DeployModel operation. """ class UndeployModelOperationMetadata(proto.Message): - r"""Details of UndeployModel operation.""" + r"""Details of UndeployModel operation. """ class CreateDatasetOperationMetadata(proto.Message): - r"""Details of CreateDataset operation.""" + r"""Details of CreateDataset operation. """ class CreateModelOperationMetadata(proto.Message): - r"""Details of CreateModel operation.""" + r"""Details of CreateModel operation. """ class ImportDataOperationMetadata(proto.Message): - r"""Details of ImportData operation.""" + r"""Details of ImportData operation. """ class ExportDataOperationMetadata(proto.Message): r"""Details of ExportData operation. - Attributes: output_info (google.cloud.automl_v1.types.ExportDataOperationMetadata.ExportDataOutputInfo): Output only. Information further describing @@ -196,7 +180,7 @@ class ExportDataOutputInfo(proto.Message): """ gcs_output_directory = proto.Field( - proto.STRING, number=1, oneof="output_location" + proto.STRING, number=1, oneof="output_location", ) output_info = proto.Field(proto.MESSAGE, number=1, message=ExportDataOutputInfo,) @@ -204,7 +188,6 @@ class ExportDataOutputInfo(proto.Message): class BatchPredictOperationMetadata(proto.Message): r"""Details of BatchPredict operation. - Attributes: input_config (google.cloud.automl_v1.types.BatchPredictInputConfig): Output only. The input config that was given @@ -227,19 +210,17 @@ class BatchPredictOutputInfo(proto.Message): """ gcs_output_directory = proto.Field( - proto.STRING, number=1, oneof="output_location" + proto.STRING, number=1, oneof="output_location", ) input_config = proto.Field( proto.MESSAGE, number=1, message=io.BatchPredictInputConfig, ) - output_info = proto.Field(proto.MESSAGE, number=2, message=BatchPredictOutputInfo,) class ExportModelOperationMetadata(proto.Message): r"""Details of ExportModel operation. - Attributes: output_info (google.cloud.automl_v1.types.ExportModelOperationMetadata.ExportModelOutputInfo): Output only. Information further describing @@ -257,7 +238,7 @@ class ExportModelOutputInfo(proto.Message): exported. """ - gcs_output_directory = proto.Field(proto.STRING, number=1) + gcs_output_directory = proto.Field(proto.STRING, number=1,) output_info = proto.Field(proto.MESSAGE, number=2, message=ExportModelOutputInfo,) diff --git a/google/cloud/automl_v1/types/prediction_service.py b/google/cloud/automl_v1/types/prediction_service.py index 9805f522..30660c69 100644 --- a/google/cloud/automl_v1/types/prediction_service.py +++ b/google/cloud/automl_v1/types/prediction_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import annotation_payload from google.cloud.automl_v1.types import data_items from google.cloud.automl_v1.types import io @@ -78,11 +75,9 @@ class PredictRequest(proto.Message): objects. The default is false. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) payload = proto.Field(proto.MESSAGE, number=2, message=data_items.ExamplePayload,) - - params = proto.MapField(proto.STRING, proto.STRING, number=3) + params = proto.MapField(proto.STRING, proto.STRING, number=3,) class PredictResponse(proto.Message): @@ -128,12 +123,10 @@ class PredictResponse(proto.Message): payload = proto.RepeatedField( proto.MESSAGE, number=1, message=annotation_payload.AnnotationPayload, ) - preprocessed_input = proto.Field( proto.MESSAGE, number=3, message=data_items.ExamplePayload, ) - - metadata = proto.MapField(proto.STRING, proto.STRING, number=2) + metadata = proto.MapField(proto.STRING, proto.STRING, number=2,) class BatchPredictRequest(proto.Message): @@ -235,17 +228,14 @@ class BatchPredictRequest(proto.Message): Default is 0. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) input_config = proto.Field( proto.MESSAGE, number=3, message=io.BatchPredictInputConfig, ) - output_config = proto.Field( proto.MESSAGE, number=4, message=io.BatchPredictOutputConfig, ) - - params = proto.MapField(proto.STRING, proto.STRING, number=5) + params = proto.MapField(proto.STRING, proto.STRING, number=5,) class BatchPredictResult(proto.Message): @@ -269,7 +259,7 @@ class BatchPredictResult(proto.Message): bounding boxes returned per frame. """ - metadata = proto.MapField(proto.STRING, proto.STRING, number=1) + metadata = proto.MapField(proto.STRING, proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/service.py b/google/cloud/automl_v1/types/service.py index bb84d854..84a11881 100644 --- a/google/cloud/automl_v1/types/service.py +++ b/google/cloud/automl_v1/types/service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import dataset as gca_dataset from google.cloud.automl_v1.types import image from google.cloud.automl_v1.types import io from google.cloud.automl_v1.types import model as gca_model from google.cloud.automl_v1.types import model_evaluation as gca_model_evaluation -from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -66,8 +63,7 @@ class CreateDatasetRequest(proto.Message): Required. The dataset to create. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) dataset = proto.Field(proto.MESSAGE, number=2, message=gca_dataset.Dataset,) @@ -81,7 +77,7 @@ class GetDatasetRequest(proto.Message): retrieve. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListDatasetsRequest(proto.Message): @@ -114,13 +110,10 @@ class ListDatasetsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListDatasetsResponse(proto.Message): @@ -143,8 +136,7 @@ def raw_page(self): datasets = proto.RepeatedField( proto.MESSAGE, number=1, message=gca_dataset.Dataset, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class UpdateDatasetRequest(proto.Message): @@ -161,8 +153,9 @@ class UpdateDatasetRequest(proto.Message): """ dataset = proto.Field(proto.MESSAGE, number=1, message=gca_dataset.Dataset,) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class DeleteDatasetRequest(proto.Message): @@ -175,7 +168,7 @@ class DeleteDatasetRequest(proto.Message): delete. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ImportDataRequest(proto.Message): @@ -192,8 +185,7 @@ class ImportDataRequest(proto.Message): domain specific semantics, if any. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) input_config = proto.Field(proto.MESSAGE, number=3, message=io.InputConfig,) @@ -208,8 +200,7 @@ class ExportDataRequest(proto.Message): Required. The desired output location. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field(proto.MESSAGE, number=3, message=io.OutputConfig,) @@ -223,7 +214,7 @@ class GetAnnotationSpecRequest(proto.Message): spec to retrieve. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateModelRequest(proto.Message): @@ -238,8 +229,7 @@ class CreateModelRequest(proto.Message): Required. The model to create. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) model = proto.Field(proto.MESSAGE, number=4, message=gca_model.Model,) @@ -252,7 +242,7 @@ class GetModelRequest(proto.Message): Required. Resource name of the model. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListModelsRequest(proto.Message): @@ -288,13 +278,10 @@ class ListModelsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListModelsResponse(proto.Message): @@ -315,8 +302,7 @@ def raw_page(self): return self model = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_model.Model,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class DeleteModelRequest(proto.Message): @@ -329,7 +315,7 @@ class DeleteModelRequest(proto.Message): deleted. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateModelRequest(proto.Message): @@ -346,8 +332,9 @@ class UpdateModelRequest(proto.Message): """ model = proto.Field(proto.MESSAGE, number=1, message=gca_model.Model,) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class DeployModelRequest(proto.Message): @@ -372,15 +359,13 @@ class DeployModelRequest(proto.Message): oneof="model_deployment_metadata", message=image.ImageObjectDetectionModelDeploymentMetadata, ) - image_classification_model_deployment_metadata = proto.Field( proto.MESSAGE, number=4, oneof="model_deployment_metadata", message=image.ImageClassificationModelDeploymentMetadata, ) - - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UndeployModelRequest(proto.Message): @@ -393,7 +378,7 @@ class UndeployModelRequest(proto.Message): undeploy. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ExportModelRequest(proto.Message): @@ -411,8 +396,7 @@ class ExportModelRequest(proto.Message): configuration. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field( proto.MESSAGE, number=3, message=io.ModelExportOutputConfig, ) @@ -428,7 +412,7 @@ class GetModelEvaluationRequest(proto.Message): evaluation. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListModelEvaluationsRequest(proto.Message): @@ -465,13 +449,10 @@ class ListModelEvaluationsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListModelEvaluationsResponse(proto.Message): @@ -497,8 +478,7 @@ def raw_page(self): model_evaluation = proto.RepeatedField( proto.MESSAGE, number=1, message=gca_model_evaluation.ModelEvaluation, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/text.py b/google/cloud/automl_v1/types/text.py index 360a4b02..a666cf46 100644 --- a/google/cloud/automl_v1/types/text.py +++ b/google/cloud/automl_v1/types/text.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import classification @@ -36,7 +33,6 @@ class TextClassificationDatasetMetadata(proto.Message): r"""Dataset metadata for classification. - Attributes: classification_type (google.cloud.automl_v1.types.ClassificationType): Required. Type of the classification problem. @@ -49,7 +45,6 @@ class TextClassificationDatasetMetadata(proto.Message): class TextClassificationModelMetadata(proto.Message): r"""Model metadata that is specific to text classification. - Attributes: classification_type (google.cloud.automl_v1.types.ClassificationType): Output only. Classification type of the @@ -62,16 +57,15 @@ class TextClassificationModelMetadata(proto.Message): class TextExtractionDatasetMetadata(proto.Message): - r"""Dataset metadata that is specific to text extraction""" + r"""Dataset metadata that is specific to text extraction """ class TextExtractionModelMetadata(proto.Message): - r"""Model metadata that is specific to text extraction.""" + r"""Model metadata that is specific to text extraction. """ class TextSentimentDatasetMetadata(proto.Message): r"""Dataset metadata for text sentiment. - Attributes: sentiment_max (int): Required. A sentiment is expressed as an integer ordinal, @@ -83,11 +77,11 @@ class TextSentimentDatasetMetadata(proto.Message): and 10 (inclusive). """ - sentiment_max = proto.Field(proto.INT32, number=1) + sentiment_max = proto.Field(proto.INT32, number=1,) class TextSentimentModelMetadata(proto.Message): - r"""Model metadata that is specific to text sentiment.""" + r"""Model metadata that is specific to text sentiment. """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/text_extraction.py b/google/cloud/automl_v1/types/text_extraction.py index 834b14ac..188c39d9 100644 --- a/google/cloud/automl_v1/types/text_extraction.py +++ b/google/cloud/automl_v1/types/text_extraction.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import text_segment as gca_text_segment @@ -29,7 +26,6 @@ class TextExtractionAnnotation(proto.Message): r"""Annotation for identifying spans of text. - Attributes: text_segment (google.cloud.automl_v1.types.TextSegment): An entity annotation will set this, which is @@ -47,13 +43,11 @@ class TextExtractionAnnotation(proto.Message): oneof="annotation", message=gca_text_segment.TextSegment, ) - - score = proto.Field(proto.FLOAT, number=1) + score = proto.Field(proto.FLOAT, number=1,) class TextExtractionEvaluationMetrics(proto.Message): r"""Model evaluation metrics for text extraction problems. - Attributes: au_prc (float): Output only. The Area under precision recall @@ -66,7 +60,6 @@ class TextExtractionEvaluationMetrics(proto.Message): class ConfidenceMetricsEntry(proto.Message): r"""Metrics for a single confidence threshold. - Attributes: confidence_threshold (float): Output only. The confidence threshold value @@ -84,16 +77,12 @@ class ConfidenceMetricsEntry(proto.Message): precision. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1) - - recall = proto.Field(proto.FLOAT, number=3) - - precision = proto.Field(proto.FLOAT, number=4) - - f1_score = proto.Field(proto.FLOAT, number=5) - - au_prc = proto.Field(proto.FLOAT, number=1) + confidence_threshold = proto.Field(proto.FLOAT, number=1,) + recall = proto.Field(proto.FLOAT, number=3,) + precision = proto.Field(proto.FLOAT, number=4,) + f1_score = proto.Field(proto.FLOAT, number=5,) + au_prc = proto.Field(proto.FLOAT, number=1,) confidence_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=2, message=ConfidenceMetricsEntry, ) diff --git a/google/cloud/automl_v1/types/text_segment.py b/google/cloud/automl_v1/types/text_segment.py index 5267a52a..ba890198 100644 --- a/google/cloud/automl_v1/types/text_segment.py +++ b/google/cloud/automl_v1/types/text_segment.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -41,11 +39,9 @@ class TextSegment(proto.Message): is NOT included in the text segment. """ - content = proto.Field(proto.STRING, number=3) - - start_offset = proto.Field(proto.INT64, number=1) - - end_offset = proto.Field(proto.INT64, number=2) + content = proto.Field(proto.STRING, number=3,) + start_offset = proto.Field(proto.INT64, number=1,) + end_offset = proto.Field(proto.INT64, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1/types/text_sentiment.py b/google/cloud/automl_v1/types/text_sentiment.py index 52dcef02..c1e50358 100644 --- a/google/cloud/automl_v1/types/text_sentiment.py +++ b/google/cloud/automl_v1/types/text_sentiment.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import classification @@ -29,7 +26,6 @@ class TextSentimentAnnotation(proto.Message): r"""Contains annotation details specific to text sentiment. - Attributes: sentiment (int): Output only. The sentiment with the semantic, as given to @@ -50,12 +46,11 @@ class TextSentimentAnnotation(proto.Message): Analysis API. """ - sentiment = proto.Field(proto.INT32, number=1) + sentiment = proto.Field(proto.INT32, number=1,) class TextSentimentEvaluationMetrics(proto.Message): r"""Model evaluation metrics for text sentiment problems. - Attributes: precision (float): Output only. Precision. @@ -87,20 +82,13 @@ class TextSentimentEvaluationMetrics(proto.Message): annotation spec. """ - precision = proto.Field(proto.FLOAT, number=1) - - recall = proto.Field(proto.FLOAT, number=2) - - f1_score = proto.Field(proto.FLOAT, number=3) - - mean_absolute_error = proto.Field(proto.FLOAT, number=4) - - mean_squared_error = proto.Field(proto.FLOAT, number=5) - - linear_kappa = proto.Field(proto.FLOAT, number=6) - - quadratic_kappa = proto.Field(proto.FLOAT, number=7) - + precision = proto.Field(proto.FLOAT, number=1,) + recall = proto.Field(proto.FLOAT, number=2,) + f1_score = proto.Field(proto.FLOAT, number=3,) + mean_absolute_error = proto.Field(proto.FLOAT, number=4,) + mean_squared_error = proto.Field(proto.FLOAT, number=5,) + linear_kappa = proto.Field(proto.FLOAT, number=6,) + quadratic_kappa = proto.Field(proto.FLOAT, number=7,) confusion_matrix = proto.Field( proto.MESSAGE, number=8, diff --git a/google/cloud/automl_v1/types/translation.py b/google/cloud/automl_v1/types/translation.py index f7b7d6ef..d2cd6dd5 100644 --- a/google/cloud/automl_v1/types/translation.py +++ b/google/cloud/automl_v1/types/translation.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1.types import data_items @@ -34,7 +31,6 @@ class TranslationDatasetMetadata(proto.Message): r"""Dataset metadata that is specific to translation. - Attributes: source_language_code (str): Required. The BCP-47 language code of the @@ -44,14 +40,12 @@ class TranslationDatasetMetadata(proto.Message): target language. """ - source_language_code = proto.Field(proto.STRING, number=1) - - target_language_code = proto.Field(proto.STRING, number=2) + source_language_code = proto.Field(proto.STRING, number=1,) + target_language_code = proto.Field(proto.STRING, number=2,) class TranslationEvaluationMetrics(proto.Message): r"""Evaluation metrics for the dataset. - Attributes: bleu_score (float): Output only. BLEU score. @@ -59,14 +53,12 @@ class TranslationEvaluationMetrics(proto.Message): Output only. BLEU score for base model. """ - bleu_score = proto.Field(proto.DOUBLE, number=1) - - base_bleu_score = proto.Field(proto.DOUBLE, number=2) + bleu_score = proto.Field(proto.DOUBLE, number=1,) + base_bleu_score = proto.Field(proto.DOUBLE, number=2,) class TranslationModelMetadata(proto.Message): r"""Model metadata that is specific to translation. - Attributes: base_model (str): The resource name of the model to use as a baseline to train @@ -82,16 +74,13 @@ class TranslationModelMetadata(proto.Message): language code) that is used for training. """ - base_model = proto.Field(proto.STRING, number=1) - - source_language_code = proto.Field(proto.STRING, number=2) - - target_language_code = proto.Field(proto.STRING, number=3) + base_model = proto.Field(proto.STRING, number=1,) + source_language_code = proto.Field(proto.STRING, number=2,) + target_language_code = proto.Field(proto.STRING, number=3,) class TranslationAnnotation(proto.Message): r"""Annotation details specific to translation. - Attributes: translated_content (google.cloud.automl_v1.types.TextSnippet): Output only . The translated content. diff --git a/google/cloud/automl_v1beta1/__init__.py b/google/cloud/automl_v1beta1/__init__.py index 904a45aa..6a9c0f56 100644 --- a/google/cloud/automl_v1beta1/__init__.py +++ b/google/cloud/automl_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +15,18 @@ # from .services.auto_ml import AutoMlClient +from .services.auto_ml import AutoMlAsyncClient from .services.prediction_service import PredictionServiceClient from .services.tables.gcs_client import GcsClient from .services.tables.tables_client import TablesClient +from .services.prediction_service import PredictionServiceAsyncClient + from .types.annotation_payload import AnnotationPayload from .types.annotation_spec import AnnotationSpec from .types.classification import ClassificationAnnotation from .types.classification import ClassificationEvaluationMetrics -from .types.classification import ClassificationType from .types.classification import VideoClassificationAnnotation +from .types.classification import ClassificationType from .types.column_spec import ColumnSpec from .types.data_items import Document from .types.data_items import DocumentDimensions @@ -142,13 +144,15 @@ from .types.video import VideoObjectTrackingDatasetMetadata from .types.video import VideoObjectTrackingModelMetadata - __all__ = ( "GcsClient", "TablesClient", + "AutoMlAsyncClient", + "PredictionServiceAsyncClient", "AnnotationPayload", "AnnotationSpec", "ArrayStats", + "AutoMlClient", "BatchPredictInputConfig", "BatchPredictOperationMetadata", "BatchPredictOutputConfig", @@ -269,5 +273,4 @@ "VideoObjectTrackingDatasetMetadata", "VideoObjectTrackingEvaluationMetrics", "VideoObjectTrackingModelMetadata", - "AutoMlClient", ) diff --git a/google/cloud/automl_v1beta1/gapic_metadata.json b/google/cloud/automl_v1beta1/gapic_metadata.json new file mode 100644 index 00000000..11f3faaa --- /dev/null +++ b/google/cloud/automl_v1beta1/gapic_metadata.json @@ -0,0 +1,297 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.automl_v1beta1", + "protoPackage": "google.cloud.automl.v1beta1", + "schema": "1.0", + "services": { + "AutoMl": { + "clients": { + "grpc": { + "libraryClient": "AutoMlClient", + "rpcs": { + "CreateDataset": { + "methods": [ + "create_dataset" + ] + }, + "CreateModel": { + "methods": [ + "create_model" + ] + }, + "DeleteDataset": { + "methods": [ + "delete_dataset" + ] + }, + "DeleteModel": { + "methods": [ + "delete_model" + ] + }, + "DeployModel": { + "methods": [ + "deploy_model" + ] + }, + "ExportData": { + "methods": [ + "export_data" + ] + }, + "ExportEvaluatedExamples": { + "methods": [ + "export_evaluated_examples" + ] + }, + "ExportModel": { + "methods": [ + "export_model" + ] + }, + "GetAnnotationSpec": { + "methods": [ + "get_annotation_spec" + ] + }, + "GetColumnSpec": { + "methods": [ + "get_column_spec" + ] + }, + "GetDataset": { + "methods": [ + "get_dataset" + ] + }, + "GetModel": { + "methods": [ + "get_model" + ] + }, + "GetModelEvaluation": { + "methods": [ + "get_model_evaluation" + ] + }, + "GetTableSpec": { + "methods": [ + "get_table_spec" + ] + }, + "ImportData": { + "methods": [ + "import_data" + ] + }, + "ListColumnSpecs": { + "methods": [ + "list_column_specs" + ] + }, + "ListDatasets": { + "methods": [ + "list_datasets" + ] + }, + "ListModelEvaluations": { + "methods": [ + "list_model_evaluations" + ] + }, + "ListModels": { + "methods": [ + "list_models" + ] + }, + "ListTableSpecs": { + "methods": [ + "list_table_specs" + ] + }, + "UndeployModel": { + "methods": [ + "undeploy_model" + ] + }, + "UpdateColumnSpec": { + "methods": [ + "update_column_spec" + ] + }, + "UpdateDataset": { + "methods": [ + "update_dataset" + ] + }, + "UpdateTableSpec": { + "methods": [ + "update_table_spec" + ] + } + } + }, + "grpc-async": { + "libraryClient": "AutoMlAsyncClient", + "rpcs": { + "CreateDataset": { + "methods": [ + "create_dataset" + ] + }, + "CreateModel": { + "methods": [ + "create_model" + ] + }, + "DeleteDataset": { + "methods": [ + "delete_dataset" + ] + }, + "DeleteModel": { + "methods": [ + "delete_model" + ] + }, + "DeployModel": { + "methods": [ + "deploy_model" + ] + }, + "ExportData": { + "methods": [ + "export_data" + ] + }, + "ExportEvaluatedExamples": { + "methods": [ + "export_evaluated_examples" + ] + }, + "ExportModel": { + "methods": [ + "export_model" + ] + }, + "GetAnnotationSpec": { + "methods": [ + "get_annotation_spec" + ] + }, + "GetColumnSpec": { + "methods": [ + "get_column_spec" + ] + }, + "GetDataset": { + "methods": [ + "get_dataset" + ] + }, + "GetModel": { + "methods": [ + "get_model" + ] + }, + "GetModelEvaluation": { + "methods": [ + "get_model_evaluation" + ] + }, + "GetTableSpec": { + "methods": [ + "get_table_spec" + ] + }, + "ImportData": { + "methods": [ + "import_data" + ] + }, + "ListColumnSpecs": { + "methods": [ + "list_column_specs" + ] + }, + "ListDatasets": { + "methods": [ + "list_datasets" + ] + }, + "ListModelEvaluations": { + "methods": [ + "list_model_evaluations" + ] + }, + "ListModels": { + "methods": [ + "list_models" + ] + }, + "ListTableSpecs": { + "methods": [ + "list_table_specs" + ] + }, + "UndeployModel": { + "methods": [ + "undeploy_model" + ] + }, + "UpdateColumnSpec": { + "methods": [ + "update_column_spec" + ] + }, + "UpdateDataset": { + "methods": [ + "update_dataset" + ] + }, + "UpdateTableSpec": { + "methods": [ + "update_table_spec" + ] + } + } + } + } + }, + "PredictionService": { + "clients": { + "grpc": { + "libraryClient": "PredictionServiceClient", + "rpcs": { + "BatchPredict": { + "methods": [ + "batch_predict" + ] + }, + "Predict": { + "methods": [ + "predict" + ] + } + } + }, + "grpc-async": { + "libraryClient": "PredictionServiceAsyncClient", + "rpcs": { + "BatchPredict": { + "methods": [ + "batch_predict" + ] + }, + "Predict": { + "methods": [ + "predict" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/automl_v1beta1/services/__init__.py b/google/cloud/automl_v1beta1/services/__init__.py index 42ffdf2b..4de65971 100644 --- a/google/cloud/automl_v1beta1/services/__init__.py +++ b/google/cloud/automl_v1beta1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/automl_v1beta1/services/auto_ml/__init__.py b/google/cloud/automl_v1beta1/services/auto_ml/__init__.py index 3324f01a..bc398205 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/__init__.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import AutoMlClient from .async_client import AutoMlAsyncClient diff --git a/google/cloud/automl_v1beta1/services/auto_ml/async_client.py b/google/cloud/automl_v1beta1/services/auto_ml/async_client.py index f610615c..fc95ef81 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/async_client.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -56,9 +54,8 @@ from google.cloud.automl_v1beta1.types import text_sentiment from google.cloud.automl_v1beta1.types import translation from google.cloud.automl_v1beta1.types import video -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import AutoMlTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AutoMlGrpcAsyncIOTransport from .client import AutoMlClient @@ -99,29 +96,25 @@ class AutoMlAsyncClient: parse_model_evaluation_path = staticmethod(AutoMlClient.parse_model_evaluation_path) table_spec_path = staticmethod(AutoMlClient.table_spec_path) parse_table_spec_path = staticmethod(AutoMlClient.parse_table_spec_path) - common_billing_account_path = staticmethod(AutoMlClient.common_billing_account_path) parse_common_billing_account_path = staticmethod( AutoMlClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(AutoMlClient.common_folder_path) parse_common_folder_path = staticmethod(AutoMlClient.parse_common_folder_path) - common_organization_path = staticmethod(AutoMlClient.common_organization_path) parse_common_organization_path = staticmethod( AutoMlClient.parse_common_organization_path ) - common_project_path = staticmethod(AutoMlClient.common_project_path) parse_common_project_path = staticmethod(AutoMlClient.parse_common_project_path) - common_location_path = staticmethod(AutoMlClient.common_location_path) parse_common_location_path = staticmethod(AutoMlClient.parse_common_location_path) @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -136,7 +129,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -153,7 +146,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AutoMlTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: AutoMlTransport: The transport used by the client instance. @@ -167,12 +160,12 @@ def transport(self) -> AutoMlTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, AutoMlTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the auto ml client. + """Instantiates the auto ml client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -204,7 +197,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = AutoMlClient( credentials=credentials, transport=transport, @@ -240,7 +232,6 @@ async def create_dataset( This corresponds to the ``dataset`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -269,7 +260,6 @@ async def create_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if dataset is not None: @@ -317,7 +307,6 @@ async def get_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -346,7 +335,6 @@ async def get_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -359,7 +347,8 @@ async def get_dataset( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -401,7 +390,6 @@ async def list_datasets( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -431,7 +419,6 @@ async def list_datasets( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -444,7 +431,8 @@ async def list_datasets( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -492,7 +480,6 @@ async def update_dataset( This corresponds to the ``dataset`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -521,7 +508,6 @@ async def update_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if dataset is not None: request.dataset = dataset @@ -573,7 +559,6 @@ async def delete_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -613,7 +598,6 @@ async def delete_dataset( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -626,7 +610,8 @@ async def delete_dataset( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -647,7 +632,7 @@ async def delete_dataset( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -695,7 +680,6 @@ async def import_data( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -735,7 +719,6 @@ async def import_data( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -762,7 +745,7 @@ async def import_data( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -802,7 +785,6 @@ async def export_data( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -842,7 +824,6 @@ async def export_data( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -869,7 +850,7 @@ async def export_data( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -898,7 +879,6 @@ async def get_annotation_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -923,7 +903,6 @@ async def get_annotation_spec( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -936,7 +915,8 @@ async def get_annotation_spec( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -978,7 +958,6 @@ async def get_table_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1013,7 +992,6 @@ async def get_table_spec( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1026,7 +1004,8 @@ async def get_table_spec( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1068,7 +1047,6 @@ async def list_table_specs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1098,7 +1076,6 @@ async def list_table_specs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1111,7 +1088,8 @@ async def list_table_specs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1159,7 +1137,6 @@ async def update_table_spec( This corresponds to the ``table_spec`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1194,7 +1171,6 @@ async def update_table_spec( # If we have keyword arguments corresponding to fields on the # request, apply these. - if table_spec is not None: request.table_spec = table_spec @@ -1242,7 +1218,6 @@ async def get_column_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1269,7 +1244,6 @@ async def get_column_spec( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1282,7 +1256,8 @@ async def get_column_spec( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1324,7 +1299,6 @@ async def list_column_specs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1354,7 +1328,6 @@ async def list_column_specs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1367,7 +1340,8 @@ async def list_column_specs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1415,7 +1389,6 @@ async def update_column_spec( This corresponds to the ``column_spec`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1442,7 +1415,6 @@ async def update_column_spec( # If we have keyword arguments corresponding to fields on the # request, apply these. - if column_spec is not None: request.column_spec = column_spec @@ -1501,7 +1473,6 @@ async def create_model( This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1531,7 +1502,6 @@ async def create_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if model is not None: @@ -1585,7 +1555,6 @@ async def get_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1612,7 +1581,6 @@ async def get_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1625,7 +1593,8 @@ async def get_model( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1667,7 +1636,6 @@ async def list_models( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1697,7 +1665,6 @@ async def list_models( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1710,7 +1677,8 @@ async def list_models( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1761,7 +1729,6 @@ async def delete_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1801,7 +1768,6 @@ async def delete_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1814,7 +1780,8 @@ async def delete_model( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -1835,7 +1802,7 @@ async def delete_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1878,7 +1845,6 @@ async def deploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1918,7 +1884,6 @@ async def deploy_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1943,7 +1908,7 @@ async def deploy_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1980,7 +1945,6 @@ async def undeploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2020,7 +1984,6 @@ async def undeploy_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2045,7 +2008,7 @@ async def undeploy_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2092,7 +2055,6 @@ async def export_model( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2132,7 +2094,6 @@ async def export_model( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -2159,7 +2120,7 @@ async def export_model( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2211,7 +2172,6 @@ async def export_evaluated_examples( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2251,7 +2211,6 @@ async def export_evaluated_examples( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -2278,7 +2237,7 @@ async def export_evaluated_examples( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2307,7 +2266,6 @@ async def get_model_evaluation( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2332,7 +2290,6 @@ async def get_model_evaluation( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2345,7 +2302,8 @@ async def get_model_evaluation( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -2390,7 +2348,6 @@ async def list_model_evaluations( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2420,7 +2377,6 @@ async def list_model_evaluations( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent diff --git a/google/cloud/automl_v1beta1/services/auto_ml/client.py b/google/cloud/automl_v1beta1/services/auto_ml/client.py index 16b0e7cf..52e296a4 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/client.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -60,9 +58,8 @@ from google.cloud.automl_v1beta1.types import text_sentiment from google.cloud.automl_v1beta1.types import translation from google.cloud.automl_v1beta1.types import video -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import AutoMlTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AutoMlGrpcTransport from .transports.grpc_asyncio import AutoMlGrpcAsyncIOTransport @@ -81,7 +78,7 @@ class AutoMlClientMeta(type): _transport_registry["grpc_asyncio"] = AutoMlGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[AutoMlTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -119,7 +116,8 @@ class AutoMlClient(metaclass=AutoMlClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -153,7 +151,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -170,7 +169,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -189,10 +188,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AutoMlTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - AutoMlTransport: The transport used by the client instance. + AutoMlTransport: The transport used by the client + instance. """ return self._transport @@ -200,7 +200,7 @@ def transport(self) -> AutoMlTransport: def annotation_spec_path( project: str, location: str, dataset: str, annotation_spec: str, ) -> str: - """Return a fully-qualified annotation_spec string.""" + """Returns a fully-qualified annotation_spec string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}".format( project=project, location=location, @@ -210,7 +210,7 @@ def annotation_spec_path( @staticmethod def parse_annotation_spec_path(path: str) -> Dict[str, str]: - """Parse a annotation_spec path into its component segments.""" + """Parses a annotation_spec path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/annotationSpecs/(?P.+?)$", path, @@ -221,7 +221,7 @@ def parse_annotation_spec_path(path: str) -> Dict[str, str]: def column_spec_path( project: str, location: str, dataset: str, table_spec: str, column_spec: str, ) -> str: - """Return a fully-qualified column_spec string.""" + """Returns a fully-qualified column_spec string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/tableSpecs/{table_spec}/columnSpecs/{column_spec}".format( project=project, location=location, @@ -232,7 +232,7 @@ def column_spec_path( @staticmethod def parse_column_spec_path(path: str) -> Dict[str, str]: - """Parse a column_spec path into its component segments.""" + """Parses a column_spec path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/tableSpecs/(?P.+?)/columnSpecs/(?P.+?)$", path, @@ -241,14 +241,14 @@ def parse_column_spec_path(path: str) -> Dict[str, str]: @staticmethod def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( project=project, location=location, dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -257,14 +257,14 @@ def parse_dataset_path(path: str) -> Dict[str, str]: @staticmethod def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -275,7 +275,7 @@ def parse_model_path(path: str) -> Dict[str, str]: def model_evaluation_path( project: str, location: str, model: str, model_evaluation: str, ) -> str: - """Return a fully-qualified model_evaluation string.""" + """Returns a fully-qualified model_evaluation string.""" return "projects/{project}/locations/{location}/models/{model}/modelEvaluations/{model_evaluation}".format( project=project, location=location, @@ -285,7 +285,7 @@ def model_evaluation_path( @staticmethod def parse_model_evaluation_path(path: str) -> Dict[str, str]: - """Parse a model_evaluation path into its component segments.""" + """Parses a model_evaluation path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)/modelEvaluations/(?P.+?)$", path, @@ -296,14 +296,14 @@ def parse_model_evaluation_path(path: str) -> Dict[str, str]: def table_spec_path( project: str, location: str, dataset: str, table_spec: str, ) -> str: - """Return a fully-qualified table_spec string.""" + """Returns a fully-qualified table_spec string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/tableSpecs/{table_spec}".format( project=project, location=location, dataset=dataset, table_spec=table_spec, ) @staticmethod def parse_table_spec_path(path: str) -> Dict[str, str]: - """Parse a table_spec path into its component segments.""" + """Parses a table_spec path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/tableSpecs/(?P.+?)$", path, @@ -312,7 +312,7 @@ def parse_table_spec_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -325,7 +325,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -336,7 +336,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -347,7 +347,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -358,7 +358,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -372,12 +372,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, AutoMlTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the auto ml client. + """Instantiates the auto ml client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -432,9 +432,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -446,12 +447,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -466,8 +469,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -510,7 +513,6 @@ def create_dataset( This corresponds to the ``dataset`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -541,10 +543,8 @@ def create_dataset( # there are no flattened fields. if not isinstance(request, service.CreateDatasetRequest): request = service.CreateDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if dataset is not None: @@ -588,7 +588,6 @@ def get_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -619,10 +618,8 @@ def get_dataset( # there are no flattened fields. if not isinstance(request, service.GetDatasetRequest): request = service.GetDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -664,7 +661,6 @@ def list_datasets( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -696,10 +692,8 @@ def list_datasets( # there are no flattened fields. if not isinstance(request, service.ListDatasetsRequest): request = service.ListDatasetsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -747,7 +741,6 @@ def update_dataset( This corresponds to the ``dataset`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -778,10 +771,8 @@ def update_dataset( # there are no flattened fields. if not isinstance(request, service.UpdateDatasetRequest): request = service.UpdateDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if dataset is not None: request.dataset = dataset @@ -829,7 +820,6 @@ def delete_dataset( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -871,10 +861,8 @@ def delete_dataset( # there are no flattened fields. if not isinstance(request, service.DeleteDatasetRequest): request = service.DeleteDatasetRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -895,7 +883,7 @@ def delete_dataset( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -943,7 +931,6 @@ def import_data( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -985,10 +972,8 @@ def import_data( # there are no flattened fields. if not isinstance(request, service.ImportDataRequest): request = service.ImportDataRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -1011,7 +996,7 @@ def import_data( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1051,7 +1036,6 @@ def export_data( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1093,10 +1077,8 @@ def export_data( # there are no flattened fields. if not isinstance(request, service.ExportDataRequest): request = service.ExportDataRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -1119,7 +1101,7 @@ def export_data( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -1148,7 +1130,6 @@ def get_annotation_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1175,10 +1156,8 @@ def get_annotation_spec( # there are no flattened fields. if not isinstance(request, service.GetAnnotationSpecRequest): request = service.GetAnnotationSpecRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1220,7 +1199,6 @@ def get_table_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1257,10 +1235,8 @@ def get_table_spec( # there are no flattened fields. if not isinstance(request, service.GetTableSpecRequest): request = service.GetTableSpecRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1302,7 +1278,6 @@ def list_table_specs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1334,10 +1309,8 @@ def list_table_specs( # there are no flattened fields. if not isinstance(request, service.ListTableSpecsRequest): request = service.ListTableSpecsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1385,7 +1358,6 @@ def update_table_spec( This corresponds to the ``table_spec`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1422,10 +1394,8 @@ def update_table_spec( # there are no flattened fields. if not isinstance(request, service.UpdateTableSpecRequest): request = service.UpdateTableSpecRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if table_spec is not None: request.table_spec = table_spec @@ -1469,7 +1439,6 @@ def get_column_spec( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1498,10 +1467,8 @@ def get_column_spec( # there are no flattened fields. if not isinstance(request, service.GetColumnSpecRequest): request = service.GetColumnSpecRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1543,7 +1510,6 @@ def list_column_specs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1575,10 +1541,8 @@ def list_column_specs( # there are no flattened fields. if not isinstance(request, service.ListColumnSpecsRequest): request = service.ListColumnSpecsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1626,7 +1590,6 @@ def update_column_spec( This corresponds to the ``column_spec`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1655,10 +1618,8 @@ def update_column_spec( # there are no flattened fields. if not isinstance(request, service.UpdateColumnSpecRequest): request = service.UpdateColumnSpecRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if column_spec is not None: request.column_spec = column_spec @@ -1713,7 +1674,6 @@ def create_model( This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1745,10 +1705,8 @@ def create_model( # there are no flattened fields. if not isinstance(request, service.CreateModelRequest): request = service.CreateModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if model is not None: @@ -1798,7 +1756,6 @@ def get_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1827,10 +1784,8 @@ def get_model( # there are no flattened fields. if not isinstance(request, service.GetModelRequest): request = service.GetModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1872,7 +1827,6 @@ def list_models( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1904,10 +1858,8 @@ def list_models( # there are no flattened fields. if not isinstance(request, service.ListModelsRequest): request = service.ListModelsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1958,7 +1910,6 @@ def delete_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2000,10 +1951,8 @@ def delete_model( # there are no flattened fields. if not isinstance(request, service.DeleteModelRequest): request = service.DeleteModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2024,7 +1973,7 @@ def delete_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2067,7 +2016,6 @@ def deploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2109,10 +2057,8 @@ def deploy_model( # there are no flattened fields. if not isinstance(request, service.DeployModelRequest): request = service.DeployModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2133,7 +2079,7 @@ def deploy_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2170,7 +2116,6 @@ def undeploy_model( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2212,10 +2157,8 @@ def undeploy_model( # there are no flattened fields. if not isinstance(request, service.UndeployModelRequest): request = service.UndeployModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2236,7 +2179,7 @@ def undeploy_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2283,7 +2226,6 @@ def export_model( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2325,10 +2267,8 @@ def export_model( # there are no flattened fields. if not isinstance(request, service.ExportModelRequest): request = service.ExportModelRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -2351,7 +2291,7 @@ def export_model( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2403,7 +2343,6 @@ def export_evaluated_examples( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2445,10 +2384,8 @@ def export_evaluated_examples( # there are no flattened fields. if not isinstance(request, service.ExportEvaluatedExamplesRequest): request = service.ExportEvaluatedExamplesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -2473,7 +2410,7 @@ def export_evaluated_examples( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadata, ) @@ -2502,7 +2439,6 @@ def get_model_evaluation( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2529,10 +2465,8 @@ def get_model_evaluation( # there are no flattened fields. if not isinstance(request, service.GetModelEvaluationRequest): request = service.GetModelEvaluationRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -2577,7 +2511,6 @@ def list_model_evaluations( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2609,10 +2542,8 @@ def list_model_evaluations( # there are no flattened fields. if not isinstance(request, service.ListModelEvaluationsRequest): request = service.ListModelEvaluationsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent diff --git a/google/cloud/automl_v1beta1/services/auto_ml/pagers.py b/google/cloud/automl_v1beta1/services/auto_ml/pagers.py index 10233877..dcc5e642 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/pagers.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -122,7 +120,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -250,7 +248,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -378,7 +376,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -506,7 +504,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -634,7 +632,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/automl_v1beta1/services/auto_ml/transports/__init__.py b/google/cloud/automl_v1beta1/services/auto_ml/transports/__init__.py index 946bdb5f..f0c466d9 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/transports/__init__.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py b/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py index bc7c22ea..51e46c9b 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,17 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.automl_v1beta1.types import annotation_spec from google.cloud.automl_v1beta1.types import column_spec @@ -36,8 +36,7 @@ from google.cloud.automl_v1beta1.types import service from google.cloud.automl_v1beta1.types import table_spec from google.cloud.automl_v1beta1.types import table_spec as gca_table_spec -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -46,27 +45,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class AutoMlTransport(abc.ABC): """Abstract transport class for AutoMl.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "automl.googleapis.com" + def __init__( self, *, - host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -75,7 +88,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -89,29 +102,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -125,7 +185,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -139,7 +200,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -156,7 +218,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -176,7 +239,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -190,7 +254,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -204,7 +269,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -221,7 +287,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -235,7 +302,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -255,7 +323,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -269,7 +338,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -283,7 +353,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -311,7 +382,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=5.0, ), @@ -333,76 +405,72 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def create_dataset( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateDatasetRequest], - typing.Union[gca_dataset.Dataset, typing.Awaitable[gca_dataset.Dataset]], + Union[gca_dataset.Dataset, Awaitable[gca_dataset.Dataset]], ]: raise NotImplementedError() @property def get_dataset( self, - ) -> typing.Callable[ - [service.GetDatasetRequest], - typing.Union[dataset.Dataset, typing.Awaitable[dataset.Dataset]], + ) -> Callable[ + [service.GetDatasetRequest], Union[dataset.Dataset, Awaitable[dataset.Dataset]] ]: raise NotImplementedError() @property def list_datasets( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListDatasetsRequest], - typing.Union[ - service.ListDatasetsResponse, typing.Awaitable[service.ListDatasetsResponse] - ], + Union[service.ListDatasetsResponse, Awaitable[service.ListDatasetsResponse]], ]: raise NotImplementedError() @property def update_dataset( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdateDatasetRequest], - typing.Union[gca_dataset.Dataset, typing.Awaitable[gca_dataset.Dataset]], + Union[gca_dataset.Dataset, Awaitable[gca_dataset.Dataset]], ]: raise NotImplementedError() @property def delete_dataset( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteDatasetRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def import_data( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ImportDataRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_data( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ExportDataRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_annotation_spec( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetAnnotationSpecRequest], - typing.Union[ - annotation_spec.AnnotationSpec, - typing.Awaitable[annotation_spec.AnnotationSpec], + Union[ + annotation_spec.AnnotationSpec, Awaitable[annotation_spec.AnnotationSpec] ], ]: raise NotImplementedError() @@ -410,20 +478,19 @@ def get_annotation_spec( @property def get_table_spec( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetTableSpecRequest], - typing.Union[table_spec.TableSpec, typing.Awaitable[table_spec.TableSpec]], + Union[table_spec.TableSpec, Awaitable[table_spec.TableSpec]], ]: raise NotImplementedError() @property def list_table_specs( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListTableSpecsRequest], - typing.Union[ - service.ListTableSpecsResponse, - typing.Awaitable[service.ListTableSpecsResponse], + Union[ + service.ListTableSpecsResponse, Awaitable[service.ListTableSpecsResponse] ], ]: raise NotImplementedError() @@ -431,31 +498,28 @@ def list_table_specs( @property def update_table_spec( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdateTableSpecRequest], - typing.Union[ - gca_table_spec.TableSpec, typing.Awaitable[gca_table_spec.TableSpec] - ], + Union[gca_table_spec.TableSpec, Awaitable[gca_table_spec.TableSpec]], ]: raise NotImplementedError() @property def get_column_spec( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetColumnSpecRequest], - typing.Union[column_spec.ColumnSpec, typing.Awaitable[column_spec.ColumnSpec]], + Union[column_spec.ColumnSpec, Awaitable[column_spec.ColumnSpec]], ]: raise NotImplementedError() @property def list_column_specs( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListColumnSpecsRequest], - typing.Union[ - service.ListColumnSpecsResponse, - typing.Awaitable[service.ListColumnSpecsResponse], + Union[ + service.ListColumnSpecsResponse, Awaitable[service.ListColumnSpecsResponse] ], ]: raise NotImplementedError() @@ -463,96 +527,91 @@ def list_column_specs( @property def update_column_spec( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdateColumnSpecRequest], - typing.Union[ - gca_column_spec.ColumnSpec, typing.Awaitable[gca_column_spec.ColumnSpec] - ], + Union[gca_column_spec.ColumnSpec, Awaitable[gca_column_spec.ColumnSpec]], ]: raise NotImplementedError() @property def create_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_model( self, - ) -> typing.Callable[ - [service.GetModelRequest], - typing.Union[model.Model, typing.Awaitable[model.Model]], + ) -> Callable[ + [service.GetModelRequest], Union[model.Model, Awaitable[model.Model]] ]: raise NotImplementedError() @property def list_models( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListModelsRequest], - typing.Union[ - service.ListModelsResponse, typing.Awaitable[service.ListModelsResponse] - ], + Union[service.ListModelsResponse, Awaitable[service.ListModelsResponse]], ]: raise NotImplementedError() @property def delete_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def deploy_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeployModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def undeploy_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UndeployModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_model( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ExportModelRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_evaluated_examples( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ExportEvaluatedExamplesRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def get_model_evaluation( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetModelEvaluationRequest], - typing.Union[ + Union[ model_evaluation.ModelEvaluation, - typing.Awaitable[model_evaluation.ModelEvaluation], + Awaitable[model_evaluation.ModelEvaluation], ], ]: raise NotImplementedError() @@ -560,11 +619,11 @@ def get_model_evaluation( @property def list_model_evaluations( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListModelEvaluationsRequest], - typing.Union[ + Union[ service.ListModelEvaluationsResponse, - typing.Awaitable[service.ListModelEvaluationsResponse], + Awaitable[service.ListModelEvaluationsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py b/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py index 9a03b53c..ba8bf68e 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore @@ -37,8 +35,7 @@ from google.cloud.automl_v1beta1.types import service from google.cloud.automl_v1beta1.types import table_spec from google.cloud.automl_v1beta1.types import table_spec as gca_table_spec -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import AutoMlTransport, DEFAULT_CLIENT_INFO @@ -75,7 +72,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -89,7 +86,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -200,7 +198,7 @@ def __init__( def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -231,13 +229,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -366,7 +366,7 @@ def update_dataset( @property def delete_dataset( self, - ) -> Callable[[service.DeleteDatasetRequest], operations.Operation]: + ) -> Callable[[service.DeleteDatasetRequest], operations_pb2.Operation]: r"""Return a callable for the delete dataset method over gRPC. Deletes a dataset and all of its contents. Returns empty @@ -389,14 +389,14 @@ def delete_dataset( self._stubs["delete_dataset"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/DeleteDataset", request_serializer=service.DeleteDatasetRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_dataset"] @property def import_data( self, - ) -> Callable[[service.ImportDataRequest], operations.Operation]: + ) -> Callable[[service.ImportDataRequest], operations_pb2.Operation]: r"""Return a callable for the import data method over gRPC. Imports data into a dataset. For Tables this method can only be @@ -424,14 +424,14 @@ def import_data( self._stubs["import_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ImportData", request_serializer=service.ImportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_data"] @property def export_data( self, - ) -> Callable[[service.ExportDataRequest], operations.Operation]: + ) -> Callable[[service.ExportDataRequest], operations_pb2.Operation]: r"""Return a callable for the export data method over gRPC. Exports dataset's data to the provided output location. Returns @@ -453,7 +453,7 @@ def export_data( self._stubs["export_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ExportData", request_serializer=service.ExportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_data"] @@ -642,7 +642,7 @@ def update_column_spec( @property def create_model( self, - ) -> Callable[[service.CreateModelRequest], operations.Operation]: + ) -> Callable[[service.CreateModelRequest], operations_pb2.Operation]: r"""Return a callable for the create model method over gRPC. Creates a model. Returns a Model in the @@ -665,7 +665,7 @@ def create_model( self._stubs["create_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/CreateModel", request_serializer=service.CreateModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_model"] @@ -722,7 +722,7 @@ def list_models( @property def delete_model( self, - ) -> Callable[[service.DeleteModelRequest], operations.Operation]: + ) -> Callable[[service.DeleteModelRequest], operations_pb2.Operation]: r"""Return a callable for the delete model method over gRPC. Deletes a model. Returns ``google.protobuf.Empty`` in the @@ -744,14 +744,14 @@ def delete_model( self._stubs["delete_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/DeleteModel", request_serializer=service.DeleteModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_model"] @property def deploy_model( self, - ) -> Callable[[service.DeployModelRequest], operations.Operation]: + ) -> Callable[[service.DeployModelRequest], operations_pb2.Operation]: r"""Return a callable for the deploy model method over gRPC. Deploys a model. If a model is already deployed, deploying it @@ -784,14 +784,14 @@ def deploy_model( self._stubs["deploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/DeployModel", request_serializer=service.DeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["deploy_model"] @property def undeploy_model( self, - ) -> Callable[[service.UndeployModelRequest], operations.Operation]: + ) -> Callable[[service.UndeployModelRequest], operations_pb2.Operation]: r"""Return a callable for the undeploy model method over gRPC. Undeploys a model. If the model is not deployed this method has @@ -818,14 +818,14 @@ def undeploy_model( self._stubs["undeploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/UndeployModel", request_serializer=service.UndeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["undeploy_model"] @property def export_model( self, - ) -> Callable[[service.ExportModelRequest], operations.Operation]: + ) -> Callable[[service.ExportModelRequest], operations_pb2.Operation]: r"""Return a callable for the export model method over gRPC. Exports a trained, "export-able", model to a user specified @@ -852,14 +852,14 @@ def export_model( self._stubs["export_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ExportModel", request_serializer=service.ExportModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_model"] @property def export_evaluated_examples( self, - ) -> Callable[[service.ExportEvaluatedExamplesRequest], operations.Operation]: + ) -> Callable[[service.ExportEvaluatedExamplesRequest], operations_pb2.Operation]: r"""Return a callable for the export evaluated examples method over gRPC. Exports examples on which the model was evaluated (i.e. which @@ -892,7 +892,7 @@ def export_evaluated_examples( self._stubs["export_evaluated_examples"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ExportEvaluatedExamples", request_serializer=service.ExportEvaluatedExamplesRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_evaluated_examples"] diff --git a/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py b/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py index 4f2781a0..e451c09b 100644 --- a/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py +++ b/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -38,8 +36,7 @@ from google.cloud.automl_v1beta1.types import service from google.cloud.automl_v1beta1.types import table_spec from google.cloud.automl_v1beta1.types import table_spec as gca_table_spec -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import AutoMlTransport, DEFAULT_CLIENT_INFO from .grpc import AutoMlGrpcTransport @@ -78,7 +75,7 @@ class AutoMlGrpcAsyncIOTransport(AutoMlTransport): def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -105,13 +102,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -119,7 +118,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -133,7 +132,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -192,7 +192,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -376,7 +375,7 @@ def update_dataset( @property def delete_dataset( self, - ) -> Callable[[service.DeleteDatasetRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeleteDatasetRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete dataset method over gRPC. Deletes a dataset and all of its contents. Returns empty @@ -399,14 +398,14 @@ def delete_dataset( self._stubs["delete_dataset"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/DeleteDataset", request_serializer=service.DeleteDatasetRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_dataset"] @property def import_data( self, - ) -> Callable[[service.ImportDataRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ImportDataRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the import data method over gRPC. Imports data into a dataset. For Tables this method can only be @@ -434,14 +433,14 @@ def import_data( self._stubs["import_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ImportData", request_serializer=service.ImportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_data"] @property def export_data( self, - ) -> Callable[[service.ExportDataRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ExportDataRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the export data method over gRPC. Exports dataset's data to the provided output location. Returns @@ -463,7 +462,7 @@ def export_data( self._stubs["export_data"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ExportData", request_serializer=service.ExportDataRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_data"] @@ -662,7 +661,7 @@ def update_column_spec( @property def create_model( self, - ) -> Callable[[service.CreateModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.CreateModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the create model method over gRPC. Creates a model. Returns a Model in the @@ -685,7 +684,7 @@ def create_model( self._stubs["create_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/CreateModel", request_serializer=service.CreateModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_model"] @@ -742,7 +741,7 @@ def list_models( @property def delete_model( self, - ) -> Callable[[service.DeleteModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeleteModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete model method over gRPC. Deletes a model. Returns ``google.protobuf.Empty`` in the @@ -764,14 +763,14 @@ def delete_model( self._stubs["delete_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/DeleteModel", request_serializer=service.DeleteModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_model"] @property def deploy_model( self, - ) -> Callable[[service.DeployModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeployModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the deploy model method over gRPC. Deploys a model. If a model is already deployed, deploying it @@ -804,14 +803,14 @@ def deploy_model( self._stubs["deploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/DeployModel", request_serializer=service.DeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["deploy_model"] @property def undeploy_model( self, - ) -> Callable[[service.UndeployModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.UndeployModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the undeploy model method over gRPC. Undeploys a model. If the model is not deployed this method has @@ -838,14 +837,14 @@ def undeploy_model( self._stubs["undeploy_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/UndeployModel", request_serializer=service.UndeployModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["undeploy_model"] @property def export_model( self, - ) -> Callable[[service.ExportModelRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ExportModelRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the export model method over gRPC. Exports a trained, "export-able", model to a user specified @@ -872,7 +871,7 @@ def export_model( self._stubs["export_model"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ExportModel", request_serializer=service.ExportModelRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_model"] @@ -880,7 +879,7 @@ def export_model( def export_evaluated_examples( self, ) -> Callable[ - [service.ExportEvaluatedExamplesRequest], Awaitable[operations.Operation] + [service.ExportEvaluatedExamplesRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the export evaluated examples method over gRPC. @@ -914,7 +913,7 @@ def export_evaluated_examples( self._stubs["export_evaluated_examples"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.AutoMl/ExportEvaluatedExamples", request_serializer=service.ExportEvaluatedExamplesRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_evaluated_examples"] diff --git a/google/cloud/automl_v1beta1/services/prediction_service/__init__.py b/google/cloud/automl_v1beta1/services/prediction_service/__init__.py index 0c847693..12491bb1 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/__init__.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import PredictionServiceClient from .async_client import PredictionServiceAsyncClient diff --git a/google/cloud/automl_v1beta1/services/prediction_service/async_client.py b/google/cloud/automl_v1beta1/services/prediction_service/async_client.py index 265c896a..0d0d8c56 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/async_client.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -35,7 +33,6 @@ from google.cloud.automl_v1beta1.types import io from google.cloud.automl_v1beta1.types import operations from google.cloud.automl_v1beta1.types import prediction_service - from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport from .client import PredictionServiceClient @@ -55,31 +52,26 @@ class PredictionServiceAsyncClient: model_path = staticmethod(PredictionServiceClient.model_path) parse_model_path = staticmethod(PredictionServiceClient.parse_model_path) - common_billing_account_path = staticmethod( PredictionServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( PredictionServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(PredictionServiceClient.common_folder_path) parse_common_folder_path = staticmethod( PredictionServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( PredictionServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( PredictionServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(PredictionServiceClient.common_project_path) parse_common_project_path = staticmethod( PredictionServiceClient.parse_common_project_path ) - common_location_path = staticmethod(PredictionServiceClient.common_location_path) parse_common_location_path = staticmethod( PredictionServiceClient.parse_common_location_path @@ -87,7 +79,8 @@ class PredictionServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -102,7 +95,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -119,7 +112,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: PredictionServiceTransport: The transport used by the client instance. @@ -133,12 +126,12 @@ def transport(self) -> PredictionServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, PredictionServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -170,7 +163,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = PredictionServiceClient( credentials=credentials, transport=transport, @@ -258,7 +250,6 @@ async def predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -285,7 +276,6 @@ async def predict( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if payload is not None: @@ -458,7 +448,6 @@ async def batch_predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -489,7 +478,6 @@ async def batch_predict( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: diff --git a/google/cloud/automl_v1beta1/services/prediction_service/client.py b/google/cloud/automl_v1beta1/services/prediction_service/client.py index a1e74ba4..d5968efc 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/client.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -39,7 +37,6 @@ from google.cloud.automl_v1beta1.types import io from google.cloud.automl_v1beta1.types import operations from google.cloud.automl_v1beta1.types import prediction_service - from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import PredictionServiceGrpcTransport from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport @@ -62,7 +59,7 @@ class PredictionServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[PredictionServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -89,7 +86,8 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -123,7 +121,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -140,7 +139,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -159,23 +158,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - PredictionServiceTransport: The transport used by the client instance. + PredictionServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -184,7 +184,7 @@ def parse_model_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -197,7 +197,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -208,7 +208,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -219,7 +219,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -230,7 +230,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -244,12 +244,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, PredictionServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -304,9 +304,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -318,12 +319,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -338,8 +341,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -434,7 +437,6 @@ def predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -463,10 +465,8 @@ def predict( # there are no flattened fields. if not isinstance(request, prediction_service.PredictRequest): request = prediction_service.PredictRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if payload is not None: @@ -634,7 +634,6 @@ def batch_predict( This corresponds to the ``params`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -667,10 +666,8 @@ def batch_predict( # there are no flattened fields. if not isinstance(request, prediction_service.BatchPredictRequest): request = prediction_service.BatchPredictRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: diff --git a/google/cloud/automl_v1beta1/services/prediction_service/transports/__init__.py b/google/cloud/automl_v1beta1/services/prediction_service/transports/__init__.py index 9ec1369a..86d2e8a7 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/transports/__init__.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py b/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py index 0efb4539..d918f002 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.automl_v1beta1.types import prediction_service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class PredictionServiceTransport(abc.ABC): """Abstract transport class for PredictionService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "automl.googleapis.com" + def __init__( self, *, - host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -66,7 +79,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -80,29 +93,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -122,11 +182,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def predict( self, - ) -> typing.Callable[ + ) -> Callable[ [prediction_service.PredictRequest], - typing.Union[ + Union[ prediction_service.PredictResponse, - typing.Awaitable[prediction_service.PredictResponse], + Awaitable[prediction_service.PredictResponse], ], ]: raise NotImplementedError() @@ -134,9 +194,9 @@ def predict( @property def batch_predict( self, - ) -> typing.Callable[ + ) -> Callable[ [prediction_service.BatchPredictRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py b/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py index 5074f5b2..6eb3ed15 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.automl_v1beta1.types import prediction_service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO @@ -55,7 +52,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -69,7 +66,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -180,7 +178,7 @@ def __init__( def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -211,13 +209,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -292,7 +292,7 @@ def predict( @property def batch_predict( self, - ) -> Callable[[prediction_service.BatchPredictRequest], operations.Operation]: + ) -> Callable[[prediction_service.BatchPredictRequest], operations_pb2.Operation]: r"""Return a callable for the batch predict method over gRPC. Perform a batch prediction. Unlike the online @@ -327,7 +327,7 @@ def batch_predict( self._stubs["batch_predict"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.PredictionService/BatchPredict", request_serializer=prediction_service.BatchPredictRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["batch_predict"] diff --git a/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py b/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py index dfd52483..8b43a0c8 100644 --- a/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py +++ b/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.automl_v1beta1.types import prediction_service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .grpc import PredictionServiceGrpcTransport @@ -58,7 +55,7 @@ class PredictionServiceGrpcAsyncIOTransport(PredictionServiceTransport): def create_channel( cls, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -85,13 +82,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -99,7 +98,7 @@ def __init__( self, *, host: str = "automl.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -113,7 +112,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -172,7 +172,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -300,7 +299,7 @@ def predict( def batch_predict( self, ) -> Callable[ - [prediction_service.BatchPredictRequest], Awaitable[operations.Operation] + [prediction_service.BatchPredictRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the batch predict method over gRPC. @@ -336,7 +335,7 @@ def batch_predict( self._stubs["batch_predict"] = self.grpc_channel.unary_unary( "/google.cloud.automl.v1beta1.PredictionService/BatchPredict", request_serializer=prediction_service.BatchPredictRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["batch_predict"] diff --git a/google/cloud/automl_v1beta1/types/__init__.py b/google/cloud/automl_v1beta1/types/__init__.py index 1072fb32..ed173401 100644 --- a/google/cloud/automl_v1beta1/types/__init__.py +++ b/google/cloud/automl_v1beta1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .annotation_payload import AnnotationPayload from .annotation_spec import AnnotationSpec from .classification import ( diff --git a/google/cloud/automl_v1beta1/types/annotation_payload.py b/google/cloud/automl_v1beta1/types/annotation_payload.py index 84bae153..e1e9b12a 100644 --- a/google/cloud/automl_v1beta1/types/annotation_payload.py +++ b/google/cloud/automl_v1beta1/types/annotation_payload.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import classification as gca_classification from google.cloud.automl_v1beta1.types import detection from google.cloud.automl_v1beta1.types import tables as gca_tables @@ -33,7 +30,6 @@ class AnnotationPayload(proto.Message): r"""Contains annotation information that is relevant to AutoML. - Attributes: translation (google.cloud.automl_v1beta1.types.TranslationAnnotation): Annotation details for translation. @@ -76,56 +72,47 @@ class AnnotationPayload(proto.Message): oneof="detail", message=gca_translation.TranslationAnnotation, ) - classification = proto.Field( proto.MESSAGE, number=3, oneof="detail", message=gca_classification.ClassificationAnnotation, ) - image_object_detection = proto.Field( proto.MESSAGE, number=4, oneof="detail", message=detection.ImageObjectDetectionAnnotation, ) - video_classification = proto.Field( proto.MESSAGE, number=9, oneof="detail", message=gca_classification.VideoClassificationAnnotation, ) - video_object_tracking = proto.Field( proto.MESSAGE, number=8, oneof="detail", message=detection.VideoObjectTrackingAnnotation, ) - text_extraction = proto.Field( proto.MESSAGE, number=6, oneof="detail", message=gca_text_extraction.TextExtractionAnnotation, ) - text_sentiment = proto.Field( proto.MESSAGE, number=7, oneof="detail", message=gca_text_sentiment.TextSentimentAnnotation, ) - tables = proto.Field( proto.MESSAGE, number=10, oneof="detail", message=gca_tables.TablesAnnotation, ) - - annotation_spec_id = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=5) + annotation_spec_id = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/annotation_spec.py b/google/cloud/automl_v1beta1/types/annotation_spec.py index bb810acd..7481ac52 100644 --- a/google/cloud/automl_v1beta1/types/annotation_spec.py +++ b/google/cloud/automl_v1beta1/types/annotation_spec.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -25,7 +23,6 @@ class AnnotationSpec(proto.Message): r"""A definition of an annotation spec. - Attributes: name (str): Output only. Resource name of the annotation spec. Form: @@ -40,11 +37,9 @@ class AnnotationSpec(proto.Message): parent dataset labeled by the annotation spec. """ - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - example_count = proto.Field(proto.INT32, number=9) + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + example_count = proto.Field(proto.INT32, number=9,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/classification.py b/google/cloud/automl_v1beta1/types/classification.py index 20f3b4a6..356aef21 100644 --- a/google/cloud/automl_v1beta1/types/classification.py +++ b/google/cloud/automl_v1beta1/types/classification.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import temporal @@ -41,7 +38,6 @@ class ClassificationType(proto.Enum): class ClassificationAnnotation(proto.Message): r"""Contains annotation details specific to classification. - Attributes: score (float): Output only. A confidence estimate between @@ -53,12 +49,11 @@ class ClassificationAnnotation(proto.Message): negative or 1 for positive. """ - score = proto.Field(proto.FLOAT, number=1) + score = proto.Field(proto.FLOAT, number=1,) class VideoClassificationAnnotation(proto.Message): r"""Contains annotation details specific to video classification. - Attributes: type_ (str): Output only. Expresses the type of video classification. @@ -96,12 +91,10 @@ class VideoClassificationAnnotation(proto.Message): to which the annotation applies. """ - type_ = proto.Field(proto.STRING, number=1) - + type_ = proto.Field(proto.STRING, number=1,) classification_annotation = proto.Field( proto.MESSAGE, number=2, message="ClassificationAnnotation", ) - time_segment = proto.Field(proto.MESSAGE, number=3, message=temporal.TimeSegment,) @@ -147,7 +140,6 @@ class ClassificationEvaluationMetrics(proto.Message): class ConfidenceMetricsEntry(proto.Message): r"""Metrics for a single confidence threshold. - Attributes: confidence_threshold (float): Output only. Metrics are computed with an @@ -206,37 +198,23 @@ class ConfidenceMetricsEntry(proto.Message): they would not match a ground truth label. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1) - - position_threshold = proto.Field(proto.INT32, number=14) - - recall = proto.Field(proto.FLOAT, number=2) - - precision = proto.Field(proto.FLOAT, number=3) - - false_positive_rate = proto.Field(proto.FLOAT, number=8) - - f1_score = proto.Field(proto.FLOAT, number=4) - - recall_at1 = proto.Field(proto.FLOAT, number=5) - - precision_at1 = proto.Field(proto.FLOAT, number=6) - - false_positive_rate_at1 = proto.Field(proto.FLOAT, number=9) - - f1_score_at1 = proto.Field(proto.FLOAT, number=7) - - true_positive_count = proto.Field(proto.INT64, number=10) - - false_positive_count = proto.Field(proto.INT64, number=11) - - false_negative_count = proto.Field(proto.INT64, number=12) - - true_negative_count = proto.Field(proto.INT64, number=13) + confidence_threshold = proto.Field(proto.FLOAT, number=1,) + position_threshold = proto.Field(proto.INT32, number=14,) + recall = proto.Field(proto.FLOAT, number=2,) + precision = proto.Field(proto.FLOAT, number=3,) + false_positive_rate = proto.Field(proto.FLOAT, number=8,) + f1_score = proto.Field(proto.FLOAT, number=4,) + recall_at1 = proto.Field(proto.FLOAT, number=5,) + precision_at1 = proto.Field(proto.FLOAT, number=6,) + false_positive_rate_at1 = proto.Field(proto.FLOAT, number=9,) + f1_score_at1 = proto.Field(proto.FLOAT, number=7,) + true_positive_count = proto.Field(proto.INT64, number=10,) + false_positive_count = proto.Field(proto.INT64, number=11,) + false_negative_count = proto.Field(proto.INT64, number=12,) + true_negative_count = proto.Field(proto.INT64, number=13,) class ConfusionMatrix(proto.Message): r"""Confusion matrix of the model running the classification. - Attributes: annotation_spec_id (Sequence[str]): Output only. IDs of the annotation specs used in the @@ -264,7 +242,6 @@ class ConfusionMatrix(proto.Message): class Row(proto.Message): r"""Output only. A row in the confusion matrix. - Attributes: example_count (Sequence[int]): Output only. Value of the specific cell in the confusion @@ -276,33 +253,25 @@ class Row(proto.Message): field. """ - example_count = proto.RepeatedField(proto.INT32, number=1) - - annotation_spec_id = proto.RepeatedField(proto.STRING, number=1) - - display_name = proto.RepeatedField(proto.STRING, number=3) + example_count = proto.RepeatedField(proto.INT32, number=1,) + annotation_spec_id = proto.RepeatedField(proto.STRING, number=1,) + display_name = proto.RepeatedField(proto.STRING, number=3,) row = proto.RepeatedField( proto.MESSAGE, number=2, message="ClassificationEvaluationMetrics.ConfusionMatrix.Row", ) - au_prc = proto.Field(proto.FLOAT, number=1) - - base_au_prc = proto.Field(proto.FLOAT, number=2) - - au_roc = proto.Field(proto.FLOAT, number=6) - - log_loss = proto.Field(proto.FLOAT, number=7) - + au_prc = proto.Field(proto.FLOAT, number=1,) + base_au_prc = proto.Field(proto.FLOAT, number=2,) + au_roc = proto.Field(proto.FLOAT, number=6,) + log_loss = proto.Field(proto.FLOAT, number=7,) confidence_metrics_entry = proto.RepeatedField( proto.MESSAGE, number=3, message=ConfidenceMetricsEntry, ) - confusion_matrix = proto.Field(proto.MESSAGE, number=4, message=ConfusionMatrix,) - - annotation_spec_id = proto.RepeatedField(proto.STRING, number=5) + annotation_spec_id = proto.RepeatedField(proto.STRING, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/column_spec.py b/google/cloud/automl_v1beta1/types/column_spec.py index 40d6976f..bed285de 100644 --- a/google/cloud/automl_v1beta1/types/column_spec.py +++ b/google/cloud/automl_v1beta1/types/column_spec.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import data_stats as gca_data_stats from google.cloud.automl_v1beta1.types import data_types @@ -74,25 +71,19 @@ class CorrelatedColumn(proto.Message): column. """ - column_spec_id = proto.Field(proto.STRING, number=1) - + column_spec_id = proto.Field(proto.STRING, number=1,) correlation_stats = proto.Field( proto.MESSAGE, number=2, message=gca_data_stats.CorrelationStats, ) - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) data_type = proto.Field(proto.MESSAGE, number=2, message=data_types.DataType,) - - display_name = proto.Field(proto.STRING, number=3) - + display_name = proto.Field(proto.STRING, number=3,) data_stats = proto.Field(proto.MESSAGE, number=4, message=gca_data_stats.DataStats,) - top_correlated_columns = proto.RepeatedField( proto.MESSAGE, number=5, message=CorrelatedColumn, ) - - etag = proto.Field(proto.STRING, number=6) + etag = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/data_items.py b/google/cloud/automl_v1beta1/types/data_items.py index 098ad147..3ac72882 100644 --- a/google/cloud/automl_v1beta1/types/data_items.py +++ b/google/cloud/automl_v1beta1/types/data_items.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import geometry from google.cloud.automl_v1beta1.types import io from google.cloud.automl_v1beta1.types import text_segment as gca_text_segment -from google.protobuf import struct_pb2 as struct # type: ignore +from google.protobuf import struct_pb2 # type: ignore __protobuf__ = proto.module( @@ -53,18 +50,15 @@ class Image(proto.Message): Output only. HTTP URI to the thumbnail image. """ - image_bytes = proto.Field(proto.BYTES, number=1, oneof="data") - + image_bytes = proto.Field(proto.BYTES, number=1, oneof="data",) input_config = proto.Field( proto.MESSAGE, number=6, oneof="data", message=io.InputConfig, ) - - thumbnail_uri = proto.Field(proto.STRING, number=4) + thumbnail_uri = proto.Field(proto.STRING, number=4,) class TextSnippet(proto.Message): r"""A representation of a text snippet. - Attributes: content (str): Required. The content of the text snippet as @@ -81,16 +75,13 @@ class TextSnippet(proto.Message): the content. """ - content = proto.Field(proto.STRING, number=1) - - mime_type = proto.Field(proto.STRING, number=2) - - content_uri = proto.Field(proto.STRING, number=4) + content = proto.Field(proto.STRING, number=1,) + mime_type = proto.Field(proto.STRING, number=2,) + content_uri = proto.Field(proto.STRING, number=4,) class DocumentDimensions(proto.Message): r"""Message that describes dimension of a document. - Attributes: unit (google.cloud.automl_v1beta1.types.DocumentDimensions.DocumentDimensionUnit): Unit of the dimension. @@ -110,15 +101,12 @@ class DocumentDimensionUnit(proto.Enum): POINT = 3 unit = proto.Field(proto.ENUM, number=1, enum=DocumentDimensionUnit,) - - width = proto.Field(proto.FLOAT, number=2) - - height = proto.Field(proto.FLOAT, number=3) + width = proto.Field(proto.FLOAT, number=2,) + height = proto.Field(proto.FLOAT, number=3,) class Document(proto.Message): r"""A structured text document e.g. a PDF. - Attributes: input_config (google.cloud.automl_v1beta1.types.DocumentInputConfig): An input config specifying the content of the @@ -182,33 +170,25 @@ class TextSegmentType(proto.Enum): text_segment = proto.Field( proto.MESSAGE, number=1, message=gca_text_segment.TextSegment, ) - - page_number = proto.Field(proto.INT32, number=2) - + page_number = proto.Field(proto.INT32, number=2,) bounding_poly = proto.Field( proto.MESSAGE, number=3, message=geometry.BoundingPoly, ) - text_segment_type = proto.Field( proto.ENUM, number=4, enum="Document.Layout.TextSegmentType", ) input_config = proto.Field(proto.MESSAGE, number=1, message=io.DocumentInputConfig,) - document_text = proto.Field(proto.MESSAGE, number=2, message="TextSnippet",) - layout = proto.RepeatedField(proto.MESSAGE, number=3, message=Layout,) - document_dimensions = proto.Field( proto.MESSAGE, number=4, message="DocumentDimensions", ) - - page_count = proto.Field(proto.INT32, number=5) + page_count = proto.Field(proto.INT32, number=5,) class Row(proto.Message): r"""A representation of a row in a relational table. - Attributes: column_spec_ids (Sequence[str]): The resource IDs of the column specs describing the columns @@ -228,14 +208,12 @@ class Row(proto.Message): of the Model this row is being passed to. """ - column_spec_ids = proto.RepeatedField(proto.STRING, number=2) - - values = proto.RepeatedField(proto.MESSAGE, number=3, message=struct.Value,) + column_spec_ids = proto.RepeatedField(proto.STRING, number=2,) + values = proto.RepeatedField(proto.MESSAGE, number=3, message=struct_pb2.Value,) class ExamplePayload(proto.Message): r"""Example data used for training or prediction. - Attributes: image (google.cloud.automl_v1beta1.types.Image): Example image. @@ -248,15 +226,12 @@ class ExamplePayload(proto.Message): """ image = proto.Field(proto.MESSAGE, number=1, oneof="payload", message="Image",) - text_snippet = proto.Field( proto.MESSAGE, number=2, oneof="payload", message="TextSnippet", ) - document = proto.Field( proto.MESSAGE, number=4, oneof="payload", message="Document", ) - row = proto.Field(proto.MESSAGE, number=3, oneof="payload", message="Row",) diff --git a/google/cloud/automl_v1beta1/types/data_stats.py b/google/cloud/automl_v1beta1/types/data_stats.py index e6c60cd0..f8a890b2 100644 --- a/google/cloud/automl_v1beta1/types/data_stats.py +++ b/google/cloud/automl_v1beta1/types/data_stats.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -61,37 +59,28 @@ class DataStats(proto.Message): float64_stats = proto.Field( proto.MESSAGE, number=3, oneof="stats", message="Float64Stats", ) - string_stats = proto.Field( proto.MESSAGE, number=4, oneof="stats", message="StringStats", ) - timestamp_stats = proto.Field( proto.MESSAGE, number=5, oneof="stats", message="TimestampStats", ) - array_stats = proto.Field( proto.MESSAGE, number=6, oneof="stats", message="ArrayStats", ) - struct_stats = proto.Field( proto.MESSAGE, number=7, oneof="stats", message="StructStats", ) - category_stats = proto.Field( proto.MESSAGE, number=8, oneof="stats", message="CategoryStats", ) - - distinct_value_count = proto.Field(proto.INT64, number=1) - - null_value_count = proto.Field(proto.INT64, number=2) - - valid_value_count = proto.Field(proto.INT64, number=9) + distinct_value_count = proto.Field(proto.INT64, number=1,) + null_value_count = proto.Field(proto.INT64, number=2,) + valid_value_count = proto.Field(proto.INT64, number=9,) class Float64Stats(proto.Message): r"""The data statistics of a series of FLOAT64 values. - Attributes: mean (float): The mean of the series. @@ -113,7 +102,6 @@ class Float64Stats(proto.Message): class HistogramBucket(proto.Message): r"""A bucket of a histogram. - Attributes: min_ (float): The minimum value of the bucket, inclusive. @@ -125,18 +113,13 @@ class HistogramBucket(proto.Message): bucket, i.e. are between min and max values. """ - min_ = proto.Field(proto.DOUBLE, number=1) - - max_ = proto.Field(proto.DOUBLE, number=2) - - count = proto.Field(proto.INT64, number=3) - - mean = proto.Field(proto.DOUBLE, number=1) - - standard_deviation = proto.Field(proto.DOUBLE, number=2) - - quantiles = proto.RepeatedField(proto.DOUBLE, number=3) + min_ = proto.Field(proto.DOUBLE, number=1,) + max_ = proto.Field(proto.DOUBLE, number=2,) + count = proto.Field(proto.INT64, number=3,) + mean = proto.Field(proto.DOUBLE, number=1,) + standard_deviation = proto.Field(proto.DOUBLE, number=2,) + quantiles = proto.RepeatedField(proto.DOUBLE, number=3,) histogram_buckets = proto.RepeatedField( proto.MESSAGE, number=4, message=HistogramBucket, ) @@ -144,7 +127,6 @@ class HistogramBucket(proto.Message): class StringStats(proto.Message): r"""The data statistics of a series of STRING values. - Attributes: top_unigram_stats (Sequence[google.cloud.automl_v1beta1.types.StringStats.UnigramStats]): The statistics of the top 20 unigrams, ordered by @@ -153,7 +135,6 @@ class StringStats(proto.Message): class UnigramStats(proto.Message): r"""The statistics of a unigram. - Attributes: value (str): The unigram. @@ -162,9 +143,8 @@ class UnigramStats(proto.Message): the series. """ - value = proto.Field(proto.STRING, number=1) - - count = proto.Field(proto.INT64, number=2) + value = proto.Field(proto.STRING, number=1,) + count = proto.Field(proto.INT64, number=2,) top_unigram_stats = proto.RepeatedField( proto.MESSAGE, number=1, message=UnigramStats, @@ -173,7 +153,6 @@ class UnigramStats(proto.Message): class TimestampStats(proto.Message): r"""The data statistics of a series of TIMESTAMP values. - Attributes: granular_stats (Sequence[google.cloud.automl_v1beta1.types.TimestampStats.GranularStatsEntry]): The string key is the pre-defined granularity. Currently @@ -185,7 +164,6 @@ class TimestampStats(proto.Message): class GranularStats(proto.Message): r"""Stats split by a defined in context granularity. - Attributes: buckets (Sequence[google.cloud.automl_v1beta1.types.TimestampStats.GranularStats.BucketsEntry]): A map from granularity key to example count for that key. @@ -193,7 +171,7 @@ class GranularStats(proto.Message): ``5`` means May). """ - buckets = proto.MapField(proto.INT32, proto.INT64, number=1) + buckets = proto.MapField(proto.INT32, proto.INT64, number=1,) granular_stats = proto.MapField( proto.STRING, proto.MESSAGE, number=1, message=GranularStats, @@ -202,7 +180,6 @@ class GranularStats(proto.Message): class ArrayStats(proto.Message): r"""The data statistics of a series of ARRAY values. - Attributes: member_stats (google.cloud.automl_v1beta1.types.DataStats): Stats of all the values of all arrays, as if @@ -215,7 +192,6 @@ class ArrayStats(proto.Message): class StructStats(proto.Message): r"""The data statistics of a series of STRUCT values. - Attributes: field_stats (Sequence[google.cloud.automl_v1beta1.types.StructStats.FieldStatsEntry]): Map from a field name of the struct to data @@ -230,7 +206,6 @@ class StructStats(proto.Message): class CategoryStats(proto.Message): r"""The data statistics of a series of CATEGORY values. - Attributes: top_category_stats (Sequence[google.cloud.automl_v1beta1.types.CategoryStats.SingleCategoryStats]): The statistics of the top 20 CATEGORY values, ordered by @@ -240,7 +215,6 @@ class CategoryStats(proto.Message): class SingleCategoryStats(proto.Message): r"""The statistics of a single CATEGORY value. - Attributes: value (str): The CATEGORY value. @@ -249,9 +223,8 @@ class SingleCategoryStats(proto.Message): the series. """ - value = proto.Field(proto.STRING, number=1) - - count = proto.Field(proto.INT64, number=2) + value = proto.Field(proto.STRING, number=1,) + count = proto.Field(proto.INT64, number=2,) top_category_stats = proto.RepeatedField( proto.MESSAGE, number=1, message=SingleCategoryStats, @@ -269,7 +242,7 @@ class CorrelationStats(proto.Message): measure. """ - cramers_v = proto.Field(proto.DOUBLE, number=1) + cramers_v = proto.Field(proto.DOUBLE, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/data_types.py b/google/cloud/automl_v1beta1/types/data_types.py index 9b335aeb..877cd4fe 100644 --- a/google/cloud/automl_v1beta1/types/data_types.py +++ b/google/cloud/automl_v1beta1/types/data_types.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -81,16 +79,12 @@ class DataType(proto.Message): list_element_type = proto.Field( proto.MESSAGE, number=2, oneof="details", message="DataType", ) - struct_type = proto.Field( proto.MESSAGE, number=3, oneof="details", message="StructType", ) - - time_format = proto.Field(proto.STRING, number=5, oneof="details") - + time_format = proto.Field(proto.STRING, number=5, oneof="details",) type_code = proto.Field(proto.ENUM, number=1, enum="TypeCode",) - - nullable = proto.Field(proto.BOOL, number=4) + nullable = proto.Field(proto.BOOL, number=4,) class StructType(proto.Message): diff --git a/google/cloud/automl_v1beta1/types/dataset.py b/google/cloud/automl_v1beta1/types/dataset.py index 438dc794..3cba50bc 100644 --- a/google/cloud/automl_v1beta1/types/dataset.py +++ b/google/cloud/automl_v1beta1/types/dataset.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import image from google.cloud.automl_v1beta1.types import tables from google.cloud.automl_v1beta1.types import text from google.cloud.automl_v1beta1.types import translation from google.cloud.automl_v1beta1.types import video -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -91,74 +88,62 @@ class Dataset(proto.Message): oneof="dataset_metadata", message=translation.TranslationDatasetMetadata, ) - image_classification_dataset_metadata = proto.Field( proto.MESSAGE, number=24, oneof="dataset_metadata", message=image.ImageClassificationDatasetMetadata, ) - text_classification_dataset_metadata = proto.Field( proto.MESSAGE, number=25, oneof="dataset_metadata", message=text.TextClassificationDatasetMetadata, ) - image_object_detection_dataset_metadata = proto.Field( proto.MESSAGE, number=26, oneof="dataset_metadata", message=image.ImageObjectDetectionDatasetMetadata, ) - video_classification_dataset_metadata = proto.Field( proto.MESSAGE, number=31, oneof="dataset_metadata", message=video.VideoClassificationDatasetMetadata, ) - video_object_tracking_dataset_metadata = proto.Field( proto.MESSAGE, number=29, oneof="dataset_metadata", message=video.VideoObjectTrackingDatasetMetadata, ) - text_extraction_dataset_metadata = proto.Field( proto.MESSAGE, number=28, oneof="dataset_metadata", message=text.TextExtractionDatasetMetadata, ) - text_sentiment_dataset_metadata = proto.Field( proto.MESSAGE, number=30, oneof="dataset_metadata", message=text.TextSentimentDatasetMetadata, ) - tables_dataset_metadata = proto.Field( proto.MESSAGE, number=33, oneof="dataset_metadata", message=tables.TablesDatasetMetadata, ) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - description = proto.Field(proto.STRING, number=3) - - example_count = proto.Field(proto.INT32, number=21) - - create_time = proto.Field(proto.MESSAGE, number=14, message=timestamp.Timestamp,) - - etag = proto.Field(proto.STRING, number=17) + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + description = proto.Field(proto.STRING, number=3,) + example_count = proto.Field(proto.INT32, number=21,) + create_time = proto.Field( + proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + ) + etag = proto.Field(proto.STRING, number=17,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/detection.py b/google/cloud/automl_v1beta1/types/detection.py index 849b6c7b..5f1cba6d 100644 --- a/google/cloud/automl_v1beta1/types/detection.py +++ b/google/cloud/automl_v1beta1/types/detection.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import geometry -from google.protobuf import duration_pb2 as duration # type: ignore +from google.protobuf import duration_pb2 # type: ignore __protobuf__ = proto.module( @@ -36,7 +33,6 @@ class ImageObjectDetectionAnnotation(proto.Message): r"""Annotation details for image object detection. - Attributes: bounding_box (google.cloud.automl_v1beta1.types.BoundingPoly): Output only. The rectangle representing the @@ -48,13 +44,11 @@ class ImageObjectDetectionAnnotation(proto.Message): """ bounding_box = proto.Field(proto.MESSAGE, number=1, message=geometry.BoundingPoly,) - - score = proto.Field(proto.FLOAT, number=2) + score = proto.Field(proto.FLOAT, number=2,) class VideoObjectTrackingAnnotation(proto.Message): r"""Annotation details for video object tracking. - Attributes: instance_id (str): Optional. The instance of the object, @@ -83,13 +77,10 @@ class VideoObjectTrackingAnnotation(proto.Message): changed to 1). """ - instance_id = proto.Field(proto.STRING, number=1) - - time_offset = proto.Field(proto.MESSAGE, number=2, message=duration.Duration,) - + instance_id = proto.Field(proto.STRING, number=1,) + time_offset = proto.Field(proto.MESSAGE, number=2, message=duration_pb2.Duration,) bounding_box = proto.Field(proto.MESSAGE, number=3, message=geometry.BoundingPoly,) - - score = proto.Field(proto.FLOAT, number=4) + score = proto.Field(proto.FLOAT, number=4,) class BoundingBoxMetricsEntry(proto.Message): @@ -114,7 +105,6 @@ class BoundingBoxMetricsEntry(proto.Message): class ConfidenceMetricsEntry(proto.Message): r"""Metrics for a single confidence threshold. - Attributes: confidence_threshold (float): Output only. The confidence threshold value @@ -130,18 +120,13 @@ class ConfidenceMetricsEntry(proto.Message): precision. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1) - - recall = proto.Field(proto.FLOAT, number=2) - - precision = proto.Field(proto.FLOAT, number=3) - - f1_score = proto.Field(proto.FLOAT, number=4) - - iou_threshold = proto.Field(proto.FLOAT, number=1) - - mean_average_precision = proto.Field(proto.FLOAT, number=2) + confidence_threshold = proto.Field(proto.FLOAT, number=1,) + recall = proto.Field(proto.FLOAT, number=2,) + precision = proto.Field(proto.FLOAT, number=3,) + f1_score = proto.Field(proto.FLOAT, number=4,) + iou_threshold = proto.Field(proto.FLOAT, number=1,) + mean_average_precision = proto.Field(proto.FLOAT, number=2,) confidence_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=3, message=ConfidenceMetricsEntry, ) @@ -168,13 +153,11 @@ class ImageObjectDetectionEvaluationMetrics(proto.Message): bounding_box_metrics_entries. """ - evaluated_bounding_box_count = proto.Field(proto.INT32, number=1) - + evaluated_bounding_box_count = proto.Field(proto.INT32, number=1,) bounding_box_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=2, message="BoundingBoxMetricsEntry", ) - - bounding_box_mean_average_precision = proto.Field(proto.FLOAT, number=3) + bounding_box_mean_average_precision = proto.Field(proto.FLOAT, number=3,) class VideoObjectTrackingEvaluationMetrics(proto.Message): @@ -203,15 +186,12 @@ class VideoObjectTrackingEvaluationMetrics(proto.Message): bounding_box_metrics_entries. """ - evaluated_frame_count = proto.Field(proto.INT32, number=1) - - evaluated_bounding_box_count = proto.Field(proto.INT32, number=2) - + evaluated_frame_count = proto.Field(proto.INT32, number=1,) + evaluated_bounding_box_count = proto.Field(proto.INT32, number=2,) bounding_box_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=4, message="BoundingBoxMetricsEntry", ) - - bounding_box_mean_average_precision = proto.Field(proto.FLOAT, number=6) + bounding_box_mean_average_precision = proto.Field(proto.FLOAT, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/geometry.py b/google/cloud/automl_v1beta1/types/geometry.py index 004b34bb..70be40be 100644 --- a/google/cloud/automl_v1beta1/types/geometry.py +++ b/google/cloud/automl_v1beta1/types/geometry.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -39,9 +37,8 @@ class NormalizedVertex(proto.Message): Required. Vertical coordinate. """ - x = proto.Field(proto.FLOAT, number=1) - - y = proto.Field(proto.FLOAT, number=2) + x = proto.Field(proto.FLOAT, number=1,) + y = proto.Field(proto.FLOAT, number=2,) class BoundingPoly(proto.Message): diff --git a/google/cloud/automl_v1beta1/types/image.py b/google/cloud/automl_v1beta1/types/image.py index f34e6fba..689b8a4f 100644 --- a/google/cloud/automl_v1beta1/types/image.py +++ b/google/cloud/automl_v1beta1/types/image.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import classification @@ -36,7 +33,6 @@ class ImageClassificationDatasetMetadata(proto.Message): r"""Dataset metadata that is specific to image classification. - Attributes: classification_type (google.cloud.automl_v1beta1.types.ClassificationType): Required. Type of the classification problem. @@ -48,12 +44,11 @@ class ImageClassificationDatasetMetadata(proto.Message): class ImageObjectDetectionDatasetMetadata(proto.Message): - r"""Dataset metadata specific to image object detection.""" + r"""Dataset metadata specific to image object detection. """ class ImageClassificationModelMetadata(proto.Message): r"""Model metadata for image classification. - Attributes: base_model_id (str): Optional. The ID of the ``base`` model. If it is specified, @@ -128,24 +123,17 @@ class ImageClassificationModelMetadata(proto.Message): handle online prediction QPS as given in the node_qps field. """ - base_model_id = proto.Field(proto.STRING, number=1) - - train_budget = proto.Field(proto.INT64, number=2) - - train_cost = proto.Field(proto.INT64, number=3) - - stop_reason = proto.Field(proto.STRING, number=5) - - model_type = proto.Field(proto.STRING, number=7) - - node_qps = proto.Field(proto.DOUBLE, number=13) - - node_count = proto.Field(proto.INT64, number=14) + base_model_id = proto.Field(proto.STRING, number=1,) + train_budget = proto.Field(proto.INT64, number=2,) + train_cost = proto.Field(proto.INT64, number=3,) + stop_reason = proto.Field(proto.STRING, number=5,) + model_type = proto.Field(proto.STRING, number=7,) + node_qps = proto.Field(proto.DOUBLE, number=13,) + node_count = proto.Field(proto.INT64, number=14,) class ImageObjectDetectionModelMetadata(proto.Message): r"""Model metadata specific to image object detection. - Attributes: model_type (str): Optional. Type of the model. The available values are: @@ -218,22 +206,16 @@ class ImageObjectDetectionModelMetadata(proto.Message): budget. """ - model_type = proto.Field(proto.STRING, number=1) - - node_count = proto.Field(proto.INT64, number=3) - - node_qps = proto.Field(proto.DOUBLE, number=4) - - stop_reason = proto.Field(proto.STRING, number=5) - - train_budget_milli_node_hours = proto.Field(proto.INT64, number=6) - - train_cost_milli_node_hours = proto.Field(proto.INT64, number=7) + model_type = proto.Field(proto.STRING, number=1,) + node_count = proto.Field(proto.INT64, number=3,) + node_qps = proto.Field(proto.DOUBLE, number=4,) + stop_reason = proto.Field(proto.STRING, number=5,) + train_budget_milli_node_hours = proto.Field(proto.INT64, number=6,) + train_cost_milli_node_hours = proto.Field(proto.INT64, number=7,) class ImageClassificationModelDeploymentMetadata(proto.Message): r"""Model deployment metadata specific to Image Classification. - Attributes: node_count (int): Input only. The number of nodes to deploy the model on. A @@ -244,12 +226,11 @@ class ImageClassificationModelDeploymentMetadata(proto.Message): Must be between 1 and 100, inclusive on both ends. """ - node_count = proto.Field(proto.INT64, number=1) + node_count = proto.Field(proto.INT64, number=1,) class ImageObjectDetectionModelDeploymentMetadata(proto.Message): r"""Model deployment metadata specific to Image Object Detection. - Attributes: node_count (int): Input only. The number of nodes to deploy the model on. A @@ -260,7 +241,7 @@ class ImageObjectDetectionModelDeploymentMetadata(proto.Message): Must be between 1 and 100, inclusive on both ends. """ - node_count = proto.Field(proto.INT64, number=1) + node_count = proto.Field(proto.INT64, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/io.py b/google/cloud/automl_v1beta1/types/io.py index 1aeb140d..4e69b64a 100644 --- a/google/cloud/automl_v1beta1/types/io.py +++ b/google/cloud/automl_v1beta1/types/io.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -359,12 +357,10 @@ class InputConfig(proto.Message): gcs_source = proto.Field( proto.MESSAGE, number=1, oneof="source", message="GcsSource", ) - bigquery_source = proto.Field( proto.MESSAGE, number=3, oneof="source", message="BigQuerySource", ) - - params = proto.MapField(proto.STRING, proto.STRING, number=2) + params = proto.MapField(proto.STRING, proto.STRING, number=2,) class BatchPredictInputConfig(proto.Message): @@ -531,7 +527,6 @@ class BatchPredictInputConfig(proto.Message): gcs_source = proto.Field( proto.MESSAGE, number=1, oneof="source", message="GcsSource", ) - bigquery_source = proto.Field( proto.MESSAGE, number=2, oneof="source", message="BigQuerySource", ) @@ -595,7 +590,6 @@ class OutputConfig(proto.Message): gcs_destination = proto.Field( proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", ) - bigquery_destination = proto.Field( proto.MESSAGE, number=2, oneof="destination", message="BigQueryDestination", ) @@ -901,7 +895,6 @@ class BatchPredictOutputConfig(proto.Message): gcs_destination = proto.Field( proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", ) - bigquery_destination = proto.Field( proto.MESSAGE, number=2, oneof="destination", message="BigQueryDestination", ) @@ -909,7 +902,6 @@ class BatchPredictOutputConfig(proto.Message): class ModelExportOutputConfig(proto.Message): r"""Output configuration for ModelExport Action. - Attributes: gcs_destination (google.cloud.automl_v1beta1.types.GcsDestination): The Google Cloud Storage location where the model is to be @@ -999,14 +991,11 @@ class ModelExportOutputConfig(proto.Message): gcs_destination = proto.Field( proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", ) - gcr_destination = proto.Field( proto.MESSAGE, number=3, oneof="destination", message="GcrDestination", ) - - model_format = proto.Field(proto.STRING, number=4) - - params = proto.MapField(proto.STRING, proto.STRING, number=2) + model_format = proto.Field(proto.STRING, number=4,) + params = proto.MapField(proto.STRING, proto.STRING, number=2,) class ExportEvaluatedExamplesOutputConfig(proto.Message): @@ -1052,7 +1041,6 @@ class ExportEvaluatedExamplesOutputConfig(proto.Message): class GcsSource(proto.Message): r"""The Google Cloud Storage location for the input content. - Attributes: input_uris (Sequence[str]): Required. Google Cloud Storage URIs to input files, up to @@ -1061,12 +1049,11 @@ class GcsSource(proto.Message): - Full object path, e.g. gs://bucket/directory/object.csv """ - input_uris = proto.RepeatedField(proto.STRING, number=1) + input_uris = proto.RepeatedField(proto.STRING, number=1,) class BigQuerySource(proto.Message): r"""The BigQuery location for the input content. - Attributes: input_uri (str): Required. BigQuery URI to a table, up to 2000 characters @@ -1075,7 +1062,7 @@ class BigQuerySource(proto.Message): - BigQuery path e.g. bq://projectId.bqDatasetId.bqTableId """ - input_uri = proto.Field(proto.STRING, number=1) + input_uri = proto.Field(proto.STRING, number=1,) class GcsDestination(proto.Message): @@ -1092,12 +1079,11 @@ class GcsDestination(proto.Message): is created if it doesn't exist. """ - output_uri_prefix = proto.Field(proto.STRING, number=1) + output_uri_prefix = proto.Field(proto.STRING, number=1,) class BigQueryDestination(proto.Message): r"""The BigQuery location for the output content. - Attributes: output_uri (str): Required. BigQuery URI to a project, up to 2000 characters @@ -1106,12 +1092,11 @@ class BigQueryDestination(proto.Message): - BigQuery path e.g. bq://projectId """ - output_uri = proto.Field(proto.STRING, number=1) + output_uri = proto.Field(proto.STRING, number=1,) class GcrDestination(proto.Message): r"""The GCR location where the image must be pushed to. - Attributes: output_uri (str): Required. Google Contained Registry URI of the new image, up @@ -1128,7 +1113,7 @@ class GcrDestination(proto.Message): project. """ - output_uri = proto.Field(proto.STRING, number=1) + output_uri = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/model.py b/google/cloud/automl_v1beta1/types/model.py index a4df8750..a91520fe 100644 --- a/google/cloud/automl_v1beta1/types/model.py +++ b/google/cloud/automl_v1beta1/types/model.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import image from google.cloud.automl_v1beta1.types import tables from google.cloud.automl_v1beta1.types import text from google.cloud.automl_v1beta1.types import translation from google.cloud.automl_v1beta1.types import video -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module(package="google.cloud.automl.v1beta1", manifest={"Model",},) @@ -31,7 +28,6 @@ class Model(proto.Message): r"""API proto representing a trained machine learning model. - Attributes: translation_model_metadata (google.cloud.automl_v1beta1.types.TranslationModelMetadata): Metadata for translation models. @@ -88,73 +84,61 @@ class DeploymentState(proto.Enum): oneof="model_metadata", message=translation.TranslationModelMetadata, ) - image_classification_model_metadata = proto.Field( proto.MESSAGE, number=13, oneof="model_metadata", message=image.ImageClassificationModelMetadata, ) - text_classification_model_metadata = proto.Field( proto.MESSAGE, number=14, oneof="model_metadata", message=text.TextClassificationModelMetadata, ) - image_object_detection_model_metadata = proto.Field( proto.MESSAGE, number=20, oneof="model_metadata", message=image.ImageObjectDetectionModelMetadata, ) - video_classification_model_metadata = proto.Field( proto.MESSAGE, number=23, oneof="model_metadata", message=video.VideoClassificationModelMetadata, ) - video_object_tracking_model_metadata = proto.Field( proto.MESSAGE, number=21, oneof="model_metadata", message=video.VideoObjectTrackingModelMetadata, ) - text_extraction_model_metadata = proto.Field( proto.MESSAGE, number=19, oneof="model_metadata", message=text.TextExtractionModelMetadata, ) - tables_model_metadata = proto.Field( proto.MESSAGE, number=24, oneof="model_metadata", message=tables.TablesModelMetadata, ) - text_sentiment_model_metadata = proto.Field( proto.MESSAGE, number=22, oneof="model_metadata", message=text.TextSentimentModelMetadata, ) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - dataset_id = proto.Field(proto.STRING, number=3) - - create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=11, message=timestamp.Timestamp,) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + dataset_id = proto.Field(proto.STRING, number=3,) + create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) + update_time = proto.Field( + proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + ) deployment_state = proto.Field(proto.ENUM, number=8, enum=DeploymentState,) diff --git a/google/cloud/automl_v1beta1/types/model_evaluation.py b/google/cloud/automl_v1beta1/types/model_evaluation.py index 25ff816f..b419463f 100644 --- a/google/cloud/automl_v1beta1/types/model_evaluation.py +++ b/google/cloud/automl_v1beta1/types/model_evaluation.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,17 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import classification from google.cloud.automl_v1beta1.types import detection from google.cloud.automl_v1beta1.types import regression from google.cloud.automl_v1beta1.types import text_extraction from google.cloud.automl_v1beta1.types import text_sentiment from google.cloud.automl_v1beta1.types import translation -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -34,7 +31,6 @@ class ModelEvaluation(proto.Message): r"""Evaluation results of a model. - Attributes: classification_evaluation_metrics (google.cloud.automl_v1beta1.types.ClassificationEvaluationMetrics): Model evaluation metrics for image, text, @@ -109,58 +105,47 @@ class ModelEvaluation(proto.Message): oneof="metrics", message=classification.ClassificationEvaluationMetrics, ) - regression_evaluation_metrics = proto.Field( proto.MESSAGE, number=24, oneof="metrics", message=regression.RegressionEvaluationMetrics, ) - translation_evaluation_metrics = proto.Field( proto.MESSAGE, number=9, oneof="metrics", message=translation.TranslationEvaluationMetrics, ) - image_object_detection_evaluation_metrics = proto.Field( proto.MESSAGE, number=12, oneof="metrics", message=detection.ImageObjectDetectionEvaluationMetrics, ) - video_object_tracking_evaluation_metrics = proto.Field( proto.MESSAGE, number=14, oneof="metrics", message=detection.VideoObjectTrackingEvaluationMetrics, ) - text_sentiment_evaluation_metrics = proto.Field( proto.MESSAGE, number=11, oneof="metrics", message=text_sentiment.TextSentimentEvaluationMetrics, ) - text_extraction_evaluation_metrics = proto.Field( proto.MESSAGE, number=13, oneof="metrics", message=text_extraction.TextExtractionEvaluationMetrics, ) - - name = proto.Field(proto.STRING, number=1) - - annotation_spec_id = proto.Field(proto.STRING, number=2) - - display_name = proto.Field(proto.STRING, number=15) - - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - evaluated_example_count = proto.Field(proto.INT32, number=6) + name = proto.Field(proto.STRING, number=1,) + annotation_spec_id = proto.Field(proto.STRING, number=2,) + display_name = proto.Field(proto.STRING, number=15,) + create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + evaluated_example_count = proto.Field(proto.INT32, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/operations.py b/google/cloud/automl_v1beta1/types/operations.py index e0b3204b..923fcb18 100644 --- a/google/cloud/automl_v1beta1/types/operations.py +++ b/google/cloud/automl_v1beta1/types/operations.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import io -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.rpc import status_pb2 as status # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore __protobuf__ = proto.module( @@ -83,97 +80,84 @@ class OperationMetadata(proto.Message): delete_details = proto.Field( proto.MESSAGE, number=8, oneof="details", message="DeleteOperationMetadata", ) - deploy_model_details = proto.Field( proto.MESSAGE, number=24, oneof="details", message="DeployModelOperationMetadata", ) - undeploy_model_details = proto.Field( proto.MESSAGE, number=25, oneof="details", message="UndeployModelOperationMetadata", ) - create_model_details = proto.Field( proto.MESSAGE, number=10, oneof="details", message="CreateModelOperationMetadata", ) - import_data_details = proto.Field( proto.MESSAGE, number=15, oneof="details", message="ImportDataOperationMetadata", ) - batch_predict_details = proto.Field( proto.MESSAGE, number=16, oneof="details", message="BatchPredictOperationMetadata", ) - export_data_details = proto.Field( proto.MESSAGE, number=21, oneof="details", message="ExportDataOperationMetadata", ) - export_model_details = proto.Field( proto.MESSAGE, number=22, oneof="details", message="ExportModelOperationMetadata", ) - export_evaluated_examples_details = proto.Field( proto.MESSAGE, number=26, oneof="details", message="ExportEvaluatedExamplesOperationMetadata", ) - - progress_percent = proto.Field(proto.INT32, number=13) - + progress_percent = proto.Field(proto.INT32, number=13,) partial_failures = proto.RepeatedField( - proto.MESSAGE, number=2, message=status.Status, + proto.MESSAGE, number=2, message=status_pb2.Status, ) - - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) + create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) class DeleteOperationMetadata(proto.Message): - r"""Details of operations that perform deletes of any entities.""" + r"""Details of operations that perform deletes of any entities. """ class DeployModelOperationMetadata(proto.Message): - r"""Details of DeployModel operation.""" + r"""Details of DeployModel operation. """ class UndeployModelOperationMetadata(proto.Message): - r"""Details of UndeployModel operation.""" + r"""Details of UndeployModel operation. """ class CreateModelOperationMetadata(proto.Message): - r"""Details of CreateModel operation.""" + r"""Details of CreateModel operation. """ class ImportDataOperationMetadata(proto.Message): - r"""Details of ImportData operation.""" + r"""Details of ImportData operation. """ class ExportDataOperationMetadata(proto.Message): r"""Details of ExportData operation. - Attributes: output_info (google.cloud.automl_v1beta1.types.ExportDataOperationMetadata.ExportDataOutputInfo): Output only. Information further describing @@ -196,11 +180,10 @@ class ExportDataOutputInfo(proto.Message): """ gcs_output_directory = proto.Field( - proto.STRING, number=1, oneof="output_location" + proto.STRING, number=1, oneof="output_location", ) - bigquery_output_dataset = proto.Field( - proto.STRING, number=2, oneof="output_location" + proto.STRING, number=2, oneof="output_location", ) output_info = proto.Field(proto.MESSAGE, number=1, message=ExportDataOutputInfo,) @@ -208,7 +191,6 @@ class ExportDataOutputInfo(proto.Message): class BatchPredictOperationMetadata(proto.Message): r"""Details of BatchPredict operation. - Attributes: input_config (google.cloud.automl_v1beta1.types.BatchPredictInputConfig): Output only. The input config that was given @@ -235,23 +217,20 @@ class BatchPredictOutputInfo(proto.Message): """ gcs_output_directory = proto.Field( - proto.STRING, number=1, oneof="output_location" + proto.STRING, number=1, oneof="output_location", ) - bigquery_output_dataset = proto.Field( - proto.STRING, number=2, oneof="output_location" + proto.STRING, number=2, oneof="output_location", ) input_config = proto.Field( proto.MESSAGE, number=1, message=io.BatchPredictInputConfig, ) - output_info = proto.Field(proto.MESSAGE, number=2, message=BatchPredictOutputInfo,) class ExportModelOperationMetadata(proto.Message): r"""Details of ExportModel operation. - Attributes: output_info (google.cloud.automl_v1beta1.types.ExportModelOperationMetadata.ExportModelOutputInfo): Output only. Information further describing @@ -270,14 +249,13 @@ class ExportModelOutputInfo(proto.Message): exported. """ - gcs_output_directory = proto.Field(proto.STRING, number=1) + gcs_output_directory = proto.Field(proto.STRING, number=1,) output_info = proto.Field(proto.MESSAGE, number=2, message=ExportModelOutputInfo,) class ExportEvaluatedExamplesOperationMetadata(proto.Message): r"""Details of EvaluatedExamples operation. - Attributes: output_info (google.cloud.automl_v1beta1.types.ExportEvaluatedExamplesOperationMetadata.ExportEvaluatedExamplesOutputInfo): Output only. Information further describing @@ -298,7 +276,7 @@ class ExportEvaluatedExamplesOutputInfo(proto.Message): written. """ - bigquery_output_dataset = proto.Field(proto.STRING, number=2) + bigquery_output_dataset = proto.Field(proto.STRING, number=2,) output_info = proto.Field( proto.MESSAGE, number=2, message=ExportEvaluatedExamplesOutputInfo, diff --git a/google/cloud/automl_v1beta1/types/prediction_service.py b/google/cloud/automl_v1beta1/types/prediction_service.py index 1261d5f6..afcdc8d3 100644 --- a/google/cloud/automl_v1beta1/types/prediction_service.py +++ b/google/cloud/automl_v1beta1/types/prediction_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import annotation_payload from google.cloud.automl_v1beta1.types import data_items from google.cloud.automl_v1beta1.types import io @@ -71,11 +68,9 @@ class PredictRequest(proto.Message): TablesAnnotation. The default is false. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) payload = proto.Field(proto.MESSAGE, number=2, message=data_items.ExamplePayload,) - - params = proto.MapField(proto.STRING, proto.STRING, number=3) + params = proto.MapField(proto.STRING, proto.STRING, number=3,) class PredictResponse(proto.Message): @@ -117,12 +112,10 @@ class PredictResponse(proto.Message): payload = proto.RepeatedField( proto.MESSAGE, number=1, message=annotation_payload.AnnotationPayload, ) - preprocessed_input = proto.Field( proto.MESSAGE, number=3, message=data_items.ExamplePayload, ) - - metadata = proto.MapField(proto.STRING, proto.STRING, number=2) + metadata = proto.MapField(proto.STRING, proto.STRING, number=2,) class BatchPredictRequest(proto.Message): @@ -219,17 +212,14 @@ class BatchPredictRequest(proto.Message): returned. Value in 0 to 1 range. Default is 0. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) input_config = proto.Field( proto.MESSAGE, number=3, message=io.BatchPredictInputConfig, ) - output_config = proto.Field( proto.MESSAGE, number=4, message=io.BatchPredictOutputConfig, ) - - params = proto.MapField(proto.STRING, proto.STRING, number=5) + params = proto.MapField(proto.STRING, proto.STRING, number=5,) class BatchPredictResult(proto.Message): @@ -251,7 +241,7 @@ class BatchPredictResult(proto.Message): have been returned. """ - metadata = proto.MapField(proto.STRING, proto.STRING, number=1) + metadata = proto.MapField(proto.STRING, proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/ranges.py b/google/cloud/automl_v1beta1/types/ranges.py index f9e72a2a..27c834d0 100644 --- a/google/cloud/automl_v1beta1/types/ranges.py +++ b/google/cloud/automl_v1beta1/types/ranges.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -25,7 +23,6 @@ class DoubleRange(proto.Message): r"""A range between two double numbers. - Attributes: start (float): Start of the range, inclusive. @@ -33,9 +30,8 @@ class DoubleRange(proto.Message): End of the range, exclusive. """ - start = proto.Field(proto.DOUBLE, number=1) - - end = proto.Field(proto.DOUBLE, number=2) + start = proto.Field(proto.DOUBLE, number=1,) + end = proto.Field(proto.DOUBLE, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/regression.py b/google/cloud/automl_v1beta1/types/regression.py index f952a396..a047d1b8 100644 --- a/google/cloud/automl_v1beta1/types/regression.py +++ b/google/cloud/automl_v1beta1/types/regression.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -25,7 +23,6 @@ class RegressionEvaluationMetrics(proto.Message): r"""Metrics for regression problems. - Attributes: root_mean_squared_error (float): Output only. Root Mean Squared Error (RMSE). @@ -41,15 +38,11 @@ class RegressionEvaluationMetrics(proto.Message): Output only. Root mean squared log error. """ - root_mean_squared_error = proto.Field(proto.FLOAT, number=1) - - mean_absolute_error = proto.Field(proto.FLOAT, number=2) - - mean_absolute_percentage_error = proto.Field(proto.FLOAT, number=3) - - r_squared = proto.Field(proto.FLOAT, number=4) - - root_mean_squared_log_error = proto.Field(proto.FLOAT, number=5) + root_mean_squared_error = proto.Field(proto.FLOAT, number=1,) + mean_absolute_error = proto.Field(proto.FLOAT, number=2,) + mean_absolute_percentage_error = proto.Field(proto.FLOAT, number=3,) + r_squared = proto.Field(proto.FLOAT, number=4,) + root_mean_squared_log_error = proto.Field(proto.FLOAT, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/service.py b/google/cloud/automl_v1beta1/types/service.py index 8e732af2..887e7441 100644 --- a/google/cloud/automl_v1beta1/types/service.py +++ b/google/cloud/automl_v1beta1/types/service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import column_spec as gca_column_spec from google.cloud.automl_v1beta1.types import dataset as gca_dataset from google.cloud.automl_v1beta1.types import image @@ -25,7 +22,7 @@ from google.cloud.automl_v1beta1.types import model as gca_model from google.cloud.automl_v1beta1.types import model_evaluation as gca_model_evaluation from google.cloud.automl_v1beta1.types import table_spec as gca_table_spec -from google.protobuf import field_mask_pb2 as gp_field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -76,8 +73,7 @@ class CreateDatasetRequest(proto.Message): Required. The dataset to create. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) dataset = proto.Field(proto.MESSAGE, number=2, message=gca_dataset.Dataset,) @@ -91,7 +87,7 @@ class GetDatasetRequest(proto.Message): retrieve. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListDatasetsRequest(proto.Message): @@ -124,13 +120,10 @@ class ListDatasetsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListDatasetsResponse(proto.Message): @@ -153,8 +146,7 @@ def raw_page(self): datasets = proto.RepeatedField( proto.MESSAGE, number=1, message=gca_dataset.Dataset, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class UpdateDatasetRequest(proto.Message): @@ -170,8 +162,9 @@ class UpdateDatasetRequest(proto.Message): """ dataset = proto.Field(proto.MESSAGE, number=1, message=gca_dataset.Dataset,) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class DeleteDatasetRequest(proto.Message): @@ -184,7 +177,7 @@ class DeleteDatasetRequest(proto.Message): delete. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ImportDataRequest(proto.Message): @@ -201,8 +194,7 @@ class ImportDataRequest(proto.Message): domain specific semantics, if any. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) input_config = proto.Field(proto.MESSAGE, number=3, message=io.InputConfig,) @@ -217,8 +209,7 @@ class ExportDataRequest(proto.Message): Required. The desired output location. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field(proto.MESSAGE, number=3, message=io.OutputConfig,) @@ -232,7 +223,7 @@ class GetAnnotationSpecRequest(proto.Message): spec to retrieve. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetTableSpecRequest(proto.Message): @@ -247,9 +238,8 @@ class GetTableSpecRequest(proto.Message): Mask specifying which fields to read. """ - name = proto.Field(proto.STRING, number=1) - - field_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) + name = proto.Field(proto.STRING, number=1,) + field_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) class ListTableSpecsRequest(proto.Message): @@ -277,15 +267,11 @@ class ListTableSpecsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - field_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + field_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListTableSpecsResponse(proto.Message): @@ -308,8 +294,7 @@ def raw_page(self): table_specs = proto.RepeatedField( proto.MESSAGE, number=1, message=gca_table_spec.TableSpec, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class UpdateTableSpecRequest(proto.Message): @@ -325,8 +310,9 @@ class UpdateTableSpecRequest(proto.Message): """ table_spec = proto.Field(proto.MESSAGE, number=1, message=gca_table_spec.TableSpec,) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class GetColumnSpecRequest(proto.Message): @@ -341,9 +327,8 @@ class GetColumnSpecRequest(proto.Message): Mask specifying which fields to read. """ - name = proto.Field(proto.STRING, number=1) - - field_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) + name = proto.Field(proto.STRING, number=1,) + field_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) class ListColumnSpecsRequest(proto.Message): @@ -371,15 +356,11 @@ class ListColumnSpecsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - field_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + field_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListColumnSpecsResponse(proto.Message): @@ -402,8 +383,7 @@ def raw_page(self): column_specs = proto.RepeatedField( proto.MESSAGE, number=1, message=gca_column_spec.ColumnSpec, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class UpdateColumnSpecRequest(proto.Message): @@ -421,8 +401,9 @@ class UpdateColumnSpecRequest(proto.Message): column_spec = proto.Field( proto.MESSAGE, number=1, message=gca_column_spec.ColumnSpec, ) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=gp_field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class CreateModelRequest(proto.Message): @@ -437,8 +418,7 @@ class CreateModelRequest(proto.Message): Required. The model to create. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) model = proto.Field(proto.MESSAGE, number=4, message=gca_model.Model,) @@ -451,7 +431,7 @@ class GetModelRequest(proto.Message): Required. Resource name of the model. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListModelsRequest(proto.Message): @@ -487,13 +467,10 @@ class ListModelsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListModelsResponse(proto.Message): @@ -514,8 +491,7 @@ def raw_page(self): return self model = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_model.Model,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class DeleteModelRequest(proto.Message): @@ -528,7 +504,7 @@ class DeleteModelRequest(proto.Message): deleted. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class DeployModelRequest(proto.Message): @@ -553,15 +529,13 @@ class DeployModelRequest(proto.Message): oneof="model_deployment_metadata", message=image.ImageObjectDetectionModelDeploymentMetadata, ) - image_classification_model_deployment_metadata = proto.Field( proto.MESSAGE, number=4, oneof="model_deployment_metadata", message=image.ImageClassificationModelDeploymentMetadata, ) - - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UndeployModelRequest(proto.Message): @@ -574,7 +548,7 @@ class UndeployModelRequest(proto.Message): undeploy. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ExportModelRequest(proto.Message): @@ -592,8 +566,7 @@ class ExportModelRequest(proto.Message): configuration. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field( proto.MESSAGE, number=3, message=io.ModelExportOutputConfig, ) @@ -612,8 +585,7 @@ class ExportEvaluatedExamplesRequest(proto.Message): configuration. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field( proto.MESSAGE, number=3, message=io.ExportEvaluatedExamplesOutputConfig, ) @@ -629,7 +601,7 @@ class GetModelEvaluationRequest(proto.Message): evaluation. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListModelEvaluationsRequest(proto.Message): @@ -665,13 +637,10 @@ class ListModelEvaluationsRequest(proto.Message): call. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=6) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=6,) class ListModelEvaluationsResponse(proto.Message): @@ -697,8 +666,7 @@ def raw_page(self): model_evaluation = proto.RepeatedField( proto.MESSAGE, number=1, message=gca_model_evaluation.ModelEvaluation, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/table_spec.py b/google/cloud/automl_v1beta1/types/table_spec.py index e69c24ce..da06cb37 100644 --- a/google/cloud/automl_v1beta1/types/table_spec.py +++ b/google/cloud/automl_v1beta1/types/table_spec.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import io @@ -73,21 +70,15 @@ class TableSpec(proto.Message): happens. """ - name = proto.Field(proto.STRING, number=1) - - time_column_spec_id = proto.Field(proto.STRING, number=2) - - row_count = proto.Field(proto.INT64, number=3) - - valid_row_count = proto.Field(proto.INT64, number=4) - - column_count = proto.Field(proto.INT64, number=7) - + name = proto.Field(proto.STRING, number=1,) + time_column_spec_id = proto.Field(proto.STRING, number=2,) + row_count = proto.Field(proto.INT64, number=3,) + valid_row_count = proto.Field(proto.INT64, number=4,) + column_count = proto.Field(proto.INT64, number=7,) input_configs = proto.RepeatedField( proto.MESSAGE, number=5, message=io.InputConfig, ) - - etag = proto.Field(proto.STRING, number=6) + etag = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/tables.py b/google/cloud/automl_v1beta1/types/tables.py index 50b82e0f..15258ecc 100644 --- a/google/cloud/automl_v1beta1/types/tables.py +++ b/google/cloud/automl_v1beta1/types/tables.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import column_spec from google.cloud.automl_v1beta1.types import data_stats from google.cloud.automl_v1beta1.types import ranges -from google.protobuf import struct_pb2 as struct # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -38,7 +35,6 @@ class TablesDatasetMetadata(proto.Message): r"""Metadata for a dataset used for AutoML Tables. - Attributes: primary_table_spec_id (str): Output only. The table_spec_id of the primary table of this @@ -105,26 +101,20 @@ class TablesDatasetMetadata(proto.Message): effort basis. """ - primary_table_spec_id = proto.Field(proto.STRING, number=1) - - target_column_spec_id = proto.Field(proto.STRING, number=2) - - weight_column_spec_id = proto.Field(proto.STRING, number=3) - - ml_use_column_spec_id = proto.Field(proto.STRING, number=4) - + primary_table_spec_id = proto.Field(proto.STRING, number=1,) + target_column_spec_id = proto.Field(proto.STRING, number=2,) + weight_column_spec_id = proto.Field(proto.STRING, number=3,) + ml_use_column_spec_id = proto.Field(proto.STRING, number=4,) target_column_correlations = proto.MapField( proto.STRING, proto.MESSAGE, number=6, message=data_stats.CorrelationStats, ) - stats_update_time = proto.Field( - proto.MESSAGE, number=7, message=timestamp.Timestamp, + proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) class TablesModelMetadata(proto.Message): r"""Model metadata specific to AutoML Tables. - Attributes: optimization_objective_recall_value (float): Required when optimization_objective is @@ -229,37 +219,28 @@ class TablesModelMetadata(proto.Message): """ optimization_objective_recall_value = proto.Field( - proto.FLOAT, number=17, oneof="additional_optimization_objective_config" + proto.FLOAT, number=17, oneof="additional_optimization_objective_config", ) - optimization_objective_precision_value = proto.Field( - proto.FLOAT, number=18, oneof="additional_optimization_objective_config" + proto.FLOAT, number=18, oneof="additional_optimization_objective_config", ) - target_column_spec = proto.Field( proto.MESSAGE, number=2, message=column_spec.ColumnSpec, ) - input_feature_column_specs = proto.RepeatedField( proto.MESSAGE, number=3, message=column_spec.ColumnSpec, ) - - optimization_objective = proto.Field(proto.STRING, number=4) - + optimization_objective = proto.Field(proto.STRING, number=4,) tables_model_column_info = proto.RepeatedField( proto.MESSAGE, number=5, message="TablesModelColumnInfo", ) - - train_budget_milli_node_hours = proto.Field(proto.INT64, number=6) - - train_cost_milli_node_hours = proto.Field(proto.INT64, number=7) - - disable_early_stopping = proto.Field(proto.BOOL, number=12) + train_budget_milli_node_hours = proto.Field(proto.INT64, number=6,) + train_cost_milli_node_hours = proto.Field(proto.INT64, number=7,) + disable_early_stopping = proto.Field(proto.BOOL, number=12,) class TablesAnnotation(proto.Message): r"""Contains annotation details specific to Tables. - Attributes: score (float): Output only. A confidence estimate between 0.0 and 1.0, @@ -311,19 +292,15 @@ class TablesAnnotation(proto.Message): baseline example for the argmax class. """ - score = proto.Field(proto.FLOAT, number=1) - + score = proto.Field(proto.FLOAT, number=1,) prediction_interval = proto.Field( proto.MESSAGE, number=4, message=ranges.DoubleRange, ) - - value = proto.Field(proto.MESSAGE, number=2, message=struct.Value,) - + value = proto.Field(proto.MESSAGE, number=2, message=struct_pb2.Value,) tables_model_column_info = proto.RepeatedField( proto.MESSAGE, number=3, message="TablesModelColumnInfo", ) - - baseline_score = proto.Field(proto.FLOAT, number=5) + baseline_score = proto.Field(proto.FLOAT, number=5,) class TablesModelColumnInfo(proto.Message): @@ -359,11 +336,9 @@ class TablesModelColumnInfo(proto.Message): values are computed using the Sampled Shapley method. """ - column_spec_name = proto.Field(proto.STRING, number=1) - - column_display_name = proto.Field(proto.STRING, number=2) - - feature_importance = proto.Field(proto.FLOAT, number=3) + column_spec_name = proto.Field(proto.STRING, number=1,) + column_display_name = proto.Field(proto.STRING, number=2,) + feature_importance = proto.Field(proto.FLOAT, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/temporal.py b/google/cloud/automl_v1beta1/types/temporal.py index 6334e502..c1de97a4 100644 --- a/google/cloud/automl_v1beta1/types/temporal.py +++ b/google/cloud/automl_v1beta1/types/temporal.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import duration_pb2 as duration # type: ignore +from google.protobuf import duration_pb2 # type: ignore __protobuf__ = proto.module( @@ -41,9 +38,12 @@ class TimeSegment(proto.Message): start. """ - start_time_offset = proto.Field(proto.MESSAGE, number=1, message=duration.Duration,) - - end_time_offset = proto.Field(proto.MESSAGE, number=2, message=duration.Duration,) + start_time_offset = proto.Field( + proto.MESSAGE, number=1, message=duration_pb2.Duration, + ) + end_time_offset = proto.Field( + proto.MESSAGE, number=2, message=duration_pb2.Duration, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/text.py b/google/cloud/automl_v1beta1/types/text.py index 83c01a1b..233c03a2 100644 --- a/google/cloud/automl_v1beta1/types/text.py +++ b/google/cloud/automl_v1beta1/types/text.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import classification @@ -36,7 +33,6 @@ class TextClassificationDatasetMetadata(proto.Message): r"""Dataset metadata for classification. - Attributes: classification_type (google.cloud.automl_v1beta1.types.ClassificationType): Required. Type of the classification problem. @@ -49,7 +45,6 @@ class TextClassificationDatasetMetadata(proto.Message): class TextClassificationModelMetadata(proto.Message): r"""Model metadata that is specific to text classification. - Attributes: classification_type (google.cloud.automl_v1beta1.types.ClassificationType): Output only. Classification type of the @@ -62,12 +57,11 @@ class TextClassificationModelMetadata(proto.Message): class TextExtractionDatasetMetadata(proto.Message): - r"""Dataset metadata that is specific to text extraction""" + r"""Dataset metadata that is specific to text extraction """ class TextExtractionModelMetadata(proto.Message): r"""Model metadata that is specific to text extraction. - Attributes: model_hint (str): Indicates the scope of model use case. @@ -79,12 +73,11 @@ class TextExtractionModelMetadata(proto.Message): that is tuned for healthcare applications. """ - model_hint = proto.Field(proto.STRING, number=3) + model_hint = proto.Field(proto.STRING, number=3,) class TextSentimentDatasetMetadata(proto.Message): r"""Dataset metadata for text sentiment. - Attributes: sentiment_max (int): Required. A sentiment is expressed as an integer ordinal, @@ -96,11 +89,11 @@ class TextSentimentDatasetMetadata(proto.Message): and 10 (inclusive). """ - sentiment_max = proto.Field(proto.INT32, number=1) + sentiment_max = proto.Field(proto.INT32, number=1,) class TextSentimentModelMetadata(proto.Message): - r"""Model metadata that is specific to text sentiment.""" + r"""Model metadata that is specific to text sentiment. """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/text_extraction.py b/google/cloud/automl_v1beta1/types/text_extraction.py index 13fd60f2..e120608b 100644 --- a/google/cloud/automl_v1beta1/types/text_extraction.py +++ b/google/cloud/automl_v1beta1/types/text_extraction.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import text_segment as gca_text_segment @@ -29,7 +26,6 @@ class TextExtractionAnnotation(proto.Message): r"""Annotation for identifying spans of text. - Attributes: text_segment (google.cloud.automl_v1beta1.types.TextSegment): An entity annotation will set this, which is @@ -47,13 +43,11 @@ class TextExtractionAnnotation(proto.Message): oneof="annotation", message=gca_text_segment.TextSegment, ) - - score = proto.Field(proto.FLOAT, number=1) + score = proto.Field(proto.FLOAT, number=1,) class TextExtractionEvaluationMetrics(proto.Message): r"""Model evaluation metrics for text extraction problems. - Attributes: au_prc (float): Output only. The Area under precision recall @@ -66,7 +60,6 @@ class TextExtractionEvaluationMetrics(proto.Message): class ConfidenceMetricsEntry(proto.Message): r"""Metrics for a single confidence threshold. - Attributes: confidence_threshold (float): Output only. The confidence threshold value @@ -84,16 +77,12 @@ class ConfidenceMetricsEntry(proto.Message): precision. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1) - - recall = proto.Field(proto.FLOAT, number=3) - - precision = proto.Field(proto.FLOAT, number=4) - - f1_score = proto.Field(proto.FLOAT, number=5) - - au_prc = proto.Field(proto.FLOAT, number=1) + confidence_threshold = proto.Field(proto.FLOAT, number=1,) + recall = proto.Field(proto.FLOAT, number=3,) + precision = proto.Field(proto.FLOAT, number=4,) + f1_score = proto.Field(proto.FLOAT, number=5,) + au_prc = proto.Field(proto.FLOAT, number=1,) confidence_metrics_entries = proto.RepeatedField( proto.MESSAGE, number=2, message=ConfidenceMetricsEntry, ) diff --git a/google/cloud/automl_v1beta1/types/text_segment.py b/google/cloud/automl_v1beta1/types/text_segment.py index 646bb9f9..82f6561f 100644 --- a/google/cloud/automl_v1beta1/types/text_segment.py +++ b/google/cloud/automl_v1beta1/types/text_segment.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -41,11 +39,9 @@ class TextSegment(proto.Message): is NOT included in the text segment. """ - content = proto.Field(proto.STRING, number=3) - - start_offset = proto.Field(proto.INT64, number=1) - - end_offset = proto.Field(proto.INT64, number=2) + content = proto.Field(proto.STRING, number=3,) + start_offset = proto.Field(proto.INT64, number=1,) + end_offset = proto.Field(proto.INT64, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/text_sentiment.py b/google/cloud/automl_v1beta1/types/text_sentiment.py index 16206eb1..0cdb0def 100644 --- a/google/cloud/automl_v1beta1/types/text_sentiment.py +++ b/google/cloud/automl_v1beta1/types/text_sentiment.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import classification @@ -29,7 +26,6 @@ class TextSentimentAnnotation(proto.Message): r"""Contains annotation details specific to text sentiment. - Attributes: sentiment (int): Output only. The sentiment with the semantic, as given to @@ -50,12 +46,11 @@ class TextSentimentAnnotation(proto.Message): Analysis API. """ - sentiment = proto.Field(proto.INT32, number=1) + sentiment = proto.Field(proto.INT32, number=1,) class TextSentimentEvaluationMetrics(proto.Message): r"""Model evaluation metrics for text sentiment problems. - Attributes: precision (float): Output only. Precision. @@ -90,27 +85,19 @@ class TextSentimentEvaluationMetrics(proto.Message): this evaluation. Deprecated . """ - precision = proto.Field(proto.FLOAT, number=1) - - recall = proto.Field(proto.FLOAT, number=2) - - f1_score = proto.Field(proto.FLOAT, number=3) - - mean_absolute_error = proto.Field(proto.FLOAT, number=4) - - mean_squared_error = proto.Field(proto.FLOAT, number=5) - - linear_kappa = proto.Field(proto.FLOAT, number=6) - - quadratic_kappa = proto.Field(proto.FLOAT, number=7) - + precision = proto.Field(proto.FLOAT, number=1,) + recall = proto.Field(proto.FLOAT, number=2,) + f1_score = proto.Field(proto.FLOAT, number=3,) + mean_absolute_error = proto.Field(proto.FLOAT, number=4,) + mean_squared_error = proto.Field(proto.FLOAT, number=5,) + linear_kappa = proto.Field(proto.FLOAT, number=6,) + quadratic_kappa = proto.Field(proto.FLOAT, number=7,) confusion_matrix = proto.Field( proto.MESSAGE, number=8, message=classification.ClassificationEvaluationMetrics.ConfusionMatrix, ) - - annotation_spec_id = proto.RepeatedField(proto.STRING, number=9) + annotation_spec_id = proto.RepeatedField(proto.STRING, number=9,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/automl_v1beta1/types/translation.py b/google/cloud/automl_v1beta1/types/translation.py index 34ba6f24..231624b0 100644 --- a/google/cloud/automl_v1beta1/types/translation.py +++ b/google/cloud/automl_v1beta1/types/translation.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.automl_v1beta1.types import data_items @@ -34,7 +31,6 @@ class TranslationDatasetMetadata(proto.Message): r"""Dataset metadata that is specific to translation. - Attributes: source_language_code (str): Required. The BCP-47 language code of the @@ -44,14 +40,12 @@ class TranslationDatasetMetadata(proto.Message): target language. """ - source_language_code = proto.Field(proto.STRING, number=1) - - target_language_code = proto.Field(proto.STRING, number=2) + source_language_code = proto.Field(proto.STRING, number=1,) + target_language_code = proto.Field(proto.STRING, number=2,) class TranslationEvaluationMetrics(proto.Message): r"""Evaluation metrics for the dataset. - Attributes: bleu_score (float): Output only. BLEU score. @@ -59,14 +53,12 @@ class TranslationEvaluationMetrics(proto.Message): Output only. BLEU score for base model. """ - bleu_score = proto.Field(proto.DOUBLE, number=1) - - base_bleu_score = proto.Field(proto.DOUBLE, number=2) + bleu_score = proto.Field(proto.DOUBLE, number=1,) + base_bleu_score = proto.Field(proto.DOUBLE, number=2,) class TranslationModelMetadata(proto.Message): r"""Model metadata that is specific to translation. - Attributes: base_model (str): The resource name of the model to use as a baseline to train @@ -82,16 +74,13 @@ class TranslationModelMetadata(proto.Message): language code) that is used for training. """ - base_model = proto.Field(proto.STRING, number=1) - - source_language_code = proto.Field(proto.STRING, number=2) - - target_language_code = proto.Field(proto.STRING, number=3) + base_model = proto.Field(proto.STRING, number=1,) + source_language_code = proto.Field(proto.STRING, number=2,) + target_language_code = proto.Field(proto.STRING, number=3,) class TranslationAnnotation(proto.Message): r"""Annotation details specific to translation. - Attributes: translated_content (google.cloud.automl_v1beta1.types.TextSnippet): Output only . The translated content. diff --git a/google/cloud/automl_v1beta1/types/video.py b/google/cloud/automl_v1beta1/types/video.py index 685393b9..02315f55 100644 --- a/google/cloud/automl_v1beta1/types/video.py +++ b/google/cloud/automl_v1beta1/types/video.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -32,19 +30,19 @@ class VideoClassificationDatasetMetadata(proto.Message): r"""Dataset metadata specific to video classification. All Video Classification datasets are treated as multi label. - """ + """ class VideoObjectTrackingDatasetMetadata(proto.Message): - r"""Dataset metadata specific to video object tracking.""" + r"""Dataset metadata specific to video object tracking. """ class VideoClassificationModelMetadata(proto.Message): - r"""Model metadata specific to video classification.""" + r"""Model metadata specific to video classification. """ class VideoObjectTrackingModelMetadata(proto.Message): - r"""Model metadata specific to video object tracking.""" + r"""Model metadata specific to video object tracking. """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owlbot.py b/owlbot.py index e4a49945..bc528110 100644 --- a/owlbot.py +++ b/owlbot.py @@ -30,8 +30,10 @@ s.replace( library / f"google/cloud/automl_v1beta1/__init__.py", "from .services.auto_ml import AutoMlClient\n" + "from .services.auto_ml import AutoMlAsyncClient\n" "from .services.prediction_service import PredictionServiceClient\n", "from .services.auto_ml import AutoMlClient\n" + "from .services.auto_ml import AutoMlAsyncClient\n" "from .services.prediction_service import PredictionServiceClient\n" "from .services.tables.gcs_client import GcsClient\n" "from .services.tables.tables_client import TablesClient\n" diff --git a/scripts/fixup_automl_v1_keywords.py b/scripts/fixup_automl_v1_keywords.py index 9051bf99..be4c58a4 100644 --- a/scripts/fixup_automl_v1_keywords.py +++ b/scripts/fixup_automl_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,27 +39,26 @@ def partition( class automlCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_predict': ('name', 'input_config', 'output_config', 'params', ), - 'create_dataset': ('parent', 'dataset', ), - 'create_model': ('parent', 'model', ), - 'delete_dataset': ('name', ), - 'delete_model': ('name', ), - 'deploy_model': ('name', 'image_object_detection_model_deployment_metadata', 'image_classification_model_deployment_metadata', ), - 'export_data': ('name', 'output_config', ), - 'export_model': ('name', 'output_config', ), - 'get_annotation_spec': ('name', ), - 'get_dataset': ('name', ), - 'get_model': ('name', ), - 'get_model_evaluation': ('name', ), - 'import_data': ('name', 'input_config', ), - 'list_datasets': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_model_evaluations': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_models': ('parent', 'filter', 'page_size', 'page_token', ), - 'predict': ('name', 'payload', 'params', ), - 'undeploy_model': ('name', ), - 'update_dataset': ('dataset', 'update_mask', ), - 'update_model': ('model', 'update_mask', ), - + 'batch_predict': ('name', 'input_config', 'output_config', 'params', ), + 'create_dataset': ('parent', 'dataset', ), + 'create_model': ('parent', 'model', ), + 'delete_dataset': ('name', ), + 'delete_model': ('name', ), + 'deploy_model': ('name', 'image_object_detection_model_deployment_metadata', 'image_classification_model_deployment_metadata', ), + 'export_data': ('name', 'output_config', ), + 'export_model': ('name', 'output_config', ), + 'get_annotation_spec': ('name', ), + 'get_dataset': ('name', ), + 'get_model': ('name', ), + 'get_model_evaluation': ('name', ), + 'import_data': ('name', 'input_config', ), + 'list_datasets': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_model_evaluations': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_models': ('parent', 'filter', 'page_size', 'page_token', ), + 'predict': ('name', 'payload', 'params', ), + 'undeploy_model': ('name', ), + 'update_dataset': ('dataset', 'update_mask', ), + 'update_model': ('model', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -92,7 +89,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/scripts/fixup_automl_v1beta1_keywords.py b/scripts/fixup_automl_v1beta1_keywords.py index 8a34eafd..68569e00 100644 --- a/scripts/fixup_automl_v1beta1_keywords.py +++ b/scripts/fixup_automl_v1beta1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,33 +39,32 @@ def partition( class automlCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_predict': ('name', 'input_config', 'output_config', 'params', ), - 'create_dataset': ('parent', 'dataset', ), - 'create_model': ('parent', 'model', ), - 'delete_dataset': ('name', ), - 'delete_model': ('name', ), - 'deploy_model': ('name', 'image_object_detection_model_deployment_metadata', 'image_classification_model_deployment_metadata', ), - 'export_data': ('name', 'output_config', ), - 'export_evaluated_examples': ('name', 'output_config', ), - 'export_model': ('name', 'output_config', ), - 'get_annotation_spec': ('name', ), - 'get_column_spec': ('name', 'field_mask', ), - 'get_dataset': ('name', ), - 'get_model': ('name', ), - 'get_model_evaluation': ('name', ), - 'get_table_spec': ('name', 'field_mask', ), - 'import_data': ('name', 'input_config', ), - 'list_column_specs': ('parent', 'field_mask', 'filter', 'page_size', 'page_token', ), - 'list_datasets': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_model_evaluations': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_models': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_table_specs': ('parent', 'field_mask', 'filter', 'page_size', 'page_token', ), - 'predict': ('name', 'payload', 'params', ), - 'undeploy_model': ('name', ), - 'update_column_spec': ('column_spec', 'update_mask', ), - 'update_dataset': ('dataset', 'update_mask', ), - 'update_table_spec': ('table_spec', 'update_mask', ), - + 'batch_predict': ('name', 'input_config', 'output_config', 'params', ), + 'create_dataset': ('parent', 'dataset', ), + 'create_model': ('parent', 'model', ), + 'delete_dataset': ('name', ), + 'delete_model': ('name', ), + 'deploy_model': ('name', 'image_object_detection_model_deployment_metadata', 'image_classification_model_deployment_metadata', ), + 'export_data': ('name', 'output_config', ), + 'export_evaluated_examples': ('name', 'output_config', ), + 'export_model': ('name', 'output_config', ), + 'get_annotation_spec': ('name', ), + 'get_column_spec': ('name', 'field_mask', ), + 'get_dataset': ('name', ), + 'get_model': ('name', ), + 'get_model_evaluation': ('name', ), + 'get_table_spec': ('name', 'field_mask', ), + 'import_data': ('name', 'input_config', ), + 'list_column_specs': ('parent', 'field_mask', 'filter', 'page_size', 'page_token', ), + 'list_datasets': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_model_evaluations': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_models': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_table_specs': ('parent', 'field_mask', 'filter', 'page_size', 'page_token', ), + 'predict': ('name', 'payload', 'params', ), + 'undeploy_model': ('name', ), + 'update_column_spec': ('column_spec', 'update_mask', ), + 'update_dataset': ('dataset', 'update_mask', ), + 'update_table_spec': ('table_spec', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -98,7 +95,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/automl_v1/__init__.py b/tests/unit/gapic/automl_v1/__init__.py index 42ffdf2b..4de65971 100644 --- a/tests/unit/gapic/automl_v1/__init__.py +++ b/tests/unit/gapic/automl_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/automl_v1/test_auto_ml.py b/tests/unit/gapic/automl_v1/test_auto_ml.py index c00be626..85f0eff3 100644 --- a/tests/unit/gapic/automl_v1/test_auto_ml.py +++ b/tests/unit/gapic/automl_v1/test_auto_ml.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,21 +23,23 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.automl_v1.services.auto_ml import AutoMlAsyncClient from google.cloud.automl_v1.services.auto_ml import AutoMlClient from google.cloud.automl_v1.services.auto_ml import pagers from google.cloud.automl_v1.services.auto_ml import transports +from google.cloud.automl_v1.services.auto_ml.transports.base import _API_CORE_VERSION +from google.cloud.automl_v1.services.auto_ml.transports.base import _GOOGLE_AUTH_VERSION from google.cloud.automl_v1.types import annotation_spec from google.cloud.automl_v1.types import classification from google.cloud.automl_v1.types import dataset @@ -57,8 +58,32 @@ from google.cloud.automl_v1.types import translation from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -101,7 +126,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [AutoMlClient, AutoMlAsyncClient,]) def test_auto_ml_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -116,7 +141,7 @@ def test_auto_ml_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [AutoMlClient, AutoMlAsyncClient,]) def test_auto_ml_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -159,7 +184,7 @@ def test_auto_ml_client_get_transport_class(): def test_auto_ml_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(AutoMlClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -433,7 +458,7 @@ def test_create_dataset( transport: str = "grpc", request_type=service.CreateDatasetRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -444,13 +469,11 @@ def test_create_dataset( with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateDatasetRequest() # Establish that the response is the type that we expect. @@ -465,7 +488,7 @@ def test_create_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -473,7 +496,6 @@ def test_create_dataset_empty_call(): client.create_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateDatasetRequest() @@ -482,7 +504,7 @@ async def test_create_dataset_async( transport: str = "grpc_asyncio", request_type=service.CreateDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -495,13 +517,11 @@ async def test_create_dataset_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateDatasetRequest() # Establish that the response is the type that we expect. @@ -514,17 +534,17 @@ async def test_create_dataset_async_from_dict(): def test_create_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateDatasetRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -539,11 +559,12 @@ def test_create_dataset_field_headers(): @pytest.mark.asyncio async def test_create_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateDatasetRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -551,7 +572,6 @@ async def test_create_dataset_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -565,13 +585,12 @@ async def test_create_dataset_field_headers_async(): def test_create_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_dataset( @@ -587,9 +606,7 @@ def test_create_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" @@ -598,7 +615,7 @@ def test_create_dataset_flattened(): def test_create_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -616,7 +633,7 @@ def test_create_dataset_flattened_error(): @pytest.mark.asyncio async def test_create_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -641,9 +658,7 @@ async def test_create_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" @@ -653,7 +668,7 @@ async def test_create_dataset_flattened_async(): @pytest.mark.asyncio async def test_create_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -671,7 +686,7 @@ async def test_create_dataset_flattened_error_async(): def test_get_dataset(transport: str = "grpc", request_type=service.GetDatasetRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -691,27 +706,19 @@ def test_get_dataset(transport: str = "grpc", request_type=service.GetDatasetReq source_language_code="source_language_code_value" ), ) - response = client.get_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetDatasetRequest() # Establish that the response is the type that we expect. - assert isinstance(response, dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -723,7 +730,7 @@ def test_get_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -731,7 +738,6 @@ def test_get_dataset_empty_call(): client.get_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetDatasetRequest() @@ -740,7 +746,7 @@ async def test_get_dataset_async( transport: str = "grpc_asyncio", request_type=service.GetDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -759,26 +765,19 @@ async def test_get_dataset_async( etag="etag_value", ) ) - response = await client.get_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -788,17 +787,17 @@ async def test_get_dataset_async_from_dict(): def test_get_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = dataset.Dataset() - client.get_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -813,17 +812,17 @@ def test_get_dataset_field_headers(): @pytest.mark.asyncio async def test_get_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Dataset()) - await client.get_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -837,13 +836,12 @@ async def test_get_dataset_field_headers_async(): def test_get_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Dataset() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_dataset(name="name_value",) @@ -852,12 +850,11 @@ def test_get_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -869,7 +866,7 @@ def test_get_dataset_flattened_error(): @pytest.mark.asyncio async def test_get_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -885,13 +882,12 @@ async def test_get_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -905,7 +901,7 @@ def test_list_datasets( transport: str = "grpc", request_type=service.ListDatasetsRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -918,19 +914,15 @@ def test_list_datasets( call.return_value = service.ListDatasetsResponse( next_page_token="next_page_token_value", ) - response = client.list_datasets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListDatasetsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatasetsPager) - assert response.next_page_token == "next_page_token_value" @@ -942,7 +934,7 @@ def test_list_datasets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -950,7 +942,6 @@ def test_list_datasets_empty_call(): client.list_datasets() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListDatasetsRequest() @@ -959,7 +950,7 @@ async def test_list_datasets_async( transport: str = "grpc_asyncio", request_type=service.ListDatasetsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -972,18 +963,15 @@ async def test_list_datasets_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListDatasetsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_datasets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListDatasetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDatasetsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -993,17 +981,17 @@ async def test_list_datasets_async_from_dict(): def test_list_datasets_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListDatasetsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: call.return_value = service.ListDatasetsResponse() - client.list_datasets(request) # Establish that the underlying gRPC stub method was called. @@ -1018,11 +1006,12 @@ def test_list_datasets_field_headers(): @pytest.mark.asyncio async def test_list_datasets_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListDatasetsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1030,7 +1019,6 @@ async def test_list_datasets_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListDatasetsResponse() ) - await client.list_datasets(request) # Establish that the underlying gRPC stub method was called. @@ -1044,13 +1032,12 @@ async def test_list_datasets_field_headers_async(): def test_list_datasets_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListDatasetsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_datasets(parent="parent_value",) @@ -1059,12 +1046,11 @@ def test_list_datasets_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_datasets_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1076,7 +1062,7 @@ def test_list_datasets_flattened_error(): @pytest.mark.asyncio async def test_list_datasets_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1094,13 +1080,12 @@ async def test_list_datasets_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_datasets_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1111,7 +1096,7 @@ async def test_list_datasets_flattened_error_async(): def test_list_datasets_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1145,7 +1130,7 @@ def test_list_datasets_pager(): def test_list_datasets_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1171,7 +1156,7 @@ def test_list_datasets_pages(): @pytest.mark.asyncio async def test_list_datasets_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1204,7 +1189,7 @@ async def test_list_datasets_async_pager(): @pytest.mark.asyncio async def test_list_datasets_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1236,7 +1221,7 @@ def test_update_dataset( transport: str = "grpc", request_type=service.UpdateDatasetRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1256,27 +1241,19 @@ def test_update_dataset( source_language_code="source_language_code_value" ), ) - response = client.update_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateDatasetRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -1288,7 +1265,7 @@ def test_update_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1296,7 +1273,6 @@ def test_update_dataset_empty_call(): client.update_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateDatasetRequest() @@ -1305,7 +1281,7 @@ async def test_update_dataset_async( transport: str = "grpc_asyncio", request_type=service.UpdateDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1324,26 +1300,19 @@ async def test_update_dataset_async( etag="etag_value", ) ) - response = await client.update_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -1353,17 +1322,17 @@ async def test_update_dataset_async_from_dict(): def test_update_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateDatasetRequest() + request.dataset.name = "dataset.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: call.return_value = gca_dataset.Dataset() - client.update_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1380,17 +1349,17 @@ def test_update_dataset_field_headers(): @pytest.mark.asyncio async def test_update_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateDatasetRequest() + request.dataset.name = "dataset.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_dataset.Dataset()) - await client.update_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1406,13 +1375,12 @@ async def test_update_dataset_field_headers_async(): def test_update_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gca_dataset.Dataset() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_dataset( @@ -1421,25 +1389,23 @@ def test_update_dataset_flattened(): source_language_code="source_language_code_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" ) ) - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1451,13 +1417,13 @@ def test_update_dataset_flattened_error(): source_language_code="source_language_code_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1473,26 +1439,24 @@ async def test_update_dataset_flattened_async(): source_language_code="source_language_code_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" ) ) - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1504,7 +1468,7 @@ async def test_update_dataset_flattened_error_async(): source_language_code="source_language_code_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1512,7 +1476,7 @@ def test_delete_dataset( transport: str = "grpc", request_type=service.DeleteDatasetRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1523,13 +1487,11 @@ def test_delete_dataset( with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteDatasetRequest() # Establish that the response is the type that we expect. @@ -1544,7 +1506,7 @@ def test_delete_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1552,7 +1514,6 @@ def test_delete_dataset_empty_call(): client.delete_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteDatasetRequest() @@ -1561,7 +1522,7 @@ async def test_delete_dataset_async( transport: str = "grpc_asyncio", request_type=service.DeleteDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1574,13 +1535,11 @@ async def test_delete_dataset_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteDatasetRequest() # Establish that the response is the type that we expect. @@ -1593,17 +1552,17 @@ async def test_delete_dataset_async_from_dict(): def test_delete_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1618,11 +1577,12 @@ def test_delete_dataset_field_headers(): @pytest.mark.asyncio async def test_delete_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1630,7 +1590,6 @@ async def test_delete_dataset_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1644,13 +1603,12 @@ async def test_delete_dataset_field_headers_async(): def test_delete_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_dataset(name="name_value",) @@ -1659,12 +1617,11 @@ def test_delete_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1676,7 +1633,7 @@ def test_delete_dataset_flattened_error(): @pytest.mark.asyncio async def test_delete_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1694,13 +1651,12 @@ async def test_delete_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1712,7 +1668,7 @@ async def test_delete_dataset_flattened_error_async(): def test_import_data(transport: str = "grpc", request_type=service.ImportDataRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1723,13 +1679,11 @@ def test_import_data(transport: str = "grpc", request_type=service.ImportDataReq with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.import_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ImportDataRequest() # Establish that the response is the type that we expect. @@ -1744,7 +1698,7 @@ def test_import_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1752,7 +1706,6 @@ def test_import_data_empty_call(): client.import_data() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ImportDataRequest() @@ -1761,7 +1714,7 @@ async def test_import_data_async( transport: str = "grpc_asyncio", request_type=service.ImportDataRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1774,13 +1727,11 @@ async def test_import_data_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.import_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ImportDataRequest() # Establish that the response is the type that we expect. @@ -1793,17 +1744,17 @@ async def test_import_data_async_from_dict(): def test_import_data_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ImportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.import_data(request) # Establish that the underlying gRPC stub method was called. @@ -1818,11 +1769,12 @@ def test_import_data_field_headers(): @pytest.mark.asyncio async def test_import_data_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ImportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1830,7 +1782,6 @@ async def test_import_data_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.import_data(request) # Establish that the underlying gRPC stub method was called. @@ -1844,13 +1795,12 @@ async def test_import_data_field_headers_async(): def test_import_data_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.import_data( @@ -1864,16 +1814,14 @@ def test_import_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.InputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) def test_import_data_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1889,7 +1837,7 @@ def test_import_data_flattened_error(): @pytest.mark.asyncio async def test_import_data_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1912,9 +1860,7 @@ async def test_import_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.InputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) @@ -1922,7 +1868,7 @@ async def test_import_data_flattened_async(): @pytest.mark.asyncio async def test_import_data_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1938,7 +1884,7 @@ async def test_import_data_flattened_error_async(): def test_export_data(transport: str = "grpc", request_type=service.ExportDataRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1949,13 +1895,11 @@ def test_export_data(transport: str = "grpc", request_type=service.ExportDataReq with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportDataRequest() # Establish that the response is the type that we expect. @@ -1970,7 +1914,7 @@ def test_export_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1978,7 +1922,6 @@ def test_export_data_empty_call(): client.export_data() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportDataRequest() @@ -1987,7 +1930,7 @@ async def test_export_data_async( transport: str = "grpc_asyncio", request_type=service.ExportDataRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2000,13 +1943,11 @@ async def test_export_data_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportDataRequest() # Establish that the response is the type that we expect. @@ -2019,17 +1960,17 @@ async def test_export_data_async_from_dict(): def test_export_data_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_data(request) # Establish that the underlying gRPC stub method was called. @@ -2044,11 +1985,12 @@ def test_export_data_field_headers(): @pytest.mark.asyncio async def test_export_data_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2056,7 +1998,6 @@ async def test_export_data_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_data(request) # Establish that the underlying gRPC stub method was called. @@ -2070,13 +2011,12 @@ async def test_export_data_field_headers_async(): def test_export_data_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_data( @@ -2092,9 +2032,7 @@ def test_export_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.OutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -2103,7 +2041,7 @@ def test_export_data_flattened(): def test_export_data_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2121,7 +2059,7 @@ def test_export_data_flattened_error(): @pytest.mark.asyncio async def test_export_data_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -2146,9 +2084,7 @@ async def test_export_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.OutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -2158,7 +2094,7 @@ async def test_export_data_flattened_async(): @pytest.mark.asyncio async def test_export_data_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2178,7 +2114,7 @@ def test_get_annotation_spec( transport: str = "grpc", request_type=service.GetAnnotationSpecRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2193,23 +2129,17 @@ def test_get_annotation_spec( call.return_value = annotation_spec.AnnotationSpec( name="name_value", display_name="display_name_value", example_count=1396, ) - response = client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAnnotationSpecRequest() # Establish that the response is the type that we expect. - assert isinstance(response, annotation_spec.AnnotationSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.example_count == 1396 @@ -2221,7 +2151,7 @@ def test_get_annotation_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2231,7 +2161,6 @@ def test_get_annotation_spec_empty_call(): client.get_annotation_spec() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAnnotationSpecRequest() @@ -2240,7 +2169,7 @@ async def test_get_annotation_spec_async( transport: str = "grpc_asyncio", request_type=service.GetAnnotationSpecRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2259,22 +2188,17 @@ async def test_get_annotation_spec_async( example_count=1396, ) ) - response = await client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAnnotationSpecRequest() # Establish that the response is the type that we expect. assert isinstance(response, annotation_spec.AnnotationSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.example_count == 1396 @@ -2284,11 +2208,12 @@ async def test_get_annotation_spec_async_from_dict(): def test_get_annotation_spec_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAnnotationSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2296,7 +2221,6 @@ def test_get_annotation_spec_field_headers(): type(client.transport.get_annotation_spec), "__call__" ) as call: call.return_value = annotation_spec.AnnotationSpec() - client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. @@ -2311,11 +2235,12 @@ def test_get_annotation_spec_field_headers(): @pytest.mark.asyncio async def test_get_annotation_spec_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAnnotationSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2325,7 +2250,6 @@ async def test_get_annotation_spec_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( annotation_spec.AnnotationSpec() ) - await client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. @@ -2339,7 +2263,7 @@ async def test_get_annotation_spec_field_headers_async(): def test_get_annotation_spec_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2347,7 +2271,6 @@ def test_get_annotation_spec_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec.AnnotationSpec() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_annotation_spec(name="name_value",) @@ -2356,12 +2279,11 @@ def test_get_annotation_spec_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_annotation_spec_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2373,7 +2295,7 @@ def test_get_annotation_spec_flattened_error(): @pytest.mark.asyncio async def test_get_annotation_spec_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2393,13 +2315,12 @@ async def test_get_annotation_spec_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_annotation_spec_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2411,7 +2332,7 @@ async def test_get_annotation_spec_flattened_error_async(): def test_create_model(transport: str = "grpc", request_type=service.CreateModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2422,13 +2343,11 @@ def test_create_model(transport: str = "grpc", request_type=service.CreateModelR with mock.patch.object(type(client.transport.create_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateModelRequest() # Establish that the response is the type that we expect. @@ -2443,7 +2362,7 @@ def test_create_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2451,7 +2370,6 @@ def test_create_model_empty_call(): client.create_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateModelRequest() @@ -2460,7 +2378,7 @@ async def test_create_model_async( transport: str = "grpc_asyncio", request_type=service.CreateModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2473,13 +2391,11 @@ async def test_create_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateModelRequest() # Establish that the response is the type that we expect. @@ -2492,17 +2408,17 @@ async def test_create_model_async_from_dict(): def test_create_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateModelRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_model(request) # Establish that the underlying gRPC stub method was called. @@ -2517,11 +2433,12 @@ def test_create_model_field_headers(): @pytest.mark.asyncio async def test_create_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateModelRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2529,7 +2446,6 @@ async def test_create_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_model(request) # Establish that the underlying gRPC stub method was called. @@ -2543,13 +2459,12 @@ async def test_create_model_field_headers_async(): def test_create_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_model( @@ -2565,9 +2480,7 @@ def test_create_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model( translation_model_metadata=translation.TranslationModelMetadata( base_model="base_model_value" @@ -2576,7 +2489,7 @@ def test_create_model_flattened(): def test_create_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2594,7 +2507,7 @@ def test_create_model_flattened_error(): @pytest.mark.asyncio async def test_create_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_model), "__call__") as call: @@ -2619,9 +2532,7 @@ async def test_create_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model( translation_model_metadata=translation.TranslationModelMetadata( base_model="base_model_value" @@ -2631,7 +2542,7 @@ async def test_create_model_flattened_async(): @pytest.mark.asyncio async def test_create_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2649,7 +2560,7 @@ async def test_create_model_flattened_error_async(): def test_get_model(transport: str = "grpc", request_type=service.GetModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2669,27 +2580,19 @@ def test_get_model(transport: str = "grpc", request_type=service.GetModelRequest base_model="base_model_value" ), ) - response = client.get_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.dataset_id == "dataset_id_value" - assert response.deployment_state == model.Model.DeploymentState.DEPLOYED - assert response.etag == "etag_value" @@ -2701,7 +2604,7 @@ def test_get_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2709,7 +2612,6 @@ def test_get_model_empty_call(): client.get_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelRequest() @@ -2718,7 +2620,7 @@ async def test_get_model_async( transport: str = "grpc_asyncio", request_type=service.GetModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2737,26 +2639,19 @@ async def test_get_model_async( etag="etag_value", ) ) - response = await client.get_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelRequest() # Establish that the response is the type that we expect. assert isinstance(response, model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.dataset_id == "dataset_id_value" - assert response.deployment_state == model.Model.DeploymentState.DEPLOYED - assert response.etag == "etag_value" @@ -2766,17 +2661,17 @@ async def test_get_model_async_from_dict(): def test_get_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: call.return_value = model.Model() - client.get_model(request) # Establish that the underlying gRPC stub method was called. @@ -2791,17 +2686,17 @@ def test_get_model_field_headers(): @pytest.mark.asyncio async def test_get_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) - await client.get_model(request) # Establish that the underlying gRPC stub method was called. @@ -2815,13 +2710,12 @@ async def test_get_model_field_headers_async(): def test_get_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = model.Model() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_model(name="name_value",) @@ -2830,12 +2724,11 @@ def test_get_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2847,7 +2740,7 @@ def test_get_model_flattened_error(): @pytest.mark.asyncio async def test_get_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -2863,13 +2756,12 @@ async def test_get_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2881,7 +2773,7 @@ async def test_get_model_flattened_error_async(): def test_list_models(transport: str = "grpc", request_type=service.ListModelsRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2894,19 +2786,15 @@ def test_list_models(transport: str = "grpc", request_type=service.ListModelsReq call.return_value = service.ListModelsResponse( next_page_token="next_page_token_value", ) - response = client.list_models(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelsPager) - assert response.next_page_token == "next_page_token_value" @@ -2918,7 +2806,7 @@ def test_list_models_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2926,7 +2814,6 @@ def test_list_models_empty_call(): client.list_models() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelsRequest() @@ -2935,7 +2822,7 @@ async def test_list_models_async( transport: str = "grpc_asyncio", request_type=service.ListModelsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2948,18 +2835,15 @@ async def test_list_models_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListModelsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_models(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListModelsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2969,17 +2853,17 @@ async def test_list_models_async_from_dict(): def test_list_models_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: call.return_value = service.ListModelsResponse() - client.list_models(request) # Establish that the underlying gRPC stub method was called. @@ -2994,11 +2878,12 @@ def test_list_models_field_headers(): @pytest.mark.asyncio async def test_list_models_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3006,7 +2891,6 @@ async def test_list_models_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListModelsResponse() ) - await client.list_models(request) # Establish that the underlying gRPC stub method was called. @@ -3020,13 +2904,12 @@ async def test_list_models_field_headers_async(): def test_list_models_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListModelsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_models(parent="parent_value",) @@ -3035,12 +2918,11 @@ def test_list_models_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_models_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3052,7 +2934,7 @@ def test_list_models_flattened_error(): @pytest.mark.asyncio async def test_list_models_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -3070,13 +2952,12 @@ async def test_list_models_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_models_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3087,7 +2968,7 @@ async def test_list_models_flattened_error_async(): def test_list_models_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -3117,7 +2998,7 @@ def test_list_models_pager(): def test_list_models_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -3139,7 +3020,7 @@ def test_list_models_pages(): @pytest.mark.asyncio async def test_list_models_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3168,7 +3049,7 @@ async def test_list_models_async_pager(): @pytest.mark.asyncio async def test_list_models_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3194,7 +3075,7 @@ async def test_list_models_async_pages(): def test_delete_model(transport: str = "grpc", request_type=service.DeleteModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3205,13 +3086,11 @@ def test_delete_model(transport: str = "grpc", request_type=service.DeleteModelR with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteModelRequest() # Establish that the response is the type that we expect. @@ -3226,7 +3105,7 @@ def test_delete_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3234,7 +3113,6 @@ def test_delete_model_empty_call(): client.delete_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteModelRequest() @@ -3243,7 +3121,7 @@ async def test_delete_model_async( transport: str = "grpc_asyncio", request_type=service.DeleteModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3256,13 +3134,11 @@ async def test_delete_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteModelRequest() # Establish that the response is the type that we expect. @@ -3275,17 +3151,17 @@ async def test_delete_model_async_from_dict(): def test_delete_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_model(request) # Establish that the underlying gRPC stub method was called. @@ -3300,11 +3176,12 @@ def test_delete_model_field_headers(): @pytest.mark.asyncio async def test_delete_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3312,7 +3189,6 @@ async def test_delete_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_model(request) # Establish that the underlying gRPC stub method was called. @@ -3326,13 +3202,12 @@ async def test_delete_model_field_headers_async(): def test_delete_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_model(name="name_value",) @@ -3341,12 +3216,11 @@ def test_delete_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3358,7 +3232,7 @@ def test_delete_model_flattened_error(): @pytest.mark.asyncio async def test_delete_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_model), "__call__") as call: @@ -3376,13 +3250,12 @@ async def test_delete_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3394,7 +3267,7 @@ async def test_delete_model_flattened_error_async(): def test_update_model(transport: str = "grpc", request_type=service.UpdateModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3414,27 +3287,19 @@ def test_update_model(transport: str = "grpc", request_type=service.UpdateModelR base_model="base_model_value" ), ) - response = client.update_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.dataset_id == "dataset_id_value" - assert response.deployment_state == gca_model.Model.DeploymentState.DEPLOYED - assert response.etag == "etag_value" @@ -3446,7 +3311,7 @@ def test_update_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3454,7 +3319,6 @@ def test_update_model_empty_call(): client.update_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateModelRequest() @@ -3463,7 +3327,7 @@ async def test_update_model_async( transport: str = "grpc_asyncio", request_type=service.UpdateModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3482,26 +3346,19 @@ async def test_update_model_async( etag="etag_value", ) ) - response = await client.update_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateModelRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.dataset_id == "dataset_id_value" - assert response.deployment_state == gca_model.Model.DeploymentState.DEPLOYED - assert response.etag == "etag_value" @@ -3511,17 +3368,17 @@ async def test_update_model_async_from_dict(): def test_update_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateModelRequest() + request.model.name = "model.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_model), "__call__") as call: call.return_value = gca_model.Model() - client.update_model(request) # Establish that the underlying gRPC stub method was called. @@ -3536,17 +3393,17 @@ def test_update_model_field_headers(): @pytest.mark.asyncio async def test_update_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateModelRequest() + request.model.name = "model.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_model), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) - await client.update_model(request) # Establish that the underlying gRPC stub method was called. @@ -3560,13 +3417,12 @@ async def test_update_model_field_headers_async(): def test_update_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gca_model.Model() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_model( @@ -3575,25 +3431,23 @@ def test_update_model_flattened(): base_model="base_model_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].model == gca_model.Model( translation_model_metadata=translation.TranslationModelMetadata( base_model="base_model_value" ) ) - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3605,13 +3459,13 @@ def test_update_model_flattened_error(): base_model="base_model_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_model), "__call__") as call: @@ -3627,26 +3481,24 @@ async def test_update_model_flattened_async(): base_model="base_model_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].model == gca_model.Model( translation_model_metadata=translation.TranslationModelMetadata( base_model="base_model_value" ) ) - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3658,13 +3510,13 @@ async def test_update_model_flattened_error_async(): base_model="base_model_value" ) ), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) def test_deploy_model(transport: str = "grpc", request_type=service.DeployModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3675,13 +3527,11 @@ def test_deploy_model(transport: str = "grpc", request_type=service.DeployModelR with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.deploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeployModelRequest() # Establish that the response is the type that we expect. @@ -3696,7 +3546,7 @@ def test_deploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3704,7 +3554,6 @@ def test_deploy_model_empty_call(): client.deploy_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeployModelRequest() @@ -3713,7 +3562,7 @@ async def test_deploy_model_async( transport: str = "grpc_asyncio", request_type=service.DeployModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3726,13 +3575,11 @@ async def test_deploy_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.deploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeployModelRequest() # Establish that the response is the type that we expect. @@ -3745,17 +3592,17 @@ async def test_deploy_model_async_from_dict(): def test_deploy_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.deploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -3770,11 +3617,12 @@ def test_deploy_model_field_headers(): @pytest.mark.asyncio async def test_deploy_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3782,7 +3630,6 @@ async def test_deploy_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.deploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -3796,13 +3643,12 @@ async def test_deploy_model_field_headers_async(): def test_deploy_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.deploy_model(name="name_value",) @@ -3811,12 +3657,11 @@ def test_deploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_deploy_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3828,7 +3673,7 @@ def test_deploy_model_flattened_error(): @pytest.mark.asyncio async def test_deploy_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -3846,13 +3691,12 @@ async def test_deploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_deploy_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3866,7 +3710,7 @@ def test_undeploy_model( transport: str = "grpc", request_type=service.UndeployModelRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3877,13 +3721,11 @@ def test_undeploy_model( with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UndeployModelRequest() # Establish that the response is the type that we expect. @@ -3898,7 +3740,7 @@ def test_undeploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3906,7 +3748,6 @@ def test_undeploy_model_empty_call(): client.undeploy_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UndeployModelRequest() @@ -3915,7 +3756,7 @@ async def test_undeploy_model_async( transport: str = "grpc_asyncio", request_type=service.UndeployModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3928,13 +3769,11 @@ async def test_undeploy_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UndeployModelRequest() # Establish that the response is the type that we expect. @@ -3947,17 +3786,17 @@ async def test_undeploy_model_async_from_dict(): def test_undeploy_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UndeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -3972,11 +3811,12 @@ def test_undeploy_model_field_headers(): @pytest.mark.asyncio async def test_undeploy_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UndeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3984,7 +3824,6 @@ async def test_undeploy_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -3998,13 +3837,12 @@ async def test_undeploy_model_field_headers_async(): def test_undeploy_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.undeploy_model(name="name_value",) @@ -4013,12 +3851,11 @@ def test_undeploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_undeploy_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4030,7 +3867,7 @@ def test_undeploy_model_flattened_error(): @pytest.mark.asyncio async def test_undeploy_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -4048,13 +3885,12 @@ async def test_undeploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_undeploy_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4066,7 +3902,7 @@ async def test_undeploy_model_flattened_error_async(): def test_export_model(transport: str = "grpc", request_type=service.ExportModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4077,13 +3913,11 @@ def test_export_model(transport: str = "grpc", request_type=service.ExportModelR with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportModelRequest() # Establish that the response is the type that we expect. @@ -4098,7 +3932,7 @@ def test_export_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4106,7 +3940,6 @@ def test_export_model_empty_call(): client.export_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportModelRequest() @@ -4115,7 +3948,7 @@ async def test_export_model_async( transport: str = "grpc_asyncio", request_type=service.ExportModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4128,13 +3961,11 @@ async def test_export_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportModelRequest() # Establish that the response is the type that we expect. @@ -4147,17 +3978,17 @@ async def test_export_model_async_from_dict(): def test_export_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_model(request) # Establish that the underlying gRPC stub method was called. @@ -4172,11 +4003,12 @@ def test_export_model_field_headers(): @pytest.mark.asyncio async def test_export_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4184,7 +4016,6 @@ async def test_export_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_model(request) # Establish that the underlying gRPC stub method was called. @@ -4198,13 +4029,12 @@ async def test_export_model_field_headers_async(): def test_export_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_model( @@ -4220,9 +4050,7 @@ def test_export_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.ModelExportOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -4231,7 +4059,7 @@ def test_export_model_flattened(): def test_export_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4249,7 +4077,7 @@ def test_export_model_flattened_error(): @pytest.mark.asyncio async def test_export_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_model), "__call__") as call: @@ -4274,9 +4102,7 @@ async def test_export_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.ModelExportOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -4286,7 +4112,7 @@ async def test_export_model_flattened_async(): @pytest.mark.asyncio async def test_export_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4306,7 +4132,7 @@ def test_get_model_evaluation( transport: str = "grpc", request_type=service.GetModelEvaluationRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4327,25 +4153,18 @@ def test_get_model_evaluation( au_prc=0.634 ), ) - response = client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelEvaluationRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.annotation_spec_id == "annotation_spec_id_value" - assert response.display_name == "display_name_value" - assert response.evaluated_example_count == 2446 @@ -4357,7 +4176,7 @@ def test_get_model_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4367,7 +4186,6 @@ def test_get_model_evaluation_empty_call(): client.get_model_evaluation() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelEvaluationRequest() @@ -4376,7 +4194,7 @@ async def test_get_model_evaluation_async( transport: str = "grpc_asyncio", request_type=service.GetModelEvaluationRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4396,24 +4214,18 @@ async def test_get_model_evaluation_async( evaluated_example_count=2446, ) ) - response = await client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelEvaluationRequest() # Establish that the response is the type that we expect. assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.annotation_spec_id == "annotation_spec_id_value" - assert response.display_name == "display_name_value" - assert response.evaluated_example_count == 2446 @@ -4423,11 +4235,12 @@ async def test_get_model_evaluation_async_from_dict(): def test_get_model_evaluation_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelEvaluationRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4435,7 +4248,6 @@ def test_get_model_evaluation_field_headers(): type(client.transport.get_model_evaluation), "__call__" ) as call: call.return_value = model_evaluation.ModelEvaluation() - client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. @@ -4450,11 +4262,12 @@ def test_get_model_evaluation_field_headers(): @pytest.mark.asyncio async def test_get_model_evaluation_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelEvaluationRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4464,7 +4277,6 @@ async def test_get_model_evaluation_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( model_evaluation.ModelEvaluation() ) - await client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. @@ -4478,7 +4290,7 @@ async def test_get_model_evaluation_field_headers_async(): def test_get_model_evaluation_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4486,7 +4298,6 @@ def test_get_model_evaluation_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = model_evaluation.ModelEvaluation() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_model_evaluation(name="name_value",) @@ -4495,12 +4306,11 @@ def test_get_model_evaluation_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_model_evaluation_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4512,7 +4322,7 @@ def test_get_model_evaluation_flattened_error(): @pytest.mark.asyncio async def test_get_model_evaluation_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4532,13 +4342,12 @@ async def test_get_model_evaluation_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_model_evaluation_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4552,7 +4361,7 @@ def test_list_model_evaluations( transport: str = "grpc", request_type=service.ListModelEvaluationsRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4567,19 +4376,15 @@ def test_list_model_evaluations( call.return_value = service.ListModelEvaluationsResponse( next_page_token="next_page_token_value", ) - response = client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelEvaluationsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationsPager) - assert response.next_page_token == "next_page_token_value" @@ -4591,7 +4396,7 @@ def test_list_model_evaluations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4601,7 +4406,6 @@ def test_list_model_evaluations_empty_call(): client.list_model_evaluations() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelEvaluationsRequest() @@ -4610,7 +4414,7 @@ async def test_list_model_evaluations_async( transport: str = "grpc_asyncio", request_type=service.ListModelEvaluationsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4627,18 +4431,15 @@ async def test_list_model_evaluations_async( next_page_token="next_page_token_value", ) ) - response = await client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelEvaluationsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListModelEvaluationsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -4648,11 +4449,12 @@ async def test_list_model_evaluations_async_from_dict(): def test_list_model_evaluations_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelEvaluationsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4660,7 +4462,6 @@ def test_list_model_evaluations_field_headers(): type(client.transport.list_model_evaluations), "__call__" ) as call: call.return_value = service.ListModelEvaluationsResponse() - client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. @@ -4675,11 +4476,12 @@ def test_list_model_evaluations_field_headers(): @pytest.mark.asyncio async def test_list_model_evaluations_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelEvaluationsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4689,7 +4491,6 @@ async def test_list_model_evaluations_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListModelEvaluationsResponse() ) - await client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. @@ -4703,7 +4504,7 @@ async def test_list_model_evaluations_field_headers_async(): def test_list_model_evaluations_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4711,7 +4512,6 @@ def test_list_model_evaluations_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = service.ListModelEvaluationsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_model_evaluations( @@ -4722,14 +4522,12 @@ def test_list_model_evaluations_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].filter == "filter_value" def test_list_model_evaluations_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4743,7 +4541,7 @@ def test_list_model_evaluations_flattened_error(): @pytest.mark.asyncio async def test_list_model_evaluations_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4765,15 +4563,13 @@ async def test_list_model_evaluations_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].filter == "filter_value" @pytest.mark.asyncio async def test_list_model_evaluations_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4786,7 +4582,7 @@ async def test_list_model_evaluations_flattened_error_async(): def test_list_model_evaluations_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4832,7 +4628,7 @@ def test_list_model_evaluations_pager(): def test_list_model_evaluations_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4870,7 +4666,7 @@ def test_list_model_evaluations_pages(): @pytest.mark.asyncio async def test_list_model_evaluations_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4915,7 +4711,7 @@ async def test_list_model_evaluations_async_pager(): @pytest.mark.asyncio async def test_list_model_evaluations_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4958,16 +4754,16 @@ async def test_list_model_evaluations_async_pages(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AutoMlClient( @@ -4977,7 +4773,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AutoMlClient( @@ -4988,7 +4784,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = AutoMlClient(transport=transport) assert client.transport is transport @@ -4997,13 +4793,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.AutoMlGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -5015,23 +4811,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.AutoMlGrpcTransport,) def test_auto_ml_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AutoMlTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -5043,7 +4839,7 @@ def test_auto_ml_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AutoMlTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -5078,15 +4874,37 @@ def test_auto_ml_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_auto_ml_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.AutoMlTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_auto_ml_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -5099,19 +4917,33 @@ def test_auto_ml_base_transport_with_credentials_file(): def test_auto_ml_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_auto_ml_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + AutoMlClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_auto_ml_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) AutoMlClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -5119,26 +4951,152 @@ def test_auto_ml_auth_adc(): ) -def test_auto_ml_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.AutoMlGrpcTransport, transports.AutoMlGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_auto_ml_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.AutoMlGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.AutoMlGrpcTransport, transports.AutoMlGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_auto_ml_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AutoMlGrpcTransport, grpc_helpers), + (transports.AutoMlGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_auto_ml_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="automl.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AutoMlGrpcTransport, grpc_helpers), + (transports.AutoMlGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_auto_ml_transport_create_channel_old_api_core(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AutoMlGrpcTransport, grpc_helpers), + (transports.AutoMlGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_auto_ml_transport_create_channel_user_scopes(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [transports.AutoMlGrpcTransport, transports.AutoMlGrpcAsyncIOTransport], ) def test_auto_ml_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5177,7 +5135,7 @@ def test_auto_ml_grpc_transport_client_cert_source_for_mtls(transport_class): def test_auto_ml_host_no_port(): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com" ), @@ -5187,7 +5145,7 @@ def test_auto_ml_host_no_port(): def test_auto_ml_host_with_port(): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com:8000" ), @@ -5238,9 +5196,9 @@ def test_auto_ml_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -5313,7 +5271,7 @@ def test_auto_ml_transport_channel_mtls_with_adc(transport_class): def test_auto_ml_grpc_lro_client(): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -5326,7 +5284,7 @@ def test_auto_ml_grpc_lro_client(): def test_auto_ml_grpc_lro_async_client(): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -5342,7 +5300,6 @@ def test_annotation_spec_path(): location = "clam" dataset = "whelk" annotation_spec = "octopus" - expected = "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}".format( project=project, location=location, @@ -5373,7 +5330,6 @@ def test_dataset_path(): project = "winkle" location = "nautilus" dataset = "scallop" - expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( project=project, location=location, dataset=dataset, ) @@ -5398,7 +5354,6 @@ def test_model_path(): project = "whelk" location = "octopus" model = "oyster" - expected = "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @@ -5424,7 +5379,6 @@ def test_model_evaluation_path(): location = "nautilus" model = "scallop" model_evaluation = "abalone" - expected = "projects/{project}/locations/{location}/models/{model}/modelEvaluations/{model_evaluation}".format( project=project, location=location, @@ -5453,7 +5407,6 @@ def test_parse_model_evaluation_path(): def test_common_billing_account_path(): billing_account = "oyster" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -5474,7 +5427,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) actual = AutoMlClient.common_folder_path(folder) assert expected == actual @@ -5493,7 +5445,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) actual = AutoMlClient.common_organization_path(organization) assert expected == actual @@ -5512,7 +5463,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) actual = AutoMlClient.common_project_path(project) assert expected == actual @@ -5532,7 +5482,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "squid" location = "clam" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -5559,7 +5508,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.AutoMlTransport, "_prep_wrapped_messages" ) as prep: client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5568,6 +5517,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = AutoMlClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/automl_v1/test_prediction_service.py b/tests/unit/gapic/automl_v1/test_prediction_service.py index e3d6dfd2..5095e327 100644 --- a/tests/unit/gapic/automl_v1/test_prediction_service.py +++ b/tests/unit/gapic/automl_v1/test_prediction_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,22 +23,28 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.automl_v1.services.prediction_service import ( PredictionServiceAsyncClient, ) from google.cloud.automl_v1.services.prediction_service import PredictionServiceClient from google.cloud.automl_v1.services.prediction_service import transports +from google.cloud.automl_v1.services.prediction_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.automl_v1.services.prediction_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.automl_v1.types import annotation_payload from google.cloud.automl_v1.types import data_items from google.cloud.automl_v1.types import geometry @@ -49,6 +54,30 @@ from google.cloud.automl_v1.types import text_segment from google.longrunning import operations_pb2 from google.oauth2 import service_account +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -100,7 +129,7 @@ def test__get_default_mtls_endpoint(): "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] ) def test_prediction_service_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -117,7 +146,7 @@ def test_prediction_service_client_from_service_account_info(client_class): "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] ) def test_prediction_service_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -170,7 +199,7 @@ def test_prediction_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(PredictionServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -468,7 +497,7 @@ def test_predict( transport: str = "grpc", request_type=prediction_service.PredictRequest ): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -479,17 +508,14 @@ def test_predict( with mock.patch.object(type(client.transport.predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = prediction_service.PredictResponse() - response = client.predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.PredictRequest() # Establish that the response is the type that we expect. - assert isinstance(response, prediction_service.PredictResponse) @@ -501,7 +527,7 @@ def test_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -509,7 +535,6 @@ def test_predict_empty_call(): client.predict() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.PredictRequest() @@ -518,7 +543,7 @@ async def test_predict_async( transport: str = "grpc_asyncio", request_type=prediction_service.PredictRequest ): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -531,13 +556,11 @@ async def test_predict_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( prediction_service.PredictResponse() ) - response = await client.predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.PredictRequest() # Establish that the response is the type that we expect. @@ -550,17 +573,17 @@ async def test_predict_async_from_dict(): def test_predict_field_headers(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: call.return_value = prediction_service.PredictResponse() - client.predict(request) # Establish that the underlying gRPC stub method was called. @@ -576,12 +599,13 @@ def test_predict_field_headers(): @pytest.mark.asyncio async def test_predict_field_headers_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -589,7 +613,6 @@ async def test_predict_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( prediction_service.PredictResponse() ) - await client.predict(request) # Establish that the underlying gRPC stub method was called. @@ -603,13 +626,12 @@ async def test_predict_field_headers_async(): def test_predict_flattened(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = prediction_service.PredictResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.predict( @@ -624,18 +646,15 @@ def test_predict_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].payload == data_items.ExamplePayload( image=data_items.Image(image_bytes=b"image_bytes_blob") ) - assert args[0].params == {"key_value": "value_value"} def test_predict_flattened_error(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -653,7 +672,7 @@ def test_predict_flattened_error(): @pytest.mark.asyncio async def test_predict_flattened_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -678,20 +697,17 @@ async def test_predict_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].payload == data_items.ExamplePayload( image=data_items.Image(image_bytes=b"image_bytes_blob") ) - assert args[0].params == {"key_value": "value_value"} @pytest.mark.asyncio async def test_predict_flattened_error_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -711,7 +727,7 @@ def test_batch_predict( transport: str = "grpc", request_type=prediction_service.BatchPredictRequest ): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -722,13 +738,11 @@ def test_batch_predict( with mock.patch.object(type(client.transport.batch_predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.batch_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.BatchPredictRequest() # Establish that the response is the type that we expect. @@ -743,7 +757,7 @@ def test_batch_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -751,7 +765,6 @@ def test_batch_predict_empty_call(): client.batch_predict() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.BatchPredictRequest() @@ -760,7 +773,7 @@ async def test_batch_predict_async( transport: str = "grpc_asyncio", request_type=prediction_service.BatchPredictRequest ): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -773,13 +786,11 @@ async def test_batch_predict_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.batch_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.BatchPredictRequest() # Establish that the response is the type that we expect. @@ -792,17 +803,17 @@ async def test_batch_predict_async_from_dict(): def test_batch_predict_field_headers(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.BatchPredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.batch_predict), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.batch_predict(request) # Establish that the underlying gRPC stub method was called. @@ -818,12 +829,13 @@ def test_batch_predict_field_headers(): @pytest.mark.asyncio async def test_batch_predict_field_headers_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.BatchPredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -831,7 +843,6 @@ async def test_batch_predict_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.batch_predict(request) # Establish that the underlying gRPC stub method was called. @@ -845,13 +856,12 @@ async def test_batch_predict_field_headers_async(): def test_batch_predict_flattened(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.batch_predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.batch_predict( @@ -871,24 +881,20 @@ def test_batch_predict_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.BatchPredictInputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) - assert args[0].output_config == io.BatchPredictOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) - assert args[0].params == {"key_value": "value_value"} def test_batch_predict_flattened_error(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -911,7 +917,7 @@ def test_batch_predict_flattened_error(): @pytest.mark.asyncio async def test_batch_predict_flattened_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -941,26 +947,22 @@ async def test_batch_predict_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.BatchPredictInputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) - assert args[0].output_config == io.BatchPredictOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) - assert args[0].params == {"key_value": "value_value"} @pytest.mark.asyncio async def test_batch_predict_flattened_error_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -984,16 +986,16 @@ async def test_batch_predict_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( @@ -1003,7 +1005,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( @@ -1014,7 +1016,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = PredictionServiceClient(transport=transport) assert client.transport is transport @@ -1023,13 +1025,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.PredictionServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1044,23 +1046,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.PredictionServiceGrpcTransport,) def test_prediction_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.PredictionServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1072,7 +1074,7 @@ def test_prediction_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.PredictionServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1091,15 +1093,37 @@ def test_prediction_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.PredictionServiceTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_prediction_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1112,19 +1136,33 @@ def test_prediction_service_base_transport_with_credentials_file(): def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_prediction_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + PredictionServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_prediction_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) PredictionServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -1132,20 +1170,156 @@ def test_prediction_service_auth_adc(): ) -def test_prediction_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_prediction_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.PredictionServiceGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_prediction_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="automl.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_prediction_service_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_prediction_service_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -1154,7 +1328,7 @@ def test_prediction_service_transport_auth_adc(): ], ) def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1193,7 +1367,7 @@ def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport def test_prediction_service_host_no_port(): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com" ), @@ -1203,7 +1377,7 @@ def test_prediction_service_host_no_port(): def test_prediction_service_host_with_port(): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com:8000" ), @@ -1259,9 +1433,9 @@ def test_prediction_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -1337,7 +1511,7 @@ def test_prediction_service_transport_channel_mtls_with_adc(transport_class): def test_prediction_service_grpc_lro_client(): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -1350,7 +1524,7 @@ def test_prediction_service_grpc_lro_client(): def test_prediction_service_grpc_lro_async_client(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -1365,7 +1539,6 @@ def test_model_path(): project = "squid" location = "clam" model = "whelk" - expected = "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @@ -1388,7 +1561,6 @@ def test_parse_model_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1409,7 +1581,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = PredictionServiceClient.common_folder_path(folder) assert expected == actual @@ -1428,7 +1599,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = PredictionServiceClient.common_organization_path(organization) assert expected == actual @@ -1447,7 +1617,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = PredictionServiceClient.common_project_path(project) assert expected == actual @@ -1467,7 +1636,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1494,7 +1662,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.PredictionServiceTransport, "_prep_wrapped_messages" ) as prep: client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1503,6 +1671,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = PredictionServiceClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/automl_v1beta1/__init__.py b/tests/unit/gapic/automl_v1beta1/__init__.py index 42ffdf2b..4de65971 100644 --- a/tests/unit/gapic/automl_v1beta1/__init__.py +++ b/tests/unit/gapic/automl_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/automl_v1beta1/test_auto_ml.py b/tests/unit/gapic/automl_v1beta1/test_auto_ml.py index 31e45e5c..2d8669b8 100644 --- a/tests/unit/gapic/automl_v1beta1/test_auto_ml.py +++ b/tests/unit/gapic/automl_v1beta1/test_auto_ml.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,21 +23,27 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.automl_v1beta1.services.auto_ml import AutoMlAsyncClient from google.cloud.automl_v1beta1.services.auto_ml import AutoMlClient from google.cloud.automl_v1beta1.services.auto_ml import pagers from google.cloud.automl_v1beta1.services.auto_ml import transports +from google.cloud.automl_v1beta1.services.auto_ml.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.automl_v1beta1.services.auto_ml.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.automl_v1beta1.types import annotation_spec from google.cloud.automl_v1beta1.types import classification from google.cloud.automl_v1beta1.types import column_spec @@ -66,8 +71,32 @@ from google.cloud.automl_v1beta1.types import video from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -110,7 +139,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [AutoMlClient, AutoMlAsyncClient,]) def test_auto_ml_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -125,7 +154,7 @@ def test_auto_ml_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [AutoMlClient, AutoMlAsyncClient,]) def test_auto_ml_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -168,7 +197,7 @@ def test_auto_ml_client_get_transport_class(): def test_auto_ml_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(AutoMlClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -442,7 +471,7 @@ def test_create_dataset( transport: str = "grpc", request_type=service.CreateDatasetRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -462,27 +491,19 @@ def test_create_dataset( source_language_code="source_language_code_value" ), ) - response = client.create_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateDatasetRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -494,7 +515,7 @@ def test_create_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -502,7 +523,6 @@ def test_create_dataset_empty_call(): client.create_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateDatasetRequest() @@ -511,7 +531,7 @@ async def test_create_dataset_async( transport: str = "grpc_asyncio", request_type=service.CreateDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -530,26 +550,19 @@ async def test_create_dataset_async( etag="etag_value", ) ) - response = await client.create_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -559,17 +572,17 @@ async def test_create_dataset_async_from_dict(): def test_create_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateDatasetRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = gca_dataset.Dataset() - client.create_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -584,17 +597,17 @@ def test_create_dataset_field_headers(): @pytest.mark.asyncio async def test_create_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateDatasetRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_dataset.Dataset()) - await client.create_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -608,13 +621,12 @@ async def test_create_dataset_field_headers_async(): def test_create_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gca_dataset.Dataset() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_dataset( @@ -630,9 +642,7 @@ def test_create_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" @@ -641,7 +651,7 @@ def test_create_dataset_flattened(): def test_create_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -659,7 +669,7 @@ def test_create_dataset_flattened_error(): @pytest.mark.asyncio async def test_create_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -682,9 +692,7 @@ async def test_create_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" @@ -694,7 +702,7 @@ async def test_create_dataset_flattened_async(): @pytest.mark.asyncio async def test_create_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -712,7 +720,7 @@ async def test_create_dataset_flattened_error_async(): def test_get_dataset(transport: str = "grpc", request_type=service.GetDatasetRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -732,27 +740,19 @@ def test_get_dataset(transport: str = "grpc", request_type=service.GetDatasetReq source_language_code="source_language_code_value" ), ) - response = client.get_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetDatasetRequest() # Establish that the response is the type that we expect. - assert isinstance(response, dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -764,7 +764,7 @@ def test_get_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -772,7 +772,6 @@ def test_get_dataset_empty_call(): client.get_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetDatasetRequest() @@ -781,7 +780,7 @@ async def test_get_dataset_async( transport: str = "grpc_asyncio", request_type=service.GetDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -800,26 +799,19 @@ async def test_get_dataset_async( etag="etag_value", ) ) - response = await client.get_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -829,17 +821,17 @@ async def test_get_dataset_async_from_dict(): def test_get_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = dataset.Dataset() - client.get_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -854,17 +846,17 @@ def test_get_dataset_field_headers(): @pytest.mark.asyncio async def test_get_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Dataset()) - await client.get_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -878,13 +870,12 @@ async def test_get_dataset_field_headers_async(): def test_get_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Dataset() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_dataset(name="name_value",) @@ -893,12 +884,11 @@ def test_get_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -910,7 +900,7 @@ def test_get_dataset_flattened_error(): @pytest.mark.asyncio async def test_get_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -926,13 +916,12 @@ async def test_get_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -946,7 +935,7 @@ def test_list_datasets( transport: str = "grpc", request_type=service.ListDatasetsRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -959,19 +948,15 @@ def test_list_datasets( call.return_value = service.ListDatasetsResponse( next_page_token="next_page_token_value", ) - response = client.list_datasets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListDatasetsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatasetsPager) - assert response.next_page_token == "next_page_token_value" @@ -983,7 +968,7 @@ def test_list_datasets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -991,7 +976,6 @@ def test_list_datasets_empty_call(): client.list_datasets() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListDatasetsRequest() @@ -1000,7 +984,7 @@ async def test_list_datasets_async( transport: str = "grpc_asyncio", request_type=service.ListDatasetsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1013,18 +997,15 @@ async def test_list_datasets_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListDatasetsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_datasets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListDatasetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDatasetsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1034,17 +1015,17 @@ async def test_list_datasets_async_from_dict(): def test_list_datasets_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListDatasetsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: call.return_value = service.ListDatasetsResponse() - client.list_datasets(request) # Establish that the underlying gRPC stub method was called. @@ -1059,11 +1040,12 @@ def test_list_datasets_field_headers(): @pytest.mark.asyncio async def test_list_datasets_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListDatasetsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1071,7 +1053,6 @@ async def test_list_datasets_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListDatasetsResponse() ) - await client.list_datasets(request) # Establish that the underlying gRPC stub method was called. @@ -1085,13 +1066,12 @@ async def test_list_datasets_field_headers_async(): def test_list_datasets_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListDatasetsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_datasets(parent="parent_value",) @@ -1100,12 +1080,11 @@ def test_list_datasets_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_datasets_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1117,7 +1096,7 @@ def test_list_datasets_flattened_error(): @pytest.mark.asyncio async def test_list_datasets_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1135,13 +1114,12 @@ async def test_list_datasets_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_datasets_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1152,7 +1130,7 @@ async def test_list_datasets_flattened_error_async(): def test_list_datasets_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1186,7 +1164,7 @@ def test_list_datasets_pager(): def test_list_datasets_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1212,7 +1190,7 @@ def test_list_datasets_pages(): @pytest.mark.asyncio async def test_list_datasets_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1245,7 +1223,7 @@ async def test_list_datasets_async_pager(): @pytest.mark.asyncio async def test_list_datasets_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1277,7 +1255,7 @@ def test_update_dataset( transport: str = "grpc", request_type=service.UpdateDatasetRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1297,27 +1275,19 @@ def test_update_dataset( source_language_code="source_language_code_value" ), ) - response = client.update_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateDatasetRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -1329,7 +1299,7 @@ def test_update_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1337,7 +1307,6 @@ def test_update_dataset_empty_call(): client.update_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateDatasetRequest() @@ -1346,7 +1315,7 @@ async def test_update_dataset_async( transport: str = "grpc_asyncio", request_type=service.UpdateDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1365,26 +1334,19 @@ async def test_update_dataset_async( etag="etag_value", ) ) - response = await client.update_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_dataset.Dataset) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.example_count == 1396 - assert response.etag == "etag_value" @@ -1394,17 +1356,17 @@ async def test_update_dataset_async_from_dict(): def test_update_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateDatasetRequest() + request.dataset.name = "dataset.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: call.return_value = gca_dataset.Dataset() - client.update_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1421,17 +1383,17 @@ def test_update_dataset_field_headers(): @pytest.mark.asyncio async def test_update_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateDatasetRequest() + request.dataset.name = "dataset.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_dataset.Dataset()) - await client.update_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1447,13 +1409,12 @@ async def test_update_dataset_field_headers_async(): def test_update_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gca_dataset.Dataset() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_dataset( @@ -1468,7 +1429,6 @@ def test_update_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" @@ -1477,7 +1437,7 @@ def test_update_dataset_flattened(): def test_update_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1494,7 +1454,7 @@ def test_update_dataset_flattened_error(): @pytest.mark.asyncio async def test_update_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1516,7 +1476,6 @@ async def test_update_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset( translation_dataset_metadata=translation.TranslationDatasetMetadata( source_language_code="source_language_code_value" @@ -1526,7 +1485,7 @@ async def test_update_dataset_flattened_async(): @pytest.mark.asyncio async def test_update_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1545,7 +1504,7 @@ def test_delete_dataset( transport: str = "grpc", request_type=service.DeleteDatasetRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1556,13 +1515,11 @@ def test_delete_dataset( with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteDatasetRequest() # Establish that the response is the type that we expect. @@ -1577,7 +1534,7 @@ def test_delete_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1585,7 +1542,6 @@ def test_delete_dataset_empty_call(): client.delete_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteDatasetRequest() @@ -1594,7 +1550,7 @@ async def test_delete_dataset_async( transport: str = "grpc_asyncio", request_type=service.DeleteDatasetRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1607,13 +1563,11 @@ async def test_delete_dataset_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteDatasetRequest() # Establish that the response is the type that we expect. @@ -1626,17 +1580,17 @@ async def test_delete_dataset_async_from_dict(): def test_delete_dataset_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1651,11 +1605,12 @@ def test_delete_dataset_field_headers(): @pytest.mark.asyncio async def test_delete_dataset_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteDatasetRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1663,7 +1618,6 @@ async def test_delete_dataset_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_dataset(request) # Establish that the underlying gRPC stub method was called. @@ -1677,13 +1631,12 @@ async def test_delete_dataset_field_headers_async(): def test_delete_dataset_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_dataset(name="name_value",) @@ -1692,12 +1645,11 @@ def test_delete_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_dataset_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1709,7 +1661,7 @@ def test_delete_dataset_flattened_error(): @pytest.mark.asyncio async def test_delete_dataset_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1727,13 +1679,12 @@ async def test_delete_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_dataset_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1745,7 +1696,7 @@ async def test_delete_dataset_flattened_error_async(): def test_import_data(transport: str = "grpc", request_type=service.ImportDataRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1756,13 +1707,11 @@ def test_import_data(transport: str = "grpc", request_type=service.ImportDataReq with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.import_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ImportDataRequest() # Establish that the response is the type that we expect. @@ -1777,7 +1726,7 @@ def test_import_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1785,7 +1734,6 @@ def test_import_data_empty_call(): client.import_data() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ImportDataRequest() @@ -1794,7 +1742,7 @@ async def test_import_data_async( transport: str = "grpc_asyncio", request_type=service.ImportDataRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1807,13 +1755,11 @@ async def test_import_data_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.import_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ImportDataRequest() # Establish that the response is the type that we expect. @@ -1826,17 +1772,17 @@ async def test_import_data_async_from_dict(): def test_import_data_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ImportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.import_data(request) # Establish that the underlying gRPC stub method was called. @@ -1851,11 +1797,12 @@ def test_import_data_field_headers(): @pytest.mark.asyncio async def test_import_data_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ImportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1863,7 +1810,6 @@ async def test_import_data_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.import_data(request) # Establish that the underlying gRPC stub method was called. @@ -1877,13 +1823,12 @@ async def test_import_data_field_headers_async(): def test_import_data_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.import_data( @@ -1897,16 +1842,14 @@ def test_import_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.InputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) def test_import_data_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1922,7 +1865,7 @@ def test_import_data_flattened_error(): @pytest.mark.asyncio async def test_import_data_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1945,9 +1888,7 @@ async def test_import_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.InputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) @@ -1955,7 +1896,7 @@ async def test_import_data_flattened_async(): @pytest.mark.asyncio async def test_import_data_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1971,7 +1912,7 @@ async def test_import_data_flattened_error_async(): def test_export_data(transport: str = "grpc", request_type=service.ExportDataRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1982,13 +1923,11 @@ def test_export_data(transport: str = "grpc", request_type=service.ExportDataReq with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportDataRequest() # Establish that the response is the type that we expect. @@ -2003,7 +1942,7 @@ def test_export_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2011,7 +1950,6 @@ def test_export_data_empty_call(): client.export_data() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportDataRequest() @@ -2020,7 +1958,7 @@ async def test_export_data_async( transport: str = "grpc_asyncio", request_type=service.ExportDataRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2033,13 +1971,11 @@ async def test_export_data_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportDataRequest() # Establish that the response is the type that we expect. @@ -2052,17 +1988,17 @@ async def test_export_data_async_from_dict(): def test_export_data_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_data(request) # Establish that the underlying gRPC stub method was called. @@ -2077,11 +2013,12 @@ def test_export_data_field_headers(): @pytest.mark.asyncio async def test_export_data_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportDataRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2089,7 +2026,6 @@ async def test_export_data_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_data(request) # Establish that the underlying gRPC stub method was called. @@ -2103,13 +2039,12 @@ async def test_export_data_field_headers_async(): def test_export_data_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_data( @@ -2125,9 +2060,7 @@ def test_export_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.OutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -2136,7 +2069,7 @@ def test_export_data_flattened(): def test_export_data_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2154,7 +2087,7 @@ def test_export_data_flattened_error(): @pytest.mark.asyncio async def test_export_data_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -2179,9 +2112,7 @@ async def test_export_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.OutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -2191,7 +2122,7 @@ async def test_export_data_flattened_async(): @pytest.mark.asyncio async def test_export_data_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2211,7 +2142,7 @@ def test_get_annotation_spec( transport: str = "grpc", request_type=service.GetAnnotationSpecRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2226,23 +2157,17 @@ def test_get_annotation_spec( call.return_value = annotation_spec.AnnotationSpec( name="name_value", display_name="display_name_value", example_count=1396, ) - response = client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAnnotationSpecRequest() # Establish that the response is the type that we expect. - assert isinstance(response, annotation_spec.AnnotationSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.example_count == 1396 @@ -2254,7 +2179,7 @@ def test_get_annotation_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2264,7 +2189,6 @@ def test_get_annotation_spec_empty_call(): client.get_annotation_spec() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAnnotationSpecRequest() @@ -2273,7 +2197,7 @@ async def test_get_annotation_spec_async( transport: str = "grpc_asyncio", request_type=service.GetAnnotationSpecRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2292,22 +2216,17 @@ async def test_get_annotation_spec_async( example_count=1396, ) ) - response = await client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAnnotationSpecRequest() # Establish that the response is the type that we expect. assert isinstance(response, annotation_spec.AnnotationSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.example_count == 1396 @@ -2317,11 +2236,12 @@ async def test_get_annotation_spec_async_from_dict(): def test_get_annotation_spec_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAnnotationSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2329,7 +2249,6 @@ def test_get_annotation_spec_field_headers(): type(client.transport.get_annotation_spec), "__call__" ) as call: call.return_value = annotation_spec.AnnotationSpec() - client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. @@ -2344,11 +2263,12 @@ def test_get_annotation_spec_field_headers(): @pytest.mark.asyncio async def test_get_annotation_spec_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAnnotationSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2358,7 +2278,6 @@ async def test_get_annotation_spec_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( annotation_spec.AnnotationSpec() ) - await client.get_annotation_spec(request) # Establish that the underlying gRPC stub method was called. @@ -2372,7 +2291,7 @@ async def test_get_annotation_spec_field_headers_async(): def test_get_annotation_spec_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2380,7 +2299,6 @@ def test_get_annotation_spec_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec.AnnotationSpec() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_annotation_spec(name="name_value",) @@ -2389,12 +2307,11 @@ def test_get_annotation_spec_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_annotation_spec_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2406,7 +2323,7 @@ def test_get_annotation_spec_flattened_error(): @pytest.mark.asyncio async def test_get_annotation_spec_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2426,13 +2343,12 @@ async def test_get_annotation_spec_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_annotation_spec_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2446,7 +2362,7 @@ def test_get_table_spec( transport: str = "grpc", request_type=service.GetTableSpecRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2464,29 +2380,20 @@ def test_get_table_spec( column_count=1302, etag="etag_value", ) - response = client.get_table_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetTableSpecRequest() # Establish that the response is the type that we expect. - assert isinstance(response, table_spec.TableSpec) - assert response.name == "name_value" - assert response.time_column_spec_id == "time_column_spec_id_value" - assert response.row_count == 992 - assert response.valid_row_count == 1615 - assert response.column_count == 1302 - assert response.etag == "etag_value" @@ -2498,7 +2405,7 @@ def test_get_table_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2506,7 +2413,6 @@ def test_get_table_spec_empty_call(): client.get_table_spec() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetTableSpecRequest() @@ -2515,7 +2421,7 @@ async def test_get_table_spec_async( transport: str = "grpc_asyncio", request_type=service.GetTableSpecRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2535,28 +2441,20 @@ async def test_get_table_spec_async( etag="etag_value", ) ) - response = await client.get_table_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetTableSpecRequest() # Establish that the response is the type that we expect. assert isinstance(response, table_spec.TableSpec) - assert response.name == "name_value" - assert response.time_column_spec_id == "time_column_spec_id_value" - assert response.row_count == 992 - assert response.valid_row_count == 1615 - assert response.column_count == 1302 - assert response.etag == "etag_value" @@ -2566,17 +2464,17 @@ async def test_get_table_spec_async_from_dict(): def test_get_table_spec_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetTableSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_table_spec), "__call__") as call: call.return_value = table_spec.TableSpec() - client.get_table_spec(request) # Establish that the underlying gRPC stub method was called. @@ -2591,11 +2489,12 @@ def test_get_table_spec_field_headers(): @pytest.mark.asyncio async def test_get_table_spec_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetTableSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2603,7 +2502,6 @@ async def test_get_table_spec_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( table_spec.TableSpec() ) - await client.get_table_spec(request) # Establish that the underlying gRPC stub method was called. @@ -2617,13 +2515,12 @@ async def test_get_table_spec_field_headers_async(): def test_get_table_spec_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_table_spec), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = table_spec.TableSpec() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_table_spec(name="name_value",) @@ -2632,12 +2529,11 @@ def test_get_table_spec_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_table_spec_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2649,7 +2545,7 @@ def test_get_table_spec_flattened_error(): @pytest.mark.asyncio async def test_get_table_spec_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_table_spec), "__call__") as call: @@ -2667,13 +2563,12 @@ async def test_get_table_spec_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_table_spec_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2687,7 +2582,7 @@ def test_list_table_specs( transport: str = "grpc", request_type=service.ListTableSpecsRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2700,19 +2595,15 @@ def test_list_table_specs( call.return_value = service.ListTableSpecsResponse( next_page_token="next_page_token_value", ) - response = client.list_table_specs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListTableSpecsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTableSpecsPager) - assert response.next_page_token == "next_page_token_value" @@ -2724,7 +2615,7 @@ def test_list_table_specs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2732,7 +2623,6 @@ def test_list_table_specs_empty_call(): client.list_table_specs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListTableSpecsRequest() @@ -2741,7 +2631,7 @@ async def test_list_table_specs_async( transport: str = "grpc_asyncio", request_type=service.ListTableSpecsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2754,18 +2644,15 @@ async def test_list_table_specs_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListTableSpecsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_table_specs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListTableSpecsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListTableSpecsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2775,17 +2662,17 @@ async def test_list_table_specs_async_from_dict(): def test_list_table_specs_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListTableSpecsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_table_specs), "__call__") as call: call.return_value = service.ListTableSpecsResponse() - client.list_table_specs(request) # Establish that the underlying gRPC stub method was called. @@ -2800,11 +2687,12 @@ def test_list_table_specs_field_headers(): @pytest.mark.asyncio async def test_list_table_specs_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListTableSpecsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2812,7 +2700,6 @@ async def test_list_table_specs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListTableSpecsResponse() ) - await client.list_table_specs(request) # Establish that the underlying gRPC stub method was called. @@ -2826,13 +2713,12 @@ async def test_list_table_specs_field_headers_async(): def test_list_table_specs_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_table_specs), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListTableSpecsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_table_specs(parent="parent_value",) @@ -2841,12 +2727,11 @@ def test_list_table_specs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_table_specs_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2858,7 +2743,7 @@ def test_list_table_specs_flattened_error(): @pytest.mark.asyncio async def test_list_table_specs_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_table_specs), "__call__") as call: @@ -2876,13 +2761,12 @@ async def test_list_table_specs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_table_specs_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2893,7 +2777,7 @@ async def test_list_table_specs_flattened_error_async(): def test_list_table_specs_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_table_specs), "__call__") as call: @@ -2931,7 +2815,7 @@ def test_list_table_specs_pager(): def test_list_table_specs_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_table_specs), "__call__") as call: @@ -2961,7 +2845,7 @@ def test_list_table_specs_pages(): @pytest.mark.asyncio async def test_list_table_specs_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2998,7 +2882,7 @@ async def test_list_table_specs_async_pager(): @pytest.mark.asyncio async def test_list_table_specs_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3034,7 +2918,7 @@ def test_update_table_spec( transport: str = "grpc", request_type=service.UpdateTableSpecRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3054,29 +2938,20 @@ def test_update_table_spec( column_count=1302, etag="etag_value", ) - response = client.update_table_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateTableSpecRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_table_spec.TableSpec) - assert response.name == "name_value" - assert response.time_column_spec_id == "time_column_spec_id_value" - assert response.row_count == 992 - assert response.valid_row_count == 1615 - assert response.column_count == 1302 - assert response.etag == "etag_value" @@ -3088,7 +2963,7 @@ def test_update_table_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3098,7 +2973,6 @@ def test_update_table_spec_empty_call(): client.update_table_spec() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateTableSpecRequest() @@ -3107,7 +2981,7 @@ async def test_update_table_spec_async( transport: str = "grpc_asyncio", request_type=service.UpdateTableSpecRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3129,28 +3003,20 @@ async def test_update_table_spec_async( etag="etag_value", ) ) - response = await client.update_table_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateTableSpecRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_table_spec.TableSpec) - assert response.name == "name_value" - assert response.time_column_spec_id == "time_column_spec_id_value" - assert response.row_count == 992 - assert response.valid_row_count == 1615 - assert response.column_count == 1302 - assert response.etag == "etag_value" @@ -3160,11 +3026,12 @@ async def test_update_table_spec_async_from_dict(): def test_update_table_spec_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateTableSpecRequest() + request.table_spec.name = "table_spec.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3172,7 +3039,6 @@ def test_update_table_spec_field_headers(): type(client.transport.update_table_spec), "__call__" ) as call: call.return_value = gca_table_spec.TableSpec() - client.update_table_spec(request) # Establish that the underlying gRPC stub method was called. @@ -3189,11 +3055,12 @@ def test_update_table_spec_field_headers(): @pytest.mark.asyncio async def test_update_table_spec_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateTableSpecRequest() + request.table_spec.name = "table_spec.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3203,7 +3070,6 @@ async def test_update_table_spec_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gca_table_spec.TableSpec() ) - await client.update_table_spec(request) # Establish that the underlying gRPC stub method was called. @@ -3219,7 +3085,7 @@ async def test_update_table_spec_field_headers_async(): def test_update_table_spec_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3227,7 +3093,6 @@ def test_update_table_spec_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gca_table_spec.TableSpec() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_table_spec( @@ -3238,12 +3103,11 @@ def test_update_table_spec_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].table_spec == gca_table_spec.TableSpec(name="name_value") def test_update_table_spec_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3256,7 +3120,7 @@ def test_update_table_spec_flattened_error(): @pytest.mark.asyncio async def test_update_table_spec_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3278,13 +3142,12 @@ async def test_update_table_spec_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].table_spec == gca_table_spec.TableSpec(name="name_value") @pytest.mark.asyncio async def test_update_table_spec_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3299,7 +3162,7 @@ def test_get_column_spec( transport: str = "grpc", request_type=service.GetColumnSpecRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3312,23 +3175,17 @@ def test_get_column_spec( call.return_value = column_spec.ColumnSpec( name="name_value", display_name="display_name_value", etag="etag_value", ) - response = client.get_column_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetColumnSpecRequest() # Establish that the response is the type that we expect. - assert isinstance(response, column_spec.ColumnSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -3340,7 +3197,7 @@ def test_get_column_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3348,7 +3205,6 @@ def test_get_column_spec_empty_call(): client.get_column_spec() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetColumnSpecRequest() @@ -3357,7 +3213,7 @@ async def test_get_column_spec_async( transport: str = "grpc_asyncio", request_type=service.GetColumnSpecRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3372,22 +3228,17 @@ async def test_get_column_spec_async( name="name_value", display_name="display_name_value", etag="etag_value", ) ) - response = await client.get_column_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetColumnSpecRequest() # Establish that the response is the type that we expect. assert isinstance(response, column_spec.ColumnSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -3397,17 +3248,17 @@ async def test_get_column_spec_async_from_dict(): def test_get_column_spec_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetColumnSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_column_spec), "__call__") as call: call.return_value = column_spec.ColumnSpec() - client.get_column_spec(request) # Establish that the underlying gRPC stub method was called. @@ -3422,11 +3273,12 @@ def test_get_column_spec_field_headers(): @pytest.mark.asyncio async def test_get_column_spec_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetColumnSpecRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3434,7 +3286,6 @@ async def test_get_column_spec_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( column_spec.ColumnSpec() ) - await client.get_column_spec(request) # Establish that the underlying gRPC stub method was called. @@ -3448,13 +3299,12 @@ async def test_get_column_spec_field_headers_async(): def test_get_column_spec_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_column_spec), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = column_spec.ColumnSpec() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_column_spec(name="name_value",) @@ -3463,12 +3313,11 @@ def test_get_column_spec_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_column_spec_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3480,7 +3329,7 @@ def test_get_column_spec_flattened_error(): @pytest.mark.asyncio async def test_get_column_spec_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_column_spec), "__call__") as call: @@ -3498,13 +3347,12 @@ async def test_get_column_spec_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_column_spec_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3518,7 +3366,7 @@ def test_list_column_specs( transport: str = "grpc", request_type=service.ListColumnSpecsRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3533,19 +3381,15 @@ def test_list_column_specs( call.return_value = service.ListColumnSpecsResponse( next_page_token="next_page_token_value", ) - response = client.list_column_specs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListColumnSpecsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListColumnSpecsPager) - assert response.next_page_token == "next_page_token_value" @@ -3557,7 +3401,7 @@ def test_list_column_specs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3567,7 +3411,6 @@ def test_list_column_specs_empty_call(): client.list_column_specs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListColumnSpecsRequest() @@ -3576,7 +3419,7 @@ async def test_list_column_specs_async( transport: str = "grpc_asyncio", request_type=service.ListColumnSpecsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3591,18 +3434,15 @@ async def test_list_column_specs_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListColumnSpecsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_column_specs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListColumnSpecsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListColumnSpecsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -3612,11 +3452,12 @@ async def test_list_column_specs_async_from_dict(): def test_list_column_specs_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListColumnSpecsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3624,7 +3465,6 @@ def test_list_column_specs_field_headers(): type(client.transport.list_column_specs), "__call__" ) as call: call.return_value = service.ListColumnSpecsResponse() - client.list_column_specs(request) # Establish that the underlying gRPC stub method was called. @@ -3639,11 +3479,12 @@ def test_list_column_specs_field_headers(): @pytest.mark.asyncio async def test_list_column_specs_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListColumnSpecsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3653,7 +3494,6 @@ async def test_list_column_specs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListColumnSpecsResponse() ) - await client.list_column_specs(request) # Establish that the underlying gRPC stub method was called. @@ -3667,7 +3507,7 @@ async def test_list_column_specs_field_headers_async(): def test_list_column_specs_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3675,7 +3515,6 @@ def test_list_column_specs_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = service.ListColumnSpecsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_column_specs(parent="parent_value",) @@ -3684,12 +3523,11 @@ def test_list_column_specs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_column_specs_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3701,7 +3539,7 @@ def test_list_column_specs_flattened_error(): @pytest.mark.asyncio async def test_list_column_specs_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3721,13 +3559,12 @@ async def test_list_column_specs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_column_specs_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3738,7 +3575,7 @@ async def test_list_column_specs_flattened_error_async(): def test_list_column_specs_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3778,7 +3615,7 @@ def test_list_column_specs_pager(): def test_list_column_specs_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3810,7 +3647,7 @@ def test_list_column_specs_pages(): @pytest.mark.asyncio async def test_list_column_specs_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3849,7 +3686,7 @@ async def test_list_column_specs_async_pager(): @pytest.mark.asyncio async def test_list_column_specs_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3887,7 +3724,7 @@ def test_update_column_spec( transport: str = "grpc", request_type=service.UpdateColumnSpecRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3902,23 +3739,17 @@ def test_update_column_spec( call.return_value = gca_column_spec.ColumnSpec( name="name_value", display_name="display_name_value", etag="etag_value", ) - response = client.update_column_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateColumnSpecRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_column_spec.ColumnSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -3930,7 +3761,7 @@ def test_update_column_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3940,7 +3771,6 @@ def test_update_column_spec_empty_call(): client.update_column_spec() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateColumnSpecRequest() @@ -3949,7 +3779,7 @@ async def test_update_column_spec_async( transport: str = "grpc_asyncio", request_type=service.UpdateColumnSpecRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3966,22 +3796,17 @@ async def test_update_column_spec_async( name="name_value", display_name="display_name_value", etag="etag_value", ) ) - response = await client.update_column_spec(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateColumnSpecRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_column_spec.ColumnSpec) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -3991,11 +3816,12 @@ async def test_update_column_spec_async_from_dict(): def test_update_column_spec_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateColumnSpecRequest() + request.column_spec.name = "column_spec.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4003,7 +3829,6 @@ def test_update_column_spec_field_headers(): type(client.transport.update_column_spec), "__call__" ) as call: call.return_value = gca_column_spec.ColumnSpec() - client.update_column_spec(request) # Establish that the underlying gRPC stub method was called. @@ -4020,11 +3845,12 @@ def test_update_column_spec_field_headers(): @pytest.mark.asyncio async def test_update_column_spec_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateColumnSpecRequest() + request.column_spec.name = "column_spec.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4034,7 +3860,6 @@ async def test_update_column_spec_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gca_column_spec.ColumnSpec() ) - await client.update_column_spec(request) # Establish that the underlying gRPC stub method was called. @@ -4050,7 +3875,7 @@ async def test_update_column_spec_field_headers_async(): def test_update_column_spec_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4058,7 +3883,6 @@ def test_update_column_spec_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gca_column_spec.ColumnSpec() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_column_spec( @@ -4069,12 +3893,11 @@ def test_update_column_spec_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].column_spec == gca_column_spec.ColumnSpec(name="name_value") def test_update_column_spec_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4087,7 +3910,7 @@ def test_update_column_spec_flattened_error(): @pytest.mark.asyncio async def test_update_column_spec_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4109,13 +3932,12 @@ async def test_update_column_spec_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].column_spec == gca_column_spec.ColumnSpec(name="name_value") @pytest.mark.asyncio async def test_update_column_spec_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4128,7 +3950,7 @@ async def test_update_column_spec_flattened_error_async(): def test_create_model(transport: str = "grpc", request_type=service.CreateModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4139,13 +3961,11 @@ def test_create_model(transport: str = "grpc", request_type=service.CreateModelR with mock.patch.object(type(client.transport.create_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateModelRequest() # Establish that the response is the type that we expect. @@ -4160,7 +3980,7 @@ def test_create_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4168,7 +3988,6 @@ def test_create_model_empty_call(): client.create_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateModelRequest() @@ -4177,7 +3996,7 @@ async def test_create_model_async( transport: str = "grpc_asyncio", request_type=service.CreateModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4190,13 +4009,11 @@ async def test_create_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateModelRequest() # Establish that the response is the type that we expect. @@ -4209,17 +4026,17 @@ async def test_create_model_async_from_dict(): def test_create_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateModelRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_model(request) # Establish that the underlying gRPC stub method was called. @@ -4234,11 +4051,12 @@ def test_create_model_field_headers(): @pytest.mark.asyncio async def test_create_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateModelRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4246,7 +4064,6 @@ async def test_create_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_model(request) # Establish that the underlying gRPC stub method was called. @@ -4260,13 +4077,12 @@ async def test_create_model_field_headers_async(): def test_create_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_model( @@ -4282,9 +4098,7 @@ def test_create_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model( translation_model_metadata=translation.TranslationModelMetadata( base_model="base_model_value" @@ -4293,7 +4107,7 @@ def test_create_model_flattened(): def test_create_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4311,7 +4125,7 @@ def test_create_model_flattened_error(): @pytest.mark.asyncio async def test_create_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_model), "__call__") as call: @@ -4336,9 +4150,7 @@ async def test_create_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model( translation_model_metadata=translation.TranslationModelMetadata( base_model="base_model_value" @@ -4348,7 +4160,7 @@ async def test_create_model_flattened_async(): @pytest.mark.asyncio async def test_create_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4366,7 +4178,7 @@ async def test_create_model_flattened_error_async(): def test_get_model(transport: str = "grpc", request_type=service.GetModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4385,25 +4197,18 @@ def test_get_model(transport: str = "grpc", request_type=service.GetModelRequest base_model="base_model_value" ), ) - response = client.get_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.dataset_id == "dataset_id_value" - assert response.deployment_state == model.Model.DeploymentState.DEPLOYED @@ -4415,7 +4220,7 @@ def test_get_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4423,7 +4228,6 @@ def test_get_model_empty_call(): client.get_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelRequest() @@ -4432,7 +4236,7 @@ async def test_get_model_async( transport: str = "grpc_asyncio", request_type=service.GetModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4450,24 +4254,18 @@ async def test_get_model_async( deployment_state=model.Model.DeploymentState.DEPLOYED, ) ) - response = await client.get_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelRequest() # Establish that the response is the type that we expect. assert isinstance(response, model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.dataset_id == "dataset_id_value" - assert response.deployment_state == model.Model.DeploymentState.DEPLOYED @@ -4477,17 +4275,17 @@ async def test_get_model_async_from_dict(): def test_get_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: call.return_value = model.Model() - client.get_model(request) # Establish that the underlying gRPC stub method was called. @@ -4502,17 +4300,17 @@ def test_get_model_field_headers(): @pytest.mark.asyncio async def test_get_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) - await client.get_model(request) # Establish that the underlying gRPC stub method was called. @@ -4526,13 +4324,12 @@ async def test_get_model_field_headers_async(): def test_get_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = model.Model() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_model(name="name_value",) @@ -4541,12 +4338,11 @@ def test_get_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4558,7 +4354,7 @@ def test_get_model_flattened_error(): @pytest.mark.asyncio async def test_get_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -4574,13 +4370,12 @@ async def test_get_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4592,7 +4387,7 @@ async def test_get_model_flattened_error_async(): def test_list_models(transport: str = "grpc", request_type=service.ListModelsRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4605,19 +4400,15 @@ def test_list_models(transport: str = "grpc", request_type=service.ListModelsReq call.return_value = service.ListModelsResponse( next_page_token="next_page_token_value", ) - response = client.list_models(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelsPager) - assert response.next_page_token == "next_page_token_value" @@ -4629,7 +4420,7 @@ def test_list_models_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4637,7 +4428,6 @@ def test_list_models_empty_call(): client.list_models() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelsRequest() @@ -4646,7 +4436,7 @@ async def test_list_models_async( transport: str = "grpc_asyncio", request_type=service.ListModelsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4659,18 +4449,15 @@ async def test_list_models_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListModelsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_models(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListModelsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -4680,17 +4467,17 @@ async def test_list_models_async_from_dict(): def test_list_models_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: call.return_value = service.ListModelsResponse() - client.list_models(request) # Establish that the underlying gRPC stub method was called. @@ -4705,11 +4492,12 @@ def test_list_models_field_headers(): @pytest.mark.asyncio async def test_list_models_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4717,7 +4505,6 @@ async def test_list_models_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListModelsResponse() ) - await client.list_models(request) # Establish that the underlying gRPC stub method was called. @@ -4731,13 +4518,12 @@ async def test_list_models_field_headers_async(): def test_list_models_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListModelsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_models(parent="parent_value",) @@ -4746,12 +4532,11 @@ def test_list_models_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_models_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4763,7 +4548,7 @@ def test_list_models_flattened_error(): @pytest.mark.asyncio async def test_list_models_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -4781,13 +4566,12 @@ async def test_list_models_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_models_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4798,7 +4582,7 @@ async def test_list_models_flattened_error_async(): def test_list_models_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -4828,7 +4612,7 @@ def test_list_models_pager(): def test_list_models_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -4850,7 +4634,7 @@ def test_list_models_pages(): @pytest.mark.asyncio async def test_list_models_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4879,7 +4663,7 @@ async def test_list_models_async_pager(): @pytest.mark.asyncio async def test_list_models_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4905,7 +4689,7 @@ async def test_list_models_async_pages(): def test_delete_model(transport: str = "grpc", request_type=service.DeleteModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4916,13 +4700,11 @@ def test_delete_model(transport: str = "grpc", request_type=service.DeleteModelR with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteModelRequest() # Establish that the response is the type that we expect. @@ -4937,7 +4719,7 @@ def test_delete_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4945,7 +4727,6 @@ def test_delete_model_empty_call(): client.delete_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteModelRequest() @@ -4954,7 +4735,7 @@ async def test_delete_model_async( transport: str = "grpc_asyncio", request_type=service.DeleteModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4967,13 +4748,11 @@ async def test_delete_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteModelRequest() # Establish that the response is the type that we expect. @@ -4986,17 +4765,17 @@ async def test_delete_model_async_from_dict(): def test_delete_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_model(request) # Establish that the underlying gRPC stub method was called. @@ -5011,11 +4790,12 @@ def test_delete_model_field_headers(): @pytest.mark.asyncio async def test_delete_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -5023,7 +4803,6 @@ async def test_delete_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_model(request) # Establish that the underlying gRPC stub method was called. @@ -5037,13 +4816,12 @@ async def test_delete_model_field_headers_async(): def test_delete_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_model(name="name_value",) @@ -5052,12 +4830,11 @@ def test_delete_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5069,7 +4846,7 @@ def test_delete_model_flattened_error(): @pytest.mark.asyncio async def test_delete_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_model), "__call__") as call: @@ -5087,13 +4864,12 @@ async def test_delete_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5105,7 +4881,7 @@ async def test_delete_model_flattened_error_async(): def test_deploy_model(transport: str = "grpc", request_type=service.DeployModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5116,13 +4892,11 @@ def test_deploy_model(transport: str = "grpc", request_type=service.DeployModelR with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.deploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeployModelRequest() # Establish that the response is the type that we expect. @@ -5137,7 +4911,7 @@ def test_deploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5145,7 +4919,6 @@ def test_deploy_model_empty_call(): client.deploy_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeployModelRequest() @@ -5154,7 +4927,7 @@ async def test_deploy_model_async( transport: str = "grpc_asyncio", request_type=service.DeployModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5167,13 +4940,11 @@ async def test_deploy_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.deploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeployModelRequest() # Establish that the response is the type that we expect. @@ -5186,17 +4957,17 @@ async def test_deploy_model_async_from_dict(): def test_deploy_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.deploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -5211,11 +4982,12 @@ def test_deploy_model_field_headers(): @pytest.mark.asyncio async def test_deploy_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -5223,7 +4995,6 @@ async def test_deploy_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.deploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -5237,13 +5008,12 @@ async def test_deploy_model_field_headers_async(): def test_deploy_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.deploy_model(name="name_value",) @@ -5252,12 +5022,11 @@ def test_deploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_deploy_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5269,7 +5038,7 @@ def test_deploy_model_flattened_error(): @pytest.mark.asyncio async def test_deploy_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -5287,13 +5056,12 @@ async def test_deploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_deploy_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5307,7 +5075,7 @@ def test_undeploy_model( transport: str = "grpc", request_type=service.UndeployModelRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5318,13 +5086,11 @@ def test_undeploy_model( with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UndeployModelRequest() # Establish that the response is the type that we expect. @@ -5339,7 +5105,7 @@ def test_undeploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5347,7 +5113,6 @@ def test_undeploy_model_empty_call(): client.undeploy_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UndeployModelRequest() @@ -5356,7 +5121,7 @@ async def test_undeploy_model_async( transport: str = "grpc_asyncio", request_type=service.UndeployModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5369,13 +5134,11 @@ async def test_undeploy_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UndeployModelRequest() # Establish that the response is the type that we expect. @@ -5388,17 +5151,17 @@ async def test_undeploy_model_async_from_dict(): def test_undeploy_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UndeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -5413,11 +5176,12 @@ def test_undeploy_model_field_headers(): @pytest.mark.asyncio async def test_undeploy_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UndeployModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -5425,7 +5189,6 @@ async def test_undeploy_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.undeploy_model(request) # Establish that the underlying gRPC stub method was called. @@ -5439,13 +5202,12 @@ async def test_undeploy_model_field_headers_async(): def test_undeploy_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.undeploy_model(name="name_value",) @@ -5454,12 +5216,11 @@ def test_undeploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_undeploy_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5471,7 +5232,7 @@ def test_undeploy_model_flattened_error(): @pytest.mark.asyncio async def test_undeploy_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -5489,13 +5250,12 @@ async def test_undeploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_undeploy_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5507,7 +5267,7 @@ async def test_undeploy_model_flattened_error_async(): def test_export_model(transport: str = "grpc", request_type=service.ExportModelRequest): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5518,13 +5278,11 @@ def test_export_model(transport: str = "grpc", request_type=service.ExportModelR with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportModelRequest() # Establish that the response is the type that we expect. @@ -5539,7 +5297,7 @@ def test_export_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5547,7 +5305,6 @@ def test_export_model_empty_call(): client.export_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportModelRequest() @@ -5556,7 +5313,7 @@ async def test_export_model_async( transport: str = "grpc_asyncio", request_type=service.ExportModelRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5569,13 +5326,11 @@ async def test_export_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportModelRequest() # Establish that the response is the type that we expect. @@ -5588,17 +5343,17 @@ async def test_export_model_async_from_dict(): def test_export_model_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_model(request) # Establish that the underlying gRPC stub method was called. @@ -5613,11 +5368,12 @@ def test_export_model_field_headers(): @pytest.mark.asyncio async def test_export_model_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportModelRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -5625,7 +5381,6 @@ async def test_export_model_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_model(request) # Establish that the underlying gRPC stub method was called. @@ -5639,13 +5394,12 @@ async def test_export_model_field_headers_async(): def test_export_model_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_model( @@ -5661,9 +5415,7 @@ def test_export_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.ModelExportOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -5672,7 +5424,7 @@ def test_export_model_flattened(): def test_export_model_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5690,7 +5442,7 @@ def test_export_model_flattened_error(): @pytest.mark.asyncio async def test_export_model_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_model), "__call__") as call: @@ -5715,9 +5467,7 @@ async def test_export_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.ModelExportOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" @@ -5727,7 +5477,7 @@ async def test_export_model_flattened_async(): @pytest.mark.asyncio async def test_export_model_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5747,7 +5497,7 @@ def test_export_evaluated_examples( transport: str = "grpc", request_type=service.ExportEvaluatedExamplesRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5760,13 +5510,11 @@ def test_export_evaluated_examples( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_evaluated_examples(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportEvaluatedExamplesRequest() # Establish that the response is the type that we expect. @@ -5781,7 +5529,7 @@ def test_export_evaluated_examples_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5791,7 +5539,6 @@ def test_export_evaluated_examples_empty_call(): client.export_evaluated_examples() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportEvaluatedExamplesRequest() @@ -5800,7 +5547,7 @@ async def test_export_evaluated_examples_async( transport: str = "grpc_asyncio", request_type=service.ExportEvaluatedExamplesRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5815,13 +5562,11 @@ async def test_export_evaluated_examples_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_evaluated_examples(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ExportEvaluatedExamplesRequest() # Establish that the response is the type that we expect. @@ -5834,11 +5579,12 @@ async def test_export_evaluated_examples_async_from_dict(): def test_export_evaluated_examples_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportEvaluatedExamplesRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -5846,7 +5592,6 @@ def test_export_evaluated_examples_field_headers(): type(client.transport.export_evaluated_examples), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_evaluated_examples(request) # Establish that the underlying gRPC stub method was called. @@ -5861,11 +5606,12 @@ def test_export_evaluated_examples_field_headers(): @pytest.mark.asyncio async def test_export_evaluated_examples_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ExportEvaluatedExamplesRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -5875,7 +5621,6 @@ async def test_export_evaluated_examples_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_evaluated_examples(request) # Establish that the underlying gRPC stub method was called. @@ -5889,7 +5634,7 @@ async def test_export_evaluated_examples_field_headers_async(): def test_export_evaluated_examples_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5897,7 +5642,6 @@ def test_export_evaluated_examples_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_evaluated_examples( @@ -5913,16 +5657,14 @@ def test_export_evaluated_examples_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.ExportEvaluatedExamplesOutputConfig( bigquery_destination=io.BigQueryDestination(output_uri="output_uri_value") ) def test_export_evaluated_examples_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5940,7 +5682,7 @@ def test_export_evaluated_examples_flattened_error(): @pytest.mark.asyncio async def test_export_evaluated_examples_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5967,9 +5709,7 @@ async def test_export_evaluated_examples_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == io.ExportEvaluatedExamplesOutputConfig( bigquery_destination=io.BigQueryDestination(output_uri="output_uri_value") ) @@ -5977,7 +5717,7 @@ async def test_export_evaluated_examples_flattened_async(): @pytest.mark.asyncio async def test_export_evaluated_examples_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5997,7 +5737,7 @@ def test_get_model_evaluation( transport: str = "grpc", request_type=service.GetModelEvaluationRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6018,25 +5758,18 @@ def test_get_model_evaluation( au_prc=0.634 ), ) - response = client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelEvaluationRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.annotation_spec_id == "annotation_spec_id_value" - assert response.display_name == "display_name_value" - assert response.evaluated_example_count == 2446 @@ -6048,7 +5781,7 @@ def test_get_model_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6058,7 +5791,6 @@ def test_get_model_evaluation_empty_call(): client.get_model_evaluation() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelEvaluationRequest() @@ -6067,7 +5799,7 @@ async def test_get_model_evaluation_async( transport: str = "grpc_asyncio", request_type=service.GetModelEvaluationRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6087,24 +5819,18 @@ async def test_get_model_evaluation_async( evaluated_example_count=2446, ) ) - response = await client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetModelEvaluationRequest() # Establish that the response is the type that we expect. assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.annotation_spec_id == "annotation_spec_id_value" - assert response.display_name == "display_name_value" - assert response.evaluated_example_count == 2446 @@ -6114,11 +5840,12 @@ async def test_get_model_evaluation_async_from_dict(): def test_get_model_evaluation_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelEvaluationRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -6126,7 +5853,6 @@ def test_get_model_evaluation_field_headers(): type(client.transport.get_model_evaluation), "__call__" ) as call: call.return_value = model_evaluation.ModelEvaluation() - client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. @@ -6141,11 +5867,12 @@ def test_get_model_evaluation_field_headers(): @pytest.mark.asyncio async def test_get_model_evaluation_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetModelEvaluationRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -6155,7 +5882,6 @@ async def test_get_model_evaluation_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( model_evaluation.ModelEvaluation() ) - await client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. @@ -6169,7 +5895,7 @@ async def test_get_model_evaluation_field_headers_async(): def test_get_model_evaluation_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6177,7 +5903,6 @@ def test_get_model_evaluation_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = model_evaluation.ModelEvaluation() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_model_evaluation(name="name_value",) @@ -6186,12 +5911,11 @@ def test_get_model_evaluation_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_model_evaluation_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6203,7 +5927,7 @@ def test_get_model_evaluation_flattened_error(): @pytest.mark.asyncio async def test_get_model_evaluation_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6223,13 +5947,12 @@ async def test_get_model_evaluation_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_model_evaluation_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6243,7 +5966,7 @@ def test_list_model_evaluations( transport: str = "grpc", request_type=service.ListModelEvaluationsRequest ): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6258,19 +5981,15 @@ def test_list_model_evaluations( call.return_value = service.ListModelEvaluationsResponse( next_page_token="next_page_token_value", ) - response = client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelEvaluationsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationsPager) - assert response.next_page_token == "next_page_token_value" @@ -6282,7 +6001,7 @@ def test_list_model_evaluations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6292,7 +6011,6 @@ def test_list_model_evaluations_empty_call(): client.list_model_evaluations() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelEvaluationsRequest() @@ -6301,7 +6019,7 @@ async def test_list_model_evaluations_async( transport: str = "grpc_asyncio", request_type=service.ListModelEvaluationsRequest ): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6318,18 +6036,15 @@ async def test_list_model_evaluations_async( next_page_token="next_page_token_value", ) ) - response = await client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListModelEvaluationsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListModelEvaluationsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -6339,11 +6054,12 @@ async def test_list_model_evaluations_async_from_dict(): def test_list_model_evaluations_field_headers(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelEvaluationsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -6351,7 +6067,6 @@ def test_list_model_evaluations_field_headers(): type(client.transport.list_model_evaluations), "__call__" ) as call: call.return_value = service.ListModelEvaluationsResponse() - client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. @@ -6366,11 +6081,12 @@ def test_list_model_evaluations_field_headers(): @pytest.mark.asyncio async def test_list_model_evaluations_field_headers_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListModelEvaluationsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -6380,7 +6096,6 @@ async def test_list_model_evaluations_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListModelEvaluationsResponse() ) - await client.list_model_evaluations(request) # Establish that the underlying gRPC stub method was called. @@ -6394,7 +6109,7 @@ async def test_list_model_evaluations_field_headers_async(): def test_list_model_evaluations_flattened(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6402,7 +6117,6 @@ def test_list_model_evaluations_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = service.ListModelEvaluationsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_model_evaluations(parent="parent_value",) @@ -6411,12 +6125,11 @@ def test_list_model_evaluations_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_model_evaluations_flattened_error(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6428,7 +6141,7 @@ def test_list_model_evaluations_flattened_error(): @pytest.mark.asyncio async def test_list_model_evaluations_flattened_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6448,13 +6161,12 @@ async def test_list_model_evaluations_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_model_evaluations_flattened_error_async(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6465,7 +6177,7 @@ async def test_list_model_evaluations_flattened_error_async(): def test_list_model_evaluations_pager(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6511,7 +6223,7 @@ def test_list_model_evaluations_pager(): def test_list_model_evaluations_pages(): - client = AutoMlClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6549,7 +6261,7 @@ def test_list_model_evaluations_pages(): @pytest.mark.asyncio async def test_list_model_evaluations_async_pager(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6594,7 +6306,7 @@ async def test_list_model_evaluations_async_pager(): @pytest.mark.asyncio async def test_list_model_evaluations_async_pages(): - client = AutoMlAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AutoMlAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6637,16 +6349,16 @@ async def test_list_model_evaluations_async_pages(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AutoMlClient( @@ -6656,7 +6368,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AutoMlClient( @@ -6667,7 +6379,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = AutoMlClient(transport=transport) assert client.transport is transport @@ -6676,13 +6388,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AutoMlGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.AutoMlGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -6694,23 +6406,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = AutoMlClient(credentials=credentials.AnonymousCredentials(),) + client = AutoMlClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.AutoMlGrpcTransport,) def test_auto_ml_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AutoMlTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -6722,7 +6434,7 @@ def test_auto_ml_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AutoMlTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -6763,15 +6475,37 @@ def test_auto_ml_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_auto_ml_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.AutoMlTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_auto_ml_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -6784,19 +6518,33 @@ def test_auto_ml_base_transport_with_credentials_file(): def test_auto_ml_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_auto_ml_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + AutoMlClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_auto_ml_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) AutoMlClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -6804,26 +6552,152 @@ def test_auto_ml_auth_adc(): ) -def test_auto_ml_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.AutoMlGrpcTransport, transports.AutoMlGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_auto_ml_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.AutoMlGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.AutoMlGrpcTransport, transports.AutoMlGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_auto_ml_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AutoMlGrpcTransport, grpc_helpers), + (transports.AutoMlGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_auto_ml_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="automl.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AutoMlGrpcTransport, grpc_helpers), + (transports.AutoMlGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_auto_ml_transport_create_channel_old_api_core(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AutoMlGrpcTransport, grpc_helpers), + (transports.AutoMlGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_auto_ml_transport_create_channel_user_scopes(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [transports.AutoMlGrpcTransport, transports.AutoMlGrpcAsyncIOTransport], ) def test_auto_ml_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6862,7 +6736,7 @@ def test_auto_ml_grpc_transport_client_cert_source_for_mtls(transport_class): def test_auto_ml_host_no_port(): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com" ), @@ -6872,7 +6746,7 @@ def test_auto_ml_host_no_port(): def test_auto_ml_host_with_port(): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com:8000" ), @@ -6923,9 +6797,9 @@ def test_auto_ml_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -6998,7 +6872,7 @@ def test_auto_ml_transport_channel_mtls_with_adc(transport_class): def test_auto_ml_grpc_lro_client(): client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -7011,7 +6885,7 @@ def test_auto_ml_grpc_lro_client(): def test_auto_ml_grpc_lro_async_client(): client = AutoMlAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -7027,7 +6901,6 @@ def test_annotation_spec_path(): location = "clam" dataset = "whelk" annotation_spec = "octopus" - expected = "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}".format( project=project, location=location, @@ -7060,7 +6933,6 @@ def test_column_spec_path(): dataset = "scallop" table_spec = "abalone" column_spec = "squid" - expected = "projects/{project}/locations/{location}/datasets/{dataset}/tableSpecs/{table_spec}/columnSpecs/{column_spec}".format( project=project, location=location, @@ -7093,7 +6965,6 @@ def test_dataset_path(): project = "cuttlefish" location = "mussel" dataset = "winkle" - expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( project=project, location=location, dataset=dataset, ) @@ -7118,7 +6989,6 @@ def test_model_path(): project = "squid" location = "clam" model = "whelk" - expected = "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @@ -7144,7 +7014,6 @@ def test_model_evaluation_path(): location = "mussel" model = "winkle" model_evaluation = "nautilus" - expected = "projects/{project}/locations/{location}/models/{model}/modelEvaluations/{model_evaluation}".format( project=project, location=location, @@ -7176,7 +7045,6 @@ def test_table_spec_path(): location = "octopus" dataset = "oyster" table_spec = "nudibranch" - expected = "projects/{project}/locations/{location}/datasets/{dataset}/tableSpecs/{table_spec}".format( project=project, location=location, dataset=dataset, table_spec=table_spec, ) @@ -7200,7 +7068,6 @@ def test_parse_table_spec_path(): def test_common_billing_account_path(): billing_account = "scallop" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -7221,7 +7088,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "squid" - expected = "folders/{folder}".format(folder=folder,) actual = AutoMlClient.common_folder_path(folder) assert expected == actual @@ -7240,7 +7106,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "whelk" - expected = "organizations/{organization}".format(organization=organization,) actual = AutoMlClient.common_organization_path(organization) assert expected == actual @@ -7259,7 +7124,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "oyster" - expected = "projects/{project}".format(project=project,) actual = AutoMlClient.common_project_path(project) assert expected == actual @@ -7279,7 +7143,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "cuttlefish" location = "mussel" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -7306,7 +7169,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.AutoMlTransport, "_prep_wrapped_messages" ) as prep: client = AutoMlClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7315,6 +7178,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = AutoMlClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/automl_v1beta1/test_prediction_service.py b/tests/unit/gapic/automl_v1beta1/test_prediction_service.py index 633ffac9..29f6823a 100644 --- a/tests/unit/gapic/automl_v1beta1/test_prediction_service.py +++ b/tests/unit/gapic/automl_v1beta1/test_prediction_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,16 +23,16 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.automl_v1beta1.services.prediction_service import ( PredictionServiceAsyncClient, @@ -42,6 +41,12 @@ PredictionServiceClient, ) from google.cloud.automl_v1beta1.services.prediction_service import transports +from google.cloud.automl_v1beta1.services.prediction_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.automl_v1beta1.services.prediction_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.automl_v1beta1.types import annotation_payload from google.cloud.automl_v1beta1.types import data_items from google.cloud.automl_v1beta1.types import geometry @@ -51,7 +56,31 @@ from google.cloud.automl_v1beta1.types import text_segment from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import struct_pb2 as struct # type: ignore +from google.protobuf import struct_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -103,7 +132,7 @@ def test__get_default_mtls_endpoint(): "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] ) def test_prediction_service_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -120,7 +149,7 @@ def test_prediction_service_client_from_service_account_info(client_class): "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] ) def test_prediction_service_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -173,7 +202,7 @@ def test_prediction_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(PredictionServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -471,7 +500,7 @@ def test_predict( transport: str = "grpc", request_type=prediction_service.PredictRequest ): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -482,17 +511,14 @@ def test_predict( with mock.patch.object(type(client.transport.predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = prediction_service.PredictResponse() - response = client.predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.PredictRequest() # Establish that the response is the type that we expect. - assert isinstance(response, prediction_service.PredictResponse) @@ -504,7 +530,7 @@ def test_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -512,7 +538,6 @@ def test_predict_empty_call(): client.predict() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.PredictRequest() @@ -521,7 +546,7 @@ async def test_predict_async( transport: str = "grpc_asyncio", request_type=prediction_service.PredictRequest ): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -534,13 +559,11 @@ async def test_predict_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( prediction_service.PredictResponse() ) - response = await client.predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.PredictRequest() # Establish that the response is the type that we expect. @@ -553,17 +576,17 @@ async def test_predict_async_from_dict(): def test_predict_field_headers(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: call.return_value = prediction_service.PredictResponse() - client.predict(request) # Establish that the underlying gRPC stub method was called. @@ -579,12 +602,13 @@ def test_predict_field_headers(): @pytest.mark.asyncio async def test_predict_field_headers_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -592,7 +616,6 @@ async def test_predict_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( prediction_service.PredictResponse() ) - await client.predict(request) # Establish that the underlying gRPC stub method was called. @@ -606,13 +629,12 @@ async def test_predict_field_headers_async(): def test_predict_flattened(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = prediction_service.PredictResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.predict( @@ -627,18 +649,15 @@ def test_predict_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].payload == data_items.ExamplePayload( image=data_items.Image(image_bytes=b"image_bytes_blob") ) - assert args[0].params == {"key_value": "value_value"} def test_predict_flattened_error(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -656,7 +675,7 @@ def test_predict_flattened_error(): @pytest.mark.asyncio async def test_predict_flattened_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -681,20 +700,17 @@ async def test_predict_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].payload == data_items.ExamplePayload( image=data_items.Image(image_bytes=b"image_bytes_blob") ) - assert args[0].params == {"key_value": "value_value"} @pytest.mark.asyncio async def test_predict_flattened_error_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -714,7 +730,7 @@ def test_batch_predict( transport: str = "grpc", request_type=prediction_service.BatchPredictRequest ): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -725,13 +741,11 @@ def test_batch_predict( with mock.patch.object(type(client.transport.batch_predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.batch_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.BatchPredictRequest() # Establish that the response is the type that we expect. @@ -746,7 +760,7 @@ def test_batch_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -754,7 +768,6 @@ def test_batch_predict_empty_call(): client.batch_predict() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.BatchPredictRequest() @@ -763,7 +776,7 @@ async def test_batch_predict_async( transport: str = "grpc_asyncio", request_type=prediction_service.BatchPredictRequest ): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -776,13 +789,11 @@ async def test_batch_predict_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.batch_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.BatchPredictRequest() # Establish that the response is the type that we expect. @@ -795,17 +806,17 @@ async def test_batch_predict_async_from_dict(): def test_batch_predict_field_headers(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.BatchPredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.batch_predict), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.batch_predict(request) # Establish that the underlying gRPC stub method was called. @@ -821,12 +832,13 @@ def test_batch_predict_field_headers(): @pytest.mark.asyncio async def test_batch_predict_field_headers_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.BatchPredictRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -834,7 +846,6 @@ async def test_batch_predict_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.batch_predict(request) # Establish that the underlying gRPC stub method was called. @@ -848,13 +859,12 @@ async def test_batch_predict_field_headers_async(): def test_batch_predict_flattened(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.batch_predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.batch_predict( @@ -874,24 +884,20 @@ def test_batch_predict_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.BatchPredictInputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) - assert args[0].output_config == io.BatchPredictOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) - assert args[0].params == {"key_value": "value_value"} def test_batch_predict_flattened_error(): - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -914,7 +920,7 @@ def test_batch_predict_flattened_error(): @pytest.mark.asyncio async def test_batch_predict_flattened_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -944,26 +950,22 @@ async def test_batch_predict_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == io.BatchPredictInputConfig( gcs_source=io.GcsSource(input_uris=["input_uris_value"]) ) - assert args[0].output_config == io.BatchPredictOutputConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) - assert args[0].params == {"key_value": "value_value"} @pytest.mark.asyncio async def test_batch_predict_flattened_error_async(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -987,16 +989,16 @@ async def test_batch_predict_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( @@ -1006,7 +1008,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( @@ -1017,7 +1019,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = PredictionServiceClient(transport=transport) assert client.transport is transport @@ -1026,13 +1028,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.PredictionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.PredictionServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1047,23 +1049,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = PredictionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.PredictionServiceGrpcTransport,) def test_prediction_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.PredictionServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1075,7 +1077,7 @@ def test_prediction_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.PredictionServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1094,15 +1096,37 @@ def test_prediction_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.PredictionServiceTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_prediction_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1115,19 +1139,33 @@ def test_prediction_service_base_transport_with_credentials_file(): def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_prediction_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + PredictionServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_prediction_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) PredictionServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -1135,20 +1173,156 @@ def test_prediction_service_auth_adc(): ) -def test_prediction_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_prediction_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.PredictionServiceGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_prediction_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="automl.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_prediction_service_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_prediction_service_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "automl.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -1157,7 +1331,7 @@ def test_prediction_service_transport_auth_adc(): ], ) def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1196,7 +1370,7 @@ def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport def test_prediction_service_host_no_port(): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com" ), @@ -1206,7 +1380,7 @@ def test_prediction_service_host_no_port(): def test_prediction_service_host_with_port(): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="automl.googleapis.com:8000" ), @@ -1262,9 +1436,9 @@ def test_prediction_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -1340,7 +1514,7 @@ def test_prediction_service_transport_channel_mtls_with_adc(transport_class): def test_prediction_service_grpc_lro_client(): client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -1353,7 +1527,7 @@ def test_prediction_service_grpc_lro_client(): def test_prediction_service_grpc_lro_async_client(): client = PredictionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -1368,7 +1542,6 @@ def test_model_path(): project = "squid" location = "clam" model = "whelk" - expected = "projects/{project}/locations/{location}/models/{model}".format( project=project, location=location, model=model, ) @@ -1391,7 +1564,6 @@ def test_parse_model_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1412,7 +1584,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = PredictionServiceClient.common_folder_path(folder) assert expected == actual @@ -1431,7 +1602,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = PredictionServiceClient.common_organization_path(organization) assert expected == actual @@ -1450,7 +1620,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = PredictionServiceClient.common_project_path(project) assert expected == actual @@ -1470,7 +1639,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1497,7 +1665,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.PredictionServiceTransport, "_prep_wrapped_messages" ) as prep: client = PredictionServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1506,6 +1674,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = PredictionServiceClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)