From 50b3ad907533fa20002de0743620261f9d8a0b7a Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Thu, 3 Sep 2020 06:13:02 -0700 Subject: [PATCH 1/3] changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. --- .../data_labeling_service/async_client.py | 130 ++++++------ .../services/data_labeling_service/client.py | 13 +- .../data_labeling_service/transports/base.py | 126 +++++------ .../data_labeling_service/transports/grpc.py | 16 +- .../transports/grpc_asyncio.py | 10 +- samples/snippets/noxfile.py | 26 +-- synth.metadata | 116 ++++++++++- .../test_data_labeling_service.py | 197 ++++++++++-------- 8 files changed, 407 insertions(+), 227 deletions(-) diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py index 5a5c908..9baa824 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py @@ -50,7 +50,7 @@ from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from .transports.base import DataLabelingServiceTransport +from .transports.base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import DataLabelingServiceGrpcAsyncIOTransport from .client import DataLabelingServiceClient @@ -63,16 +63,16 @@ class DataLabelingServiceAsyncClient: DEFAULT_ENDPOINT = DataLabelingServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DataLabelingServiceClient.DEFAULT_MTLS_ENDPOINT + dataset_path = staticmethod(DataLabelingServiceClient.dataset_path) + instruction_path = staticmethod(DataLabelingServiceClient.instruction_path) + evaluation_job_path = staticmethod(DataLabelingServiceClient.evaluation_job_path) + annotation_spec_set_path = staticmethod( DataLabelingServiceClient.annotation_spec_set_path ) - evaluation_job_path = staticmethod(DataLabelingServiceClient.evaluation_job_path) - - dataset_path = staticmethod(DataLabelingServiceClient.dataset_path) - from_service_account_file = DataLabelingServiceClient.from_service_account_file from_service_account_json = from_service_account_file @@ -87,6 +87,7 @@ def __init__( credentials: credentials.Credentials = None, transport: Union[str, DataLabelingServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the data labeling service client. @@ -119,7 +120,10 @@ def __init__( """ self._client = DataLabelingServiceClient( - credentials=credentials, transport=transport, client_options=client_options, + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, ) async def create_dataset( @@ -188,7 +192,7 @@ async def create_dataset( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_dataset, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -264,11 +268,11 @@ async def get_dataset( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -355,11 +359,11 @@ async def list_datasets( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -433,11 +437,11 @@ async def delete_dataset( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -523,7 +527,7 @@ async def import_data( rpc = gapic_v1.method_async.wrap_method( self._client._transport.import_data, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -640,11 +644,11 @@ async def export_data( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -727,11 +731,11 @@ async def get_data_item( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -819,11 +823,11 @@ async def list_data_items( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -908,11 +912,11 @@ async def get_annotated_dataset( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1001,11 +1005,11 @@ async def list_annotated_datasets( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1056,7 +1060,7 @@ async def delete_annotated_dataset( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_annotated_dataset, default_timeout=None, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1150,7 +1154,7 @@ async def label_image( rpc = gapic_v1.method_async.wrap_method( self._client._transport.label_image, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1252,7 +1256,7 @@ async def label_video( rpc = gapic_v1.method_async.wrap_method( self._client._transport.label_video, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1354,7 +1358,7 @@ async def label_text( rpc = gapic_v1.method_async.wrap_method( self._client._transport.label_text, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1449,11 +1453,11 @@ async def get_example( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1541,11 +1545,11 @@ async def list_examples( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1637,7 +1641,7 @@ async def create_annotation_spec_set( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_annotation_spec_set, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1716,11 +1720,11 @@ async def get_annotation_spec_set( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1808,11 +1812,11 @@ async def list_annotation_spec_sets( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1887,11 +1891,11 @@ async def delete_annotation_spec_set( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1975,7 +1979,7 @@ async def create_instruction( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_instruction, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2059,11 +2063,11 @@ async def get_instruction( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2151,11 +2155,11 @@ async def list_instructions( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2230,11 +2234,11 @@ async def delete_instruction( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2312,11 +2316,11 @@ async def get_evaluation( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2435,11 +2439,11 @@ async def search_evaluations( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2525,7 +2529,7 @@ async def search_example_comparisons( rpc = gapic_v1.method_async.wrap_method( self._client._transport.search_example_comparisons, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2615,7 +2619,7 @@ async def create_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2713,7 +2717,7 @@ async def update_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2795,11 +2799,11 @@ async def get_evaluation_job( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2867,7 +2871,7 @@ async def pause_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.pause_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2934,7 +2938,7 @@ async def resume_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.resume_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3003,11 +3007,11 @@ async def delete_evaluation_job( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3101,11 +3105,11 @@ async def list_evaluation_jobs( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3128,13 +3132,13 @@ async def list_evaluation_jobs( try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( "google-cloud-datalabeling", ).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() __all__ = ("DataLabelingServiceAsyncClient",) diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py index 9359be5..6b5def2 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py @@ -52,7 +52,7 @@ from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from .transports.base import DataLabelingServiceTransport +from .transports.base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import DataLabelingServiceGrpcTransport from .transports.grpc_asyncio import DataLabelingServiceGrpcAsyncIOTransport @@ -214,6 +214,7 @@ def __init__( credentials: credentials.Credentials = None, transport: Union[str, DataLabelingServiceTransport] = None, client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the data labeling service client. @@ -239,6 +240,11 @@ def __init__( (2) The ``client_cert_source`` property is used to provide client SSL credentials for mutual TLS transport. If not provided, the default SSL credentials will be used if present. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -296,6 +302,7 @@ def __init__( api_mtls_endpoint=client_options.api_endpoint, client_cert_source=client_options.client_cert_source, quota_project_id=client_options.quota_project_id, + client_info=client_info, ) def create_dataset( @@ -3215,13 +3222,13 @@ def list_evaluation_jobs( try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( "google-cloud-datalabeling", ).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() __all__ = ("DataLabelingServiceClient",) diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py index e38ee72..9f723ed 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py @@ -19,7 +19,7 @@ import typing import pkg_resources -from google import auth +from google import auth # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -42,13 +42,13 @@ try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( "google-cloud-datalabeling", ).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() class DataLabelingServiceTransport(abc.ABC): @@ -64,6 +64,7 @@ def __init__( credentials_file: typing.Optional[str] = None, scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, quota_project_id: typing.Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. @@ -81,6 +82,11 @@ def __init__( scope (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): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -108,13 +114,13 @@ def __init__( self._credentials = credentials # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages() + self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self): + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_dataset: gapic_v1.method.wrap_method( - self.create_dataset, default_timeout=30.0, client_info=_client_info, + self.create_dataset, default_timeout=30.0, client_info=client_info, ), self.get_dataset: gapic_v1.method.wrap_method( self.get_dataset, @@ -123,11 +129,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_datasets: gapic_v1.method.wrap_method( self.list_datasets, @@ -136,11 +142,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_dataset: gapic_v1.method.wrap_method( self.delete_dataset, @@ -149,14 +155,14 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.import_data: gapic_v1.method.wrap_method( - self.import_data, default_timeout=30.0, client_info=_client_info, + self.import_data, default_timeout=30.0, client_info=client_info, ), self.export_data: gapic_v1.method.wrap_method( self.export_data, @@ -165,11 +171,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_data_item: gapic_v1.method.wrap_method( self.get_data_item, @@ -178,11 +184,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_data_items: gapic_v1.method.wrap_method( self.list_data_items, @@ -191,11 +197,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_annotated_dataset: gapic_v1.method.wrap_method( self.get_annotated_dataset, @@ -204,11 +210,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_annotated_datasets: gapic_v1.method.wrap_method( self.list_annotated_datasets, @@ -217,25 +223,25 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_annotated_dataset: gapic_v1.method.wrap_method( self.delete_annotated_dataset, default_timeout=None, - client_info=_client_info, + client_info=client_info, ), self.label_image: gapic_v1.method.wrap_method( - self.label_image, default_timeout=30.0, client_info=_client_info, + self.label_image, default_timeout=30.0, client_info=client_info, ), self.label_video: gapic_v1.method.wrap_method( - self.label_video, default_timeout=30.0, client_info=_client_info, + self.label_video, default_timeout=30.0, client_info=client_info, ), self.label_text: gapic_v1.method.wrap_method( - self.label_text, default_timeout=30.0, client_info=_client_info, + self.label_text, default_timeout=30.0, client_info=client_info, ), self.get_example: gapic_v1.method.wrap_method( self.get_example, @@ -244,11 +250,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_examples: gapic_v1.method.wrap_method( self.list_examples, @@ -257,16 +263,16 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.create_annotation_spec_set: gapic_v1.method.wrap_method( self.create_annotation_spec_set, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_annotation_spec_set: gapic_v1.method.wrap_method( self.get_annotation_spec_set, @@ -275,11 +281,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_annotation_spec_sets: gapic_v1.method.wrap_method( self.list_annotation_spec_sets, @@ -288,11 +294,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_annotation_spec_set: gapic_v1.method.wrap_method( self.delete_annotation_spec_set, @@ -301,14 +307,14 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.create_instruction: gapic_v1.method.wrap_method( - self.create_instruction, default_timeout=30.0, client_info=_client_info, + self.create_instruction, default_timeout=30.0, client_info=client_info, ), self.get_instruction: gapic_v1.method.wrap_method( self.get_instruction, @@ -317,11 +323,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_instructions: gapic_v1.method.wrap_method( self.list_instructions, @@ -330,11 +336,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_instruction: gapic_v1.method.wrap_method( self.delete_instruction, @@ -343,11 +349,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_evaluation: gapic_v1.method.wrap_method( self.get_evaluation, @@ -356,11 +362,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.search_evaluations: gapic_v1.method.wrap_method( self.search_evaluations, @@ -369,26 +375,26 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.search_example_comparisons: gapic_v1.method.wrap_method( self.search_example_comparisons, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.create_evaluation_job: gapic_v1.method.wrap_method( self.create_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.update_evaluation_job: gapic_v1.method.wrap_method( self.update_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_evaluation_job: gapic_v1.method.wrap_method( self.get_evaluation_job, @@ -397,21 +403,21 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.pause_evaluation_job: gapic_v1.method.wrap_method( self.pause_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.resume_evaluation_job: gapic_v1.method.wrap_method( self.resume_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_evaluation_job: gapic_v1.method.wrap_method( self.delete_evaluation_job, @@ -420,11 +426,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_evaluation_jobs: gapic_v1.method.wrap_method( self.list_evaluation_jobs, @@ -433,11 +439,11 @@ def _prep_wrapped_messages(self): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), } diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py index 8ab57b5..430e2db 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py @@ -19,6 +19,7 @@ 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 from google.auth.transport.grpc import SslCredentials # type: ignore @@ -40,7 +41,7 @@ from google.longrunning import operations_pb2 as operations # type: ignore from google.protobuf import empty_pb2 as empty # type: ignore -from .base import DataLabelingServiceTransport +from .base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO class DataLabelingServiceGrpcTransport(DataLabelingServiceTransport): @@ -66,7 +67,8 @@ def __init__( channel: grpc.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id: Optional[str] = None + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the transport. @@ -95,6 +97,11 @@ def __init__( is None. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -150,6 +157,7 @@ def __init__( credentials_file=credentials_file, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + client_info=client_info, ) @classmethod @@ -160,7 +168,7 @@ def create_channel( credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, - **kwargs + **kwargs, ) -> grpc.Channel: """Create and return a gRPC channel object. Args: @@ -194,7 +202,7 @@ def create_channel( credentials_file=credentials_file, scopes=scopes, quota_project_id=quota_project_id, - **kwargs + **kwargs, ) @property diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py index 79fd1cf..a139d8f 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py @@ -17,6 +17,7 @@ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +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.auth import credentials # type: ignore @@ -39,7 +40,7 @@ from google.longrunning import operations_pb2 as operations # type: ignore from google.protobuf import empty_pb2 as empty # type: ignore -from .base import DataLabelingServiceTransport +from .base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO from .grpc import DataLabelingServiceGrpcTransport @@ -109,6 +110,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the transport. @@ -138,6 +140,11 @@ def __init__( is None. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -186,6 +193,7 @@ def __init__( credentials_file=credentials_file, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + client_info=client_info, ) self._stubs = {} diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 5660f08..ba55d7c 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -37,22 +37,24 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], + 'ignored_versions': ["2.7"], + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - "envs": {}, + 'envs': {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") + sys.path.append('.') from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -67,12 +69,12 @@ def get_pytest_env_vars(): ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] + env_key = TEST_CONFIG['gcloud_project_env'] # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) + ret.update(TEST_CONFIG['envs']) return ret @@ -81,7 +83,7 @@ def get_pytest_env_vars(): ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) @@ -136,7 +138,7 @@ def lint(session): args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - ".", + "." ] session.run("flake8", *args) @@ -180,9 +182,9 @@ def py(session): if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) # diff --git a/synth.metadata b/synth.metadata index 746af20..dc5d523 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-datalabeling.git", - "sha": "448682cf313c58ff9c61303d13d72a04b3dc34af" + "sha": "7a75eee979484506bb3cc3b6b3e2e51c09a4a94d" + } + }, + { + "git": { + "name": "googleapis", + "remote": "https://github.com/googleapis/googleapis.git", + "sha": "ddaa2026caf2eb00444a14b08500553824a7182a", + "internalRef": "329845759" } }, { @@ -32,5 +40,111 @@ "generator": "bazel" } } + ], + "generatedFiles": [ + ".flake8", + ".github/CONTRIBUTING.md", + ".github/ISSUE_TEMPLATE/bug_report.md", + ".github/ISSUE_TEMPLATE/feature_request.md", + ".github/ISSUE_TEMPLATE/support_request.md", + ".github/PULL_REQUEST_TEMPLATE.md", + ".github/release-please.yml", + ".gitignore", + ".kokoro/build.sh", + ".kokoro/continuous/common.cfg", + ".kokoro/continuous/continuous.cfg", + ".kokoro/docker/docs/Dockerfile", + ".kokoro/docker/docs/fetch_gpg_keys.sh", + ".kokoro/docs/common.cfg", + ".kokoro/docs/docs-presubmit.cfg", + ".kokoro/docs/docs.cfg", + ".kokoro/presubmit/common.cfg", + ".kokoro/presubmit/presubmit.cfg", + ".kokoro/publish-docs.sh", + ".kokoro/release.sh", + ".kokoro/release/common.cfg", + ".kokoro/release/release.cfg", + ".kokoro/samples/lint/common.cfg", + ".kokoro/samples/lint/continuous.cfg", + ".kokoro/samples/lint/periodic.cfg", + ".kokoro/samples/lint/presubmit.cfg", + ".kokoro/samples/python3.6/common.cfg", + ".kokoro/samples/python3.6/continuous.cfg", + ".kokoro/samples/python3.6/periodic.cfg", + ".kokoro/samples/python3.6/presubmit.cfg", + ".kokoro/samples/python3.7/common.cfg", + ".kokoro/samples/python3.7/continuous.cfg", + ".kokoro/samples/python3.7/periodic.cfg", + ".kokoro/samples/python3.7/presubmit.cfg", + ".kokoro/samples/python3.8/common.cfg", + ".kokoro/samples/python3.8/continuous.cfg", + ".kokoro/samples/python3.8/periodic.cfg", + ".kokoro/samples/python3.8/presubmit.cfg", + ".kokoro/test-samples.sh", + ".kokoro/trampoline.sh", + ".kokoro/trampoline_v2.sh", + ".trampolinerc", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.rst", + "LICENSE", + "MANIFEST.in", + "docs/_static/custom.css", + "docs/_templates/layout.html", + "docs/conf.py", + "docs/datalabeling_v1beta1/services.rst", + "docs/datalabeling_v1beta1/types.rst", + "docs/multiprocessing.rst", + "google/cloud/datalabeling/__init__.py", + "google/cloud/datalabeling/py.typed", + "google/cloud/datalabeling_v1beta1/__init__.py", + "google/cloud/datalabeling_v1beta1/proto/annotation.proto", + "google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto", + "google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto", + "google/cloud/datalabeling_v1beta1/proto/data_payloads.proto", + "google/cloud/datalabeling_v1beta1/proto/dataset.proto", + "google/cloud/datalabeling_v1beta1/proto/evaluation.proto", + "google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto", + "google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto", + "google/cloud/datalabeling_v1beta1/proto/instruction.proto", + "google/cloud/datalabeling_v1beta1/proto/operations.proto", + "google/cloud/datalabeling_v1beta1/py.typed", + "google/cloud/datalabeling_v1beta1/services/__init__.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/__init__.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/pagers.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/__init__.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py", + "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py", + "google/cloud/datalabeling_v1beta1/types/__init__.py", + "google/cloud/datalabeling_v1beta1/types/annotation.py", + "google/cloud/datalabeling_v1beta1/types/annotation_spec_set.py", + "google/cloud/datalabeling_v1beta1/types/data_labeling_service.py", + "google/cloud/datalabeling_v1beta1/types/data_payloads.py", + "google/cloud/datalabeling_v1beta1/types/dataset.py", + "google/cloud/datalabeling_v1beta1/types/evaluation.py", + "google/cloud/datalabeling_v1beta1/types/evaluation_job.py", + "google/cloud/datalabeling_v1beta1/types/human_annotation_config.py", + "google/cloud/datalabeling_v1beta1/types/instruction.py", + "google/cloud/datalabeling_v1beta1/types/operations.py", + "mypy.ini", + "noxfile.py", + "renovate.json", + "samples/AUTHORING_GUIDE.md", + "samples/CONTRIBUTING.md", + "samples/snippets/noxfile.py", + "scripts/decrypt-secrets.sh", + "scripts/fixup_datalabeling_v1beta1_keywords.py", + "scripts/readme-gen/readme_gen.py", + "scripts/readme-gen/templates/README.tmpl.rst", + "scripts/readme-gen/templates/auth.tmpl.rst", + "scripts/readme-gen/templates/auth_api_key.tmpl.rst", + "scripts/readme-gen/templates/install_deps.tmpl.rst", + "scripts/readme-gen/templates/install_portaudio.tmpl.rst", + "setup.cfg", + "testing/.gitignore", + "tests/unit/gapic/datalabeling_v1beta1/__init__.py", + "tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py" ] } \ No newline at end of file diff --git a/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py b/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py index 7d9aada..da451de 100644 --- a/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py +++ b/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py @@ -191,6 +191,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint="squid.clam.whelk", client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is @@ -207,6 +208,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint=client.DEFAULT_ENDPOINT, client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is @@ -223,6 +225,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is @@ -242,6 +245,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, client_cert_source=client_cert_source_callback, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is @@ -262,6 +266,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is @@ -282,6 +287,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint=client.DEFAULT_ENDPOINT, client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS has @@ -303,6 +309,7 @@ def test_data_labeling_service_client_client_options( api_mtls_endpoint=client.DEFAULT_ENDPOINT, client_cert_source=None, quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -337,6 +344,7 @@ def test_data_labeling_service_client_client_options_scopes( api_mtls_endpoint=client.DEFAULT_ENDPOINT, client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -371,6 +379,7 @@ def test_data_labeling_service_client_client_options_credentials_file( api_mtls_endpoint=client.DEFAULT_ENDPOINT, client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -390,6 +399,7 @@ def test_data_labeling_service_client_client_options_from_dict(): api_mtls_endpoint="squid.clam.whelk", client_cert_source=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -1113,8 +1123,8 @@ def test_list_datasets_pages(): RuntimeError, ) pages = list(client.list_datasets(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -1186,10 +1196,10 @@ async def test_list_datasets_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_datasets(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_datasets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_dataset( @@ -2299,8 +2309,8 @@ def test_list_data_items_pages(): RuntimeError, ) pages = list(client.list_data_items(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -2380,10 +2390,10 @@ async def test_list_data_items_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_data_items(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_data_items(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_get_annotated_dataset( @@ -2935,8 +2945,8 @@ def test_list_annotated_datasets_pages(): RuntimeError, ) pages = list(client.list_annotated_datasets(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -3022,10 +3032,10 @@ async def test_list_annotated_datasets_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_annotated_datasets(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_annotated_datasets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_annotated_dataset( @@ -4314,8 +4324,8 @@ def test_list_examples_pages(): RuntimeError, ) pages = list(client.list_examples(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -4387,10 +4397,10 @@ async def test_list_examples_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_examples(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_examples(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_create_annotation_spec_set( @@ -5166,8 +5176,8 @@ def test_list_annotation_spec_sets_pages(): RuntimeError, ) pages = list(client.list_annotation_spec_sets(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -5257,10 +5267,10 @@ async def test_list_annotation_spec_sets_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_annotation_spec_sets(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_annotation_spec_sets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_annotation_spec_set( @@ -6177,8 +6187,8 @@ def test_list_instructions_pages(): RuntimeError, ) pages = list(client.list_instructions(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -6258,10 +6268,10 @@ async def test_list_instructions_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_instructions(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_instructions(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_instruction( @@ -6960,8 +6970,8 @@ def test_search_evaluations_pages(): RuntimeError, ) pages = list(client.search_evaluations(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -7041,10 +7051,10 @@ async def test_search_evaluations_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.search_evaluations(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.search_evaluations(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_search_example_comparisons( @@ -7344,8 +7354,8 @@ def test_search_example_comparisons_pages(): RuntimeError, ) pages = list(client.search_example_comparisons(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -7443,10 +7453,10 @@ async def test_search_example_comparisons_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.search_example_comparisons(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.search_example_comparisons(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_create_evaluation_job( @@ -9083,8 +9093,8 @@ def test_list_evaluation_jobs_pages(): RuntimeError, ) pages = list(client.list_evaluation_jobs(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -9172,10 +9182,10 @@ async def test_list_evaluation_jobs_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_evaluation_jobs(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_evaluation_jobs(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_credentials_transport_error(): @@ -9573,51 +9583,49 @@ def test_data_labeling_service_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_instruction_path(): +def test_dataset_path(): project = "squid" - instruction = "clam" + dataset = "clam" - expected = "projects/{project}/instructions/{instruction}".format( - project=project, instruction=instruction, + expected = "projects/{project}/datasets/{dataset}".format( + project=project, dataset=dataset, ) - actual = DataLabelingServiceClient.instruction_path(project, instruction) + actual = DataLabelingServiceClient.dataset_path(project, dataset) assert expected == actual -def test_parse_instruction_path(): +def test_parse_dataset_path(): expected = { "project": "whelk", - "instruction": "octopus", + "dataset": "octopus", } - path = DataLabelingServiceClient.instruction_path(**expected) + path = DataLabelingServiceClient.dataset_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_instruction_path(path) + actual = DataLabelingServiceClient.parse_dataset_path(path) assert expected == actual -def test_annotation_spec_set_path(): +def test_instruction_path(): project = "squid" - annotation_spec_set = "clam" + instruction = "clam" - expected = "projects/{project}/annotationSpecSets/{annotation_spec_set}".format( - project=project, annotation_spec_set=annotation_spec_set, - ) - actual = DataLabelingServiceClient.annotation_spec_set_path( - project, annotation_spec_set + expected = "projects/{project}/instructions/{instruction}".format( + project=project, instruction=instruction, ) + actual = DataLabelingServiceClient.instruction_path(project, instruction) assert expected == actual -def test_parse_annotation_spec_set_path(): +def test_parse_instruction_path(): expected = { "project": "whelk", - "annotation_spec_set": "octopus", + "instruction": "octopus", } - path = DataLabelingServiceClient.annotation_spec_set_path(**expected) + path = DataLabelingServiceClient.instruction_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_annotation_spec_set_path(path) + actual = DataLabelingServiceClient.parse_instruction_path(path) assert expected == actual @@ -9644,24 +9652,47 @@ def test_parse_evaluation_job_path(): assert expected == actual -def test_dataset_path(): +def test_annotation_spec_set_path(): project = "squid" - dataset = "clam" + annotation_spec_set = "clam" - expected = "projects/{project}/datasets/{dataset}".format( - project=project, dataset=dataset, + expected = "projects/{project}/annotationSpecSets/{annotation_spec_set}".format( + project=project, annotation_spec_set=annotation_spec_set, + ) + actual = DataLabelingServiceClient.annotation_spec_set_path( + project, annotation_spec_set ) - actual = DataLabelingServiceClient.dataset_path(project, dataset) assert expected == actual -def test_parse_dataset_path(): +def test_parse_annotation_spec_set_path(): expected = { "project": "whelk", - "dataset": "octopus", + "annotation_spec_set": "octopus", } - path = DataLabelingServiceClient.dataset_path(**expected) + path = DataLabelingServiceClient.annotation_spec_set_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_dataset_path(path) + actual = DataLabelingServiceClient.parse_annotation_spec_set_path(path) assert expected == actual + + +def test_client_withDEFAULT_CLIENT_INFO(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.DataLabelingServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = DataLabelingServiceClient( + credentials=credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.DataLabelingServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = DataLabelingServiceClient.get_transport_class() + transport = transport_class( + credentials=credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info) From 3dac8e068118b5dea339653b0a731461c236c545 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Thu, 3 Sep 2020 06:14:21 -0700 Subject: [PATCH 2/3] chore(py-library): enable snippet-bot Co-authored-by: Benjamin E. Coe Source-Author: Takashi Matsuo Source-Date: Tue Sep 1 17:14:08 2020 +0000 Source-Repo: googleapis/synthtool Source-Sha: d91dd8aac77f7a9c5506c238038a26fa4f9e361e Source-Link: https://github.com/googleapis/synthtool/commit/d91dd8aac77f7a9c5506c238038a26fa4f9e361e --- .github/snippet-bot.yml | 0 synth.metadata | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .github/snippet-bot.yml diff --git a/.github/snippet-bot.yml b/.github/snippet-bot.yml new file mode 100644 index 0000000..e69de29 diff --git a/synth.metadata b/synth.metadata index dc5d523..baea70f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -19,14 +19,14 @@ "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "bd0deaa1113b588d70449535ab9cbf0f2bd0e72f" + "sha": "d91dd8aac77f7a9c5506c238038a26fa4f9e361e" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "bd0deaa1113b588d70449535ab9cbf0f2bd0e72f" + "sha": "d91dd8aac77f7a9c5506c238038a26fa4f9e361e" } } ], @@ -49,6 +49,7 @@ ".github/ISSUE_TEMPLATE/support_request.md", ".github/PULL_REQUEST_TEMPLATE.md", ".github/release-please.yml", + ".github/snippet-bot.yml", ".gitignore", ".kokoro/build.sh", ".kokoro/continuous/common.cfg", From d486dcd14cdb6afe12fddbe11043fefe49b8bd56 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Wed, 18 Nov 2020 00:02:06 +0000 Subject: [PATCH 3/3] chore: manual regen --- .kokoro/docs/common.cfg | 2 +- .kokoro/populate-secrets.sh | 43 + .kokoro/release/common.cfg | 50 +- .kokoro/samples/python3.6/common.cfg | 6 + .kokoro/samples/python3.7/common.cfg | 6 + .kokoro/samples/python3.8/common.cfg | 6 + .kokoro/test-samples.sh | 8 +- .kokoro/trampoline.sh | 15 +- CODE_OF_CONDUCT.md | 123 +- CONTRIBUTING.rst | 19 - docs/conf.py | 4 +- docs/datalabeling_v1beta1/types.rst | 1 + .../proto/annotation.proto | 3 + .../proto/annotation_spec_set.proto | 3 + .../proto/data_labeling_service.proto | 4 + .../proto/data_payloads.proto | 3 + .../datalabeling_v1beta1/proto/dataset.proto | 3 + .../proto/evaluation.proto | 3 + .../proto/evaluation_job.proto | 3 + .../proto/human_annotation_config.proto | 3 + .../proto/instruction.proto | 3 + .../proto/operations.proto | 3 + .../data_labeling_service/async_client.py | 235 ++- .../services/data_labeling_service/client.py | 241 ++- .../data_labeling_service/transports/base.py | 42 +- .../data_labeling_service/transports/grpc.py | 66 +- .../transports/grpc_asyncio.py | 57 +- .../datalabeling_v1beta1/types/annotation.py | 28 +- .../types/data_payloads.py | 2 +- noxfile.py | 10 +- samples/snippets/noxfile.py | 24 +- scripts/decrypt-secrets.sh | 15 +- .../fixup_datalabeling_v1beta1_keywords.py | 1 + synth.metadata | 119 +- .../test_data_labeling_service.py | 1863 ++++++++++------- 35 files changed, 1907 insertions(+), 1110 deletions(-) create mode 100755 .kokoro/populate-secrets.sh diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 3e05863..5875bf6 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -30,7 +30,7 @@ env_vars: { env_vars: { key: "V2_STAGING_BUCKET" - value: "docs-staging-v2-staging" + value: "docs-staging-v2" } # It will upload the docker image after successful builds. diff --git a/.kokoro/populate-secrets.sh b/.kokoro/populate-secrets.sh new file mode 100755 index 0000000..f525142 --- /dev/null +++ b/.kokoro/populate-secrets.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# 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. + +set -eo pipefail + +function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;} +function msg { println "$*" >&2 ;} +function println { printf '%s\n' "$(now) $*" ;} + + +# Populates requested secrets set in SECRET_MANAGER_KEYS from service account: +# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com +SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager" +msg "Creating folder on disk for secrets: ${SECRET_LOCATION}" +mkdir -p ${SECRET_LOCATION} +for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g") +do + msg "Retrieving secret ${key}" + docker run --entrypoint=gcloud \ + --volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \ + gcr.io/google.com/cloudsdktool/cloud-sdk \ + secrets versions access latest \ + --project cloud-devrel-kokoro-resources \ + --secret ${key} > \ + "${SECRET_LOCATION}/${key}" + if [[ $? == 0 ]]; then + msg "Secret written to ${SECRET_LOCATION}/${key}" + else + msg "Error retrieving secret ${key}" + fi +done diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 345151d..29d2d2b 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,42 +23,18 @@ env_vars: { value: "github/python-datalabeling/.kokoro/release.sh" } -# Fetch the token needed for reporting release status to GitHub -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "yoshi-automation-github-key" - } - } -} - -# Fetch PyPI password -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "google_cloud_pypi_password" - } - } -} - -# Fetch magictoken to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "releasetool-magictoken" - } - } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google_cloud_pypi_password" + } + } } -# Fetch api key to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "magic-github-proxy-api-key" - } - } -} +# Tokens needed to report release status back to GitHub +env_vars: { + key: "SECRET_MANAGER_KEYS" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" +} \ No newline at end of file diff --git a/.kokoro/samples/python3.6/common.cfg b/.kokoro/samples/python3.6/common.cfg index 88adae0..995c300 100644 --- a/.kokoro/samples/python3.6/common.cfg +++ b/.kokoro/samples/python3.6/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.6" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py36" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-datalabeling/.kokoro/test-samples.sh" diff --git a/.kokoro/samples/python3.7/common.cfg b/.kokoro/samples/python3.7/common.cfg index f25c414..f0c4a67 100644 --- a/.kokoro/samples/python3.7/common.cfg +++ b/.kokoro/samples/python3.7/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.7" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py37" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-datalabeling/.kokoro/test-samples.sh" diff --git a/.kokoro/samples/python3.8/common.cfg b/.kokoro/samples/python3.8/common.cfg index e0572fe..4391154 100644 --- a/.kokoro/samples/python3.8/common.cfg +++ b/.kokoro/samples/python3.8/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.8" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py38" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-datalabeling/.kokoro/test-samples.sh" diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh index 973deb9..e39bc8c 100755 --- a/.kokoro/test-samples.sh +++ b/.kokoro/test-samples.sh @@ -28,6 +28,12 @@ if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then git checkout $LATEST_RELEASE fi +# Exit early if samples directory doesn't exist +if [ ! -d "./samples" ]; then + echo "No tests run. `./samples` not found" + exit 0 +fi + # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -101,4 +107,4 @@ cd "$ROOT" # Workaround for Kokoro permissions issue: delete secrets rm testing/{test-env.sh,client-secrets.json,service-account.json} -exit "$RTN" \ No newline at end of file +exit "$RTN" diff --git a/.kokoro/trampoline.sh b/.kokoro/trampoline.sh index e8c4251..f39236e 100755 --- a/.kokoro/trampoline.sh +++ b/.kokoro/trampoline.sh @@ -15,9 +15,14 @@ set -eo pipefail -python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" || ret_code=$? +# Always run the cleanup script, regardless of the success of bouncing into +# the container. +function cleanup() { + chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + echo "cleanup"; +} +trap cleanup EXIT -chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh -${KOKORO_GFILE_DIR}/trampoline_cleanup.sh || true - -exit ${ret_code} +$(dirname $0)/populate-secrets.sh # Secret Manager secrets. +python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b3d1f60..039f436 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,44 +1,95 @@ -# Contributor Code of Conduct +# Code of Conduct -As contributors and maintainers of this project, -and in the interest of fostering an open and welcoming community, -we pledge to respect all people who contribute through reporting issues, -posting feature requests, updating documentation, -submitting pull requests or patches, and other activities. +## Our Pledge -We are committed to making participation in this project -a harassment-free experience for everyone, -regardless of level of experience, gender, gender identity and expression, -sexual orientation, disability, personal appearance, -body size, race, ethnicity, age, religion, or nationality. +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery -* Personal attacks -* Trolling or insulting/derogatory comments -* Public or private harassment -* Publishing other's private information, -such as physical or electronic -addresses, without explicit permission -* Other unethical or unprofessional conduct. +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct. -By adopting this Code of Conduct, -project maintainers commit themselves to fairly and consistently -applying these principles to every aspect of managing this project. -Project maintainers who do not follow or enforce the Code of Conduct -may be permanently removed from the project team. - -This code of conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior -may be reported by opening an issue -or contacting one or more of the project maintainers. - -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, -available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index eb1602f..58d838e 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -80,25 +80,6 @@ We use `nox `__ to instrument our tests. .. nox: https://pypi.org/project/nox/ -Note on Editable Installs / Develop Mode -======================================== - -- As mentioned previously, using ``setuptools`` in `develop mode`_ - or a ``pip`` `editable install`_ is not possible with this - library. This is because this library uses `namespace packages`_. - For context see `Issue #2316`_ and the relevant `PyPA issue`_. - - Since ``editable`` / ``develop`` mode can't be used, packages - need to be installed directly. Hence your changes to the source - tree don't get incorporated into the **already installed** - package. - -.. _namespace packages: https://www.python.org/dev/peps/pep-0420/ -.. _Issue #2316: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2316 -.. _PyPA issue: https://github.com/pypa/packaging-problems/issues/12 -.. _develop mode: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode -.. _editable install: https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs - ***************************************** I'm getting weird errors... Can you help? ***************************************** diff --git a/docs/conf.py b/docs/conf.py index 7f93593..2a50b27 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" +needs_sphinx = "1.5.5" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -39,6 +39,7 @@ "sphinx.ext.autosummary", "sphinx.ext.intersphinx", "sphinx.ext.coverage", + "sphinx.ext.doctest", "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", @@ -348,6 +349,7 @@ "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), "grpc": ("https://grpc.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), } diff --git a/docs/datalabeling_v1beta1/types.rst b/docs/datalabeling_v1beta1/types.rst index 634c148..2722f06 100644 --- a/docs/datalabeling_v1beta1/types.rst +++ b/docs/datalabeling_v1beta1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Datalabeling v1beta1 API .. automodule:: google.cloud.datalabeling_v1beta1.types :members: + :show-inheritance: diff --git a/google/cloud/datalabeling_v1beta1/proto/annotation.proto b/google/cloud/datalabeling_v1beta1/proto/annotation.proto index 4750fdc..7d629b2 100644 --- a/google/cloud/datalabeling_v1beta1/proto/annotation.proto +++ b/google/cloud/datalabeling_v1beta1/proto/annotation.proto @@ -22,9 +22,12 @@ import "google/api/resource.proto"; import "google/cloud/datalabeling/v1beta1/annotation_spec_set.proto"; import "google/protobuf/duration.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Specifies where the annotation comes from (whether it was provided by a // human labeler or a different source). diff --git a/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto b/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto index 71bc12a..eb9b04b 100644 --- a/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto +++ b/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto @@ -20,9 +20,12 @@ package google.cloud.datalabeling.v1beta1; import "google/api/annotations.proto"; import "google/api/resource.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // An AnnotationSpecSet is a collection of label definitions. For example, in // image classification tasks, you define a set of possible labels for images as diff --git a/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto b/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto index 7616bc2..5d0746c 100644 --- a/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto +++ b/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto @@ -31,10 +31,14 @@ import "google/longrunning/operations.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/field_mask.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; +// Service for the AI Platform Data Labeling API. service DataLabelingService { option (google.api.default_host) = "datalabeling.googleapis.com"; option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; diff --git a/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto b/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto index 721e200..4aebde4 100644 --- a/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto +++ b/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto @@ -21,9 +21,12 @@ import "google/api/annotations.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Container of information about an image. message ImagePayload { diff --git a/google/cloud/datalabeling_v1beta1/proto/dataset.proto b/google/cloud/datalabeling_v1beta1/proto/dataset.proto index a0bc9a4..cf21b19 100644 --- a/google/cloud/datalabeling_v1beta1/proto/dataset.proto +++ b/google/cloud/datalabeling_v1beta1/proto/dataset.proto @@ -25,9 +25,12 @@ import "google/cloud/datalabeling/v1beta1/data_payloads.proto"; import "google/cloud/datalabeling/v1beta1/human_annotation_config.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; enum DataType { DATA_TYPE_UNSPECIFIED = 0; diff --git a/google/cloud/datalabeling_v1beta1/proto/evaluation.proto b/google/cloud/datalabeling_v1beta1/proto/evaluation.proto index fde0366..18d3719 100644 --- a/google/cloud/datalabeling_v1beta1/proto/evaluation.proto +++ b/google/cloud/datalabeling_v1beta1/proto/evaluation.proto @@ -23,9 +23,12 @@ import "google/cloud/datalabeling/v1beta1/annotation.proto"; import "google/cloud/datalabeling/v1beta1/annotation_spec_set.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Describes an evaluation between a machine learning model's predictions and // ground truth labels. Created when an [EvaluationJob][google.cloud.datalabeling.v1beta1.EvaluationJob] runs successfully. diff --git a/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto b/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto index 49270fe..6f54ad1 100644 --- a/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto +++ b/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto @@ -25,9 +25,12 @@ import "google/cloud/datalabeling/v1beta1/human_annotation_config.proto"; import "google/protobuf/timestamp.proto"; import "google/rpc/status.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Defines an evaluation job that runs periodically to generate // [Evaluations][google.cloud.datalabeling.v1beta1.Evaluation]. [Creating an evaluation diff --git a/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto b/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto index 5658bb9..a05bd30 100644 --- a/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto +++ b/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto @@ -21,9 +21,12 @@ import "google/api/annotations.proto"; import "google/api/field_behavior.proto"; import "google/protobuf/duration.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; enum StringAggregationType { STRING_AGGREGATION_TYPE_UNSPECIFIED = 0; diff --git a/google/cloud/datalabeling_v1beta1/proto/instruction.proto b/google/cloud/datalabeling_v1beta1/proto/instruction.proto index 5083961..15bf695 100644 --- a/google/cloud/datalabeling_v1beta1/proto/instruction.proto +++ b/google/cloud/datalabeling_v1beta1/proto/instruction.proto @@ -22,9 +22,12 @@ import "google/api/resource.proto"; import "google/cloud/datalabeling/v1beta1/dataset.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Instruction of how to perform the labeling task for human operators. // Currently only PDF instruction is supported. diff --git a/google/cloud/datalabeling_v1beta1/proto/operations.proto b/google/cloud/datalabeling_v1beta1/proto/operations.proto index 7f06924..49df6d2 100644 --- a/google/cloud/datalabeling_v1beta1/proto/operations.proto +++ b/google/cloud/datalabeling_v1beta1/proto/operations.proto @@ -24,9 +24,12 @@ import "google/cloud/datalabeling/v1beta1/human_annotation_config.proto"; import "google/protobuf/timestamp.proto"; import "google/rpc/status.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Response used for ImportData longrunning operation. message ImportDataOperationResponse { diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py index 9baa824..569bf03 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py @@ -28,8 +28,8 @@ from google.auth import credentials # type: ignore from google.oauth2 import service_account # type: ignore -from google.api_core import operation -from google.api_core import operation_async +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore from google.cloud.datalabeling_v1beta1.services.data_labeling_service import pagers from google.cloud.datalabeling_v1beta1.types import annotation from google.cloud.datalabeling_v1beta1.types import annotation_spec_set @@ -56,26 +56,85 @@ class DataLabelingServiceAsyncClient: - """""" + """Service for the AI Platform Data Labeling API.""" _client: DataLabelingServiceClient DEFAULT_ENDPOINT = DataLabelingServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DataLabelingServiceClient.DEFAULT_MTLS_ENDPOINT + annotated_dataset_path = staticmethod( + DataLabelingServiceClient.annotated_dataset_path + ) + parse_annotated_dataset_path = staticmethod( + DataLabelingServiceClient.parse_annotated_dataset_path + ) + annotation_spec_set_path = staticmethod( + DataLabelingServiceClient.annotation_spec_set_path + ) + parse_annotation_spec_set_path = staticmethod( + DataLabelingServiceClient.parse_annotation_spec_set_path + ) + data_item_path = staticmethod(DataLabelingServiceClient.data_item_path) + parse_data_item_path = staticmethod(DataLabelingServiceClient.parse_data_item_path) dataset_path = staticmethod(DataLabelingServiceClient.dataset_path) - + parse_dataset_path = staticmethod(DataLabelingServiceClient.parse_dataset_path) + evaluation_path = staticmethod(DataLabelingServiceClient.evaluation_path) + parse_evaluation_path = staticmethod( + DataLabelingServiceClient.parse_evaluation_path + ) + evaluation_job_path = staticmethod(DataLabelingServiceClient.evaluation_job_path) + parse_evaluation_job_path = staticmethod( + DataLabelingServiceClient.parse_evaluation_job_path + ) + example_path = staticmethod(DataLabelingServiceClient.example_path) + parse_example_path = staticmethod(DataLabelingServiceClient.parse_example_path) instruction_path = staticmethod(DataLabelingServiceClient.instruction_path) + parse_instruction_path = staticmethod( + DataLabelingServiceClient.parse_instruction_path + ) - evaluation_job_path = staticmethod(DataLabelingServiceClient.evaluation_job_path) + common_billing_account_path = staticmethod( + DataLabelingServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + DataLabelingServiceClient.parse_common_billing_account_path + ) - annotation_spec_set_path = staticmethod( - DataLabelingServiceClient.annotation_spec_set_path + common_folder_path = staticmethod(DataLabelingServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + DataLabelingServiceClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + DataLabelingServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + DataLabelingServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(DataLabelingServiceClient.common_project_path) + parse_common_project_path = staticmethod( + DataLabelingServiceClient.parse_common_project_path + ) + + common_location_path = staticmethod(DataLabelingServiceClient.common_location_path) + parse_common_location_path = staticmethod( + DataLabelingServiceClient.parse_common_location_path ) from_service_account_file = DataLabelingServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> DataLabelingServiceTransport: + """Return the transport used by the client instance. + + Returns: + DataLabelingServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(DataLabelingServiceClient).get_transport_class, type(DataLabelingServiceClient), @@ -103,16 +162,19 @@ def __init__( client_options (ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint, this is the default value for - the environment variable) and "auto" (auto switch to the default - mTLS endpoint if client SSL credentials is present). However, - the ``api_endpoint`` property takes precedence if provided. - (2) The ``client_cert_source`` property is used to provide client - SSL credentials for mutual TLS transport. If not provided, the - default SSL credentials will be used if present. + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -171,7 +233,8 @@ async def create_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, dataset]): + has_flattened_params = any([parent, dataset]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -245,7 +308,8 @@ async def get_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -268,7 +332,7 @@ async def get_dataset( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -334,7 +398,8 @@ async def list_datasets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -359,7 +424,7 @@ async def list_datasets( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -414,7 +479,8 @@ async def delete_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -437,7 +503,7 @@ async def delete_dataset( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -506,7 +572,8 @@ async def import_data( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, input_config]): + has_flattened_params = any([name, input_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -613,9 +680,8 @@ async def export_data( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any( - [name, annotated_dataset, filter, output_config] - ): + has_flattened_params = any([name, annotated_dataset, filter, output_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -644,7 +710,7 @@ async def export_data( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -708,7 +774,8 @@ async def get_data_item( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -731,7 +798,7 @@ async def get_data_item( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -798,7 +865,8 @@ async def list_data_items( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -823,7 +891,7 @@ async def list_data_items( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -889,7 +957,8 @@ async def get_annotated_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -912,7 +981,7 @@ async def get_annotated_dataset( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -980,7 +1049,8 @@ async def list_annotated_datasets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1005,7 +1075,7 @@ async def list_annotated_datasets( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -1131,7 +1201,8 @@ async def label_image( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, basic_config, feature]): + has_flattened_params = any([parent, basic_config, feature]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1233,7 +1304,8 @@ async def label_video( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, basic_config, feature]): + has_flattened_params = any([parent, basic_config, feature]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1335,7 +1407,8 @@ async def label_text( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, basic_config, feature]): + has_flattened_params = any([parent, basic_config, feature]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1428,7 +1501,8 @@ async def get_example( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, filter]): + has_flattened_params = any([name, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1453,7 +1527,7 @@ async def get_example( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -1520,7 +1594,8 @@ async def list_examples( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1545,7 +1620,7 @@ async def list_examples( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -1620,7 +1695,8 @@ async def create_annotation_spec_set( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, annotation_spec_set]): + has_flattened_params = any([parent, annotation_spec_set]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1697,7 +1773,8 @@ async def get_annotation_spec_set( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1720,7 +1797,7 @@ async def get_annotation_spec_set( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -1787,7 +1864,8 @@ async def list_annotation_spec_sets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1812,7 +1890,7 @@ async def list_annotation_spec_sets( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -1868,7 +1946,8 @@ async def delete_annotation_spec_set( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1891,7 +1970,7 @@ async def delete_annotation_spec_set( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -1958,7 +2037,8 @@ async def create_instruction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, instruction]): + has_flattened_params = any([parent, instruction]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2040,7 +2120,8 @@ async def get_instruction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2063,7 +2144,7 @@ async def get_instruction( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -2130,7 +2211,8 @@ async def list_instructions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2155,7 +2237,7 @@ async def list_instructions( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -2211,7 +2293,8 @@ async def delete_instruction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2234,7 +2317,7 @@ async def delete_instruction( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -2293,7 +2376,8 @@ async def get_evaluation( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2316,7 +2400,7 @@ async def get_evaluation( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -2414,7 +2498,8 @@ async def search_evaluations( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2439,7 +2524,7 @@ async def search_evaluations( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -2510,7 +2595,8 @@ async def search_example_comparisons( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2598,7 +2684,8 @@ async def create_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, job]): + has_flattened_params = any([parent, job]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2696,7 +2783,8 @@ async def update_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([evaluation_job, update_mask]): + has_flattened_params = any([evaluation_job, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2776,7 +2864,8 @@ async def get_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2799,7 +2888,7 @@ async def get_evaluation_job( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -2852,7 +2941,8 @@ async def pause_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2919,7 +3009,8 @@ async def resume_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2984,7 +3075,8 @@ async def delete_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3007,7 +3099,7 @@ async def delete_evaluation_job( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -3080,7 +3172,8 @@ async def list_evaluation_jobs( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3105,7 +3198,7 @@ async def list_evaluation_jobs( maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py index 6b5def2..c90d144 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py @@ -16,22 +16,24 @@ # from collections import OrderedDict +from distutils import util import os import re -from typing import Callable, Dict, Sequence, Tuple, Type, Union +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +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 gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import 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 from google.oauth2 import service_account # type: ignore -from google.api_core import operation -from google.api_core import operation_async +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore from google.cloud.datalabeling_v1beta1.services.data_labeling_service import pagers from google.cloud.datalabeling_v1beta1.types import annotation from google.cloud.datalabeling_v1beta1.types import annotation_spec_set @@ -93,7 +95,7 @@ def get_transport_class( class DataLabelingServiceClient(metaclass=DataLabelingServiceClientMeta): - """""" + """Service for the AI Platform Data Labeling API.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): @@ -149,6 +151,33 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> DataLabelingServiceTransport: + """Return the transport used by the client instance. + + Returns: + DataLabelingServiceTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def annotated_dataset_path( + project: str, dataset: str, annotated_dataset: str, + ) -> str: + """Return a fully-qualified annotated_dataset string.""" + return "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( + project=project, dataset=dataset, annotated_dataset=annotated_dataset, + ) + + @staticmethod + def parse_annotated_dataset_path(path: str) -> Dict[str, str]: + """Parse a annotated_dataset path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/annotatedDatasets/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def annotation_spec_set_path(project: str, annotation_spec_set: str,) -> str: """Return a fully-qualified annotation_spec_set string.""" @@ -165,6 +194,22 @@ def parse_annotation_spec_set_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def data_item_path(project: str, dataset: str, data_item: str,) -> str: + """Return a fully-qualified data_item string.""" + return "projects/{project}/datasets/{dataset}/dataItems/{data_item}".format( + project=project, dataset=dataset, data_item=data_item, + ) + + @staticmethod + def parse_data_item_path(path: str) -> Dict[str, str]: + """Parse a data_item path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/dataItems/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def dataset_path(project: str, dataset: str,) -> str: """Return a fully-qualified dataset string.""" @@ -178,6 +223,22 @@ def parse_dataset_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def evaluation_path(project: str, dataset: str, evaluation: str,) -> str: + """Return a fully-qualified evaluation string.""" + return "projects/{project}/datasets/{dataset}/evaluations/{evaluation}".format( + project=project, dataset=dataset, evaluation=evaluation, + ) + + @staticmethod + def parse_evaluation_path(path: str) -> Dict[str, str]: + """Parse a evaluation path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/evaluations/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def evaluation_job_path(project: str, evaluation_job: str,) -> str: """Return a fully-qualified evaluation_job string.""" @@ -193,6 +254,27 @@ def parse_evaluation_job_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def example_path( + project: str, dataset: str, annotated_dataset: str, example: str, + ) -> str: + """Return a fully-qualified example string.""" + return "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}/examples/{example}".format( + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, + example=example, + ) + + @staticmethod + def parse_example_path(path: str) -> Dict[str, str]: + """Parse a example path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/annotatedDatasets/(?P.+?)/examples/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def instruction_path(project: str, instruction: str,) -> str: """Return a fully-qualified instruction string.""" @@ -208,12 +290,71 @@ def parse_instruction_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, - credentials: credentials.Credentials = None, - transport: Union[str, DataLabelingServiceTransport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, DataLabelingServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the data labeling service client. @@ -227,23 +368,26 @@ def __init__( transport (Union[str, ~.DataLabelingServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint, this is the default value for - the environment variable) and "auto" (auto switch to the default - mTLS endpoint if client SSL credentials is present). However, - the ``api_endpoint`` property takes precedence if provided. - (2) The ``client_cert_source`` property is used to provide client - SSL credentials for mutual TLS transport. If not provided, the - default SSL credentials will be used if present. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -251,29 +395,47 @@ def __init__( creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool( + util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + ) - if client_options.api_endpoint is None: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + ssl_credentials = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + import grpc # type: ignore + + cert, key = client_options.client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + is_mtls = True + else: + creds = SslCredentials() + is_mtls = creds.is_mtls + ssl_credentials = creds.ssl_credentials if is_mtls else None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") if use_mtls_env == "never": - client_options.api_endpoint = self.DEFAULT_ENDPOINT + api_endpoint = self.DEFAULT_ENDPOINT elif use_mtls_env == "always": - client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT + api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - has_client_cert_source = ( - client_options.client_cert_source is not None - or mtls.has_default_client_cert_source() - ) - client_options.api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT - if has_client_cert_source - else self.DEFAULT_ENDPOINT + api_endpoint = ( + self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT ) else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" ) # Save or instantiate the transport. @@ -297,10 +459,9 @@ def __init__( self._transport = Transport( credentials=credentials, credentials_file=client_options.credentials_file, - host=client_options.api_endpoint, + host=api_endpoint, scopes=client_options.scopes, - api_mtls_endpoint=client_options.api_endpoint, - client_cert_source=client_options.client_cert_source, + ssl_channel_credentials=ssl_credentials, quota_project_id=client_options.quota_project_id, client_info=client_info, ) diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py index 9f723ed..8b6aaee 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py @@ -129,7 +129,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -142,7 +142,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -155,7 +155,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -171,7 +171,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -184,7 +184,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -197,7 +197,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -210,7 +210,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -223,7 +223,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -250,7 +250,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -263,7 +263,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -281,7 +281,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -294,7 +294,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -307,7 +307,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -323,7 +323,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -336,7 +336,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -349,7 +349,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -362,7 +362,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -375,7 +375,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -403,7 +403,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -426,7 +426,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, @@ -439,7 +439,7 @@ def _prep_wrapped_messages(self, client_info): maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=30.0, diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py index 430e2db..f242bad 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py @@ -15,6 +15,7 @@ # limitations under the License. # +import warnings from typing import Callable, Dict, Optional, Sequence, Tuple from google.api_core import grpc_helpers # type: ignore @@ -24,7 +25,6 @@ from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - import grpc # type: ignore from google.cloud.datalabeling_v1beta1.types import annotation_spec_set @@ -47,6 +47,8 @@ class DataLabelingServiceGrpcTransport(DataLabelingServiceTransport): """gRPC backend transport for DataLabelingService. + Service for the AI Platform Data Labeling API. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -67,6 +69,7 @@ def __init__( channel: grpc.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -87,20 +90,22 @@ def __init__( ignored if ``channel`` is provided. channel (Optional[grpc.Channel]): A ``Channel`` instance through which to make calls. - api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If - provided, it overrides the ``host`` argument and tries to create + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A - callback to provide client SSL certificate bytes and private key - bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` - is None. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -109,6 +114,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -116,7 +123,13 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: + warnings.warn( + "api_mtls_endpoint and client_cert_source are deprecated", + DeprecationWarning, + ) + host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -147,6 +160,24 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials + else: + host = host if ":" in host else host + ":443" + + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_channel_credentials, + scopes=scopes or self.AUTH_SCOPES, + quota_project_id=quota_project_id, + ) self._stubs = {} # type: Dict[str, Callable] @@ -207,19 +238,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Sanity check: Only create a new channel if we do not already - # have one. - if not hasattr(self, "_grpc_channel"): - self._grpc_channel = self.create_channel( - self._host, credentials=self._credentials, - ) - - # Return the channel from cache. return self._grpc_channel @property diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py index a139d8f..223a86f 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py @@ -15,11 +15,13 @@ # limitations under the License. # +import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple 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.transport.grpc import SslCredentials # type: ignore @@ -47,6 +49,8 @@ class DataLabelingServiceGrpcAsyncIOTransport(DataLabelingServiceTransport): """gRPC AsyncIO backend transport for DataLabelingService. + Service for the AI Platform Data Labeling API. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -109,6 +113,7 @@ def __init__( channel: aio.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -130,14 +135,16 @@ def __init__( are passed to :func:`google.auth.default`. channel (Optional[aio.Channel]): A ``Channel`` instance through which to make calls. - api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If - provided, it overrides the ``host`` argument and tries to create + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A - callback to provide client SSL certificate bytes and private key - bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` - is None. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -152,6 +159,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -159,13 +168,24 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: + warnings.warn( + "api_mtls_endpoint and client_cert_source are deprecated", + DeprecationWarning, + ) + host = ( api_mtls_endpoint if ":" in api_mtls_endpoint else api_mtls_endpoint + ":443" ) + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + # Create SSL credentials with client_cert_source or application # default SSL credentials. if client_cert_source: @@ -185,6 +205,24 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials + else: + host = host if ":" in host else host + ":443" + + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_channel_credentials, + scopes=scopes or self.AUTH_SCOPES, + quota_project_id=quota_project_id, + ) # Run the base constructor. super().__init__( @@ -205,13 +243,6 @@ def grpc_channel(self) -> aio.Channel: This property caches on the instance; repeated calls return the same channel. """ - # Sanity check: Only create a new channel if we do not already - # have one. - if not hasattr(self, "_grpc_channel"): - self._grpc_channel = self.create_channel( - self._host, credentials=self._credentials, - ) - # Return the channel from cache. return self._grpc_channel diff --git a/google/cloud/datalabeling_v1beta1/types/annotation.py b/google/cloud/datalabeling_v1beta1/types/annotation.py index 6e75d18..c237644 100644 --- a/google/cloud/datalabeling_v1beta1/types/annotation.py +++ b/google/cloud/datalabeling_v1beta1/types/annotation.py @@ -273,7 +273,7 @@ class BoundingPoly(proto.Message): The bounding polygon vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message=Vertex,) + vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) class NormalizedBoundingPoly(proto.Message): @@ -285,7 +285,7 @@ class NormalizedBoundingPoly(proto.Message): """ normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=1, message=NormalizedVertex, + proto.MESSAGE, number=1, message="NormalizedVertex", ) @@ -303,11 +303,11 @@ class ImageBoundingPolyAnnotation(proto.Message): """ bounding_poly = proto.Field( - proto.MESSAGE, number=2, oneof="bounded_area", message=BoundingPoly, + proto.MESSAGE, number=2, oneof="bounded_area", message="BoundingPoly", ) normalized_bounding_poly = proto.Field( - proto.MESSAGE, number=3, oneof="bounded_area", message=NormalizedBoundingPoly, + proto.MESSAGE, number=3, oneof="bounded_area", message="NormalizedBoundingPoly", ) annotation_spec = proto.Field( @@ -323,7 +323,7 @@ class Polyline(proto.Message): The polyline vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message=Vertex,) + vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) class NormalizedPolyline(proto.Message): @@ -335,7 +335,7 @@ class NormalizedPolyline(proto.Message): """ normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=1, message=NormalizedVertex, + proto.MESSAGE, number=1, message="NormalizedVertex", ) @@ -351,10 +351,10 @@ class ImagePolylineAnnotation(proto.Message): Label of this polyline. """ - polyline = proto.Field(proto.MESSAGE, number=2, oneof="poly", message=Polyline,) + polyline = proto.Field(proto.MESSAGE, number=2, oneof="poly", message="Polyline",) normalized_polyline = proto.Field( - proto.MESSAGE, number=3, oneof="poly", message=NormalizedPolyline, + proto.MESSAGE, number=3, oneof="poly", message="NormalizedPolyline", ) annotation_spec = proto.Field( @@ -467,7 +467,7 @@ class VideoClassificationAnnotation(proto.Message): Label of the segment specified by time_segment. """ - time_segment = proto.Field(proto.MESSAGE, number=1, message=TimeSegment,) + time_segment = proto.Field(proto.MESSAGE, number=1, message="TimeSegment",) annotation_spec = proto.Field( proto.MESSAGE, number=2, message=annotation_spec_set.AnnotationSpec, @@ -489,11 +489,11 @@ class ObjectTrackingFrame(proto.Message): """ bounding_poly = proto.Field( - proto.MESSAGE, number=1, oneof="bounded_area", message=BoundingPoly, + proto.MESSAGE, number=1, oneof="bounded_area", message="BoundingPoly", ) normalized_bounding_poly = proto.Field( - proto.MESSAGE, number=2, oneof="bounded_area", message=NormalizedBoundingPoly, + proto.MESSAGE, number=2, oneof="bounded_area", message="NormalizedBoundingPoly", ) time_offset = proto.Field(proto.MESSAGE, number=3, message=duration.Duration,) @@ -518,10 +518,10 @@ class VideoObjectTrackingAnnotation(proto.Message): proto.MESSAGE, number=1, message=annotation_spec_set.AnnotationSpec, ) - time_segment = proto.Field(proto.MESSAGE, number=2, message=TimeSegment,) + time_segment = proto.Field(proto.MESSAGE, number=2, message="TimeSegment",) object_tracking_frames = proto.RepeatedField( - proto.MESSAGE, number=3, message=ObjectTrackingFrame, + proto.MESSAGE, number=3, message="ObjectTrackingFrame", ) @@ -540,7 +540,7 @@ class VideoEventAnnotation(proto.Message): proto.MESSAGE, number=1, message=annotation_spec_set.AnnotationSpec, ) - time_segment = proto.Field(proto.MESSAGE, number=2, message=TimeSegment,) + time_segment = proto.Field(proto.MESSAGE, number=2, message="TimeSegment",) class AnnotationMetadata(proto.Message): diff --git a/google/cloud/datalabeling_v1beta1/types/data_payloads.py b/google/cloud/datalabeling_v1beta1/types/data_payloads.py index 6117229..bb58d25 100644 --- a/google/cloud/datalabeling_v1beta1/types/data_payloads.py +++ b/google/cloud/datalabeling_v1beta1/types/data_payloads.py @@ -101,7 +101,7 @@ class VideoPayload(proto.Message): video_uri = proto.Field(proto.STRING, number=2) video_thumbnails = proto.RepeatedField( - proto.MESSAGE, number=3, message=VideoThumbnail, + proto.MESSAGE, number=3, message="VideoThumbnail", ) frame_rate = proto.Field(proto.FLOAT, number=4) diff --git a/noxfile.py b/noxfile.py index 9f35fe6..3515f4e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,7 +28,7 @@ DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -72,7 +72,9 @@ def default(session): # Install all test dependencies, then install this package in-place. session.install("asyncmock", "pytest-asyncio") - session.install("mock", "pytest", "pytest-cov") + session.install( + "mock", "pytest", "pytest-cov", + ) session.install("-e", ".") # Run py.test against the unit tests. @@ -173,7 +175,9 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark", "sphinx-docfx-yaml") + # sphinx-docfx-yaml supports up to sphinx version 1.5.5. + # https://github.com/docascode/sphinx-docfx-yaml/issues/97 + session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index ba55d7c..b90eef0 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -39,6 +39,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -132,7 +136,10 @@ def _determine_local_import_names(start_dir): @nox.session def lint(session): - session.install("flake8", "flake8-import-order") + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +148,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session): + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -201,6 +218,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") diff --git a/scripts/decrypt-secrets.sh b/scripts/decrypt-secrets.sh index ff599eb..21f6d2a 100755 --- a/scripts/decrypt-secrets.sh +++ b/scripts/decrypt-secrets.sh @@ -20,14 +20,27 @@ ROOT=$( dirname "$DIR" ) # Work from the project root. cd $ROOT +# Prevent it from overriding files. +# We recommend that sample authors use their own service account files and cloud project. +# In that case, they are supposed to prepare these files by themselves. +if [[ -f "testing/test-env.sh" ]] || \ + [[ -f "testing/service-account.json" ]] || \ + [[ -f "testing/client-secrets.json" ]]; then + echo "One or more target files exist, aborting." + exit 1 +fi + # Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources. PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}" gcloud secrets versions access latest --secret="python-docs-samples-test-env" \ + --project="${PROJECT_ID}" \ > testing/test-env.sh gcloud secrets versions access latest \ --secret="python-docs-samples-service-account" \ + --project="${PROJECT_ID}" \ > testing/service-account.json gcloud secrets versions access latest \ --secret="python-docs-samples-client-secrets" \ - > testing/client-secrets.json \ No newline at end of file + --project="${PROJECT_ID}" \ + > testing/client-secrets.json diff --git a/scripts/fixup_datalabeling_v1beta1_keywords.py b/scripts/fixup_datalabeling_v1beta1_keywords.py index 9a49fac..ed84f93 100644 --- a/scripts/fixup_datalabeling_v1beta1_keywords.py +++ b/scripts/fixup_datalabeling_v1beta1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index baea70f..a6423e9 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,30 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-datalabeling.git", - "sha": "7a75eee979484506bb3cc3b6b3e2e51c09a4a94d" + "remote": "git@github.com:googleapis/python-datalabeling.git", + "sha": "3dac8e068118b5dea339653b0a731461c236c545" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "ddaa2026caf2eb00444a14b08500553824a7182a", - "internalRef": "329845759" + "sha": "5fdb685a684269e07c10c7518372eb5d7b6bc0a9", + "internalRef": "342906697" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "d91dd8aac77f7a9c5506c238038a26fa4f9e361e" + "sha": "7fcc405a579d5d53a726ff3da1b7c8c08f0f2d58" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "d91dd8aac77f7a9c5506c238038a26fa4f9e361e" + "sha": "7fcc405a579d5d53a726ff3da1b7c8c08f0f2d58" } } ], @@ -40,112 +40,5 @@ "generator": "bazel" } } - ], - "generatedFiles": [ - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/datalabeling_v1beta1/services.rst", - "docs/datalabeling_v1beta1/types.rst", - "docs/multiprocessing.rst", - "google/cloud/datalabeling/__init__.py", - "google/cloud/datalabeling/py.typed", - "google/cloud/datalabeling_v1beta1/__init__.py", - "google/cloud/datalabeling_v1beta1/proto/annotation.proto", - "google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto", - "google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto", - "google/cloud/datalabeling_v1beta1/proto/data_payloads.proto", - "google/cloud/datalabeling_v1beta1/proto/dataset.proto", - "google/cloud/datalabeling_v1beta1/proto/evaluation.proto", - "google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto", - "google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto", - "google/cloud/datalabeling_v1beta1/proto/instruction.proto", - "google/cloud/datalabeling_v1beta1/proto/operations.proto", - "google/cloud/datalabeling_v1beta1/py.typed", - "google/cloud/datalabeling_v1beta1/services/__init__.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/__init__.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/pagers.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/__init__.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py", - "google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py", - "google/cloud/datalabeling_v1beta1/types/__init__.py", - "google/cloud/datalabeling_v1beta1/types/annotation.py", - "google/cloud/datalabeling_v1beta1/types/annotation_spec_set.py", - "google/cloud/datalabeling_v1beta1/types/data_labeling_service.py", - "google/cloud/datalabeling_v1beta1/types/data_payloads.py", - "google/cloud/datalabeling_v1beta1/types/dataset.py", - "google/cloud/datalabeling_v1beta1/types/evaluation.py", - "google/cloud/datalabeling_v1beta1/types/evaluation_job.py", - "google/cloud/datalabeling_v1beta1/types/human_annotation_config.py", - "google/cloud/datalabeling_v1beta1/types/instruction.py", - "google/cloud/datalabeling_v1beta1/types/operations.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "samples/AUTHORING_GUIDE.md", - "samples/CONTRIBUTING.md", - "samples/snippets/noxfile.py", - "scripts/decrypt-secrets.sh", - "scripts/fixup_datalabeling_v1beta1_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/datalabeling_v1beta1/__init__.py", - "tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py" ] } \ No newline at end of file diff --git a/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py b/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py index da451de..8e68492 100644 --- a/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py +++ b/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py @@ -31,7 +31,7 @@ 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 +from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.auth import credentials from google.auth.exceptions import MutualTLSChannelError @@ -61,7 +61,7 @@ from google.cloud.datalabeling_v1beta1.types import operations from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import any_pb2 as any # type: ignore +from google.protobuf import any_pb2 as gp_any # type: ignore from google.protobuf import duration_pb2 as duration # type: ignore from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import timestamp_pb2 as timestamp # type: ignore @@ -123,12 +123,12 @@ def test_data_labeling_service_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "datalabeling.googleapis.com:443" + assert client.transport._host == "datalabeling.googleapis.com:443" def test_data_labeling_service_client_get_transport_class(): @@ -188,15 +188,14 @@ def test_data_labeling_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "never"}): + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class() @@ -205,15 +204,14 @@ def test_data_labeling_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "always"}): + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class() @@ -222,95 +220,185 @@ def test_data_labeling_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", and client_cert_source is provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class() + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class() + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + ssl_channel_credentials=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + DataLabelingServiceClient, + transports.DataLabelingServiceGrpcTransport, + "grpc", + "true", + ), + ( + DataLabelingServiceAsyncClient, + transports.DataLabelingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + DataLabelingServiceClient, + transports.DataLabelingServiceGrpcTransport, + "grpc", + "false", + ), + ( + DataLabelingServiceAsyncClient, + transports.DataLabelingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + DataLabelingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DataLabelingServiceClient), +) +@mock.patch.object( + DataLabelingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DataLabelingServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_data_labeling_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): options = client_options.ClientOptions( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=client_cert_source_callback, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", and default_client_cert_source is provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): - with mock.patch.object(transport_class, "__init__") as patched: + ssl_channel_creds = mock.Mock() with mock.patch( - "google.auth.transport.mtls.has_default_client_cert_source", - return_value=True, + "grpc.ssl_channel_credentials", return_value=ssl_channel_creds ): patched.return_value = None - client = client_class() + client = client_class(client_options=options) + + if use_client_cert_env == "false": + expected_ssl_channel_creds = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_ssl_channel_creds = ssl_channel_creds + expected_host = client.DEFAULT_MTLS_ENDPOINT + patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, + host=expected_host, scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=expected_ssl_channel_creds, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", but client_cert_source and default_client_cert_source are None. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.mtls.has_default_client_cert_source", - return_value=False, + "google.auth.transport.grpc.SslCredentials.__init__", return_value=None ): - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class() - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + with mock.patch( + "google.auth.transport.grpc.SslCredentials.is_mtls", + new_callable=mock.PropertyMock, + ) as is_mtls_mock: + with mock.patch( + "google.auth.transport.grpc.SslCredentials.ssl_credentials", + new_callable=mock.PropertyMock, + ) as ssl_credentials_mock: + if use_client_cert_env == "false": + is_mtls_mock.return_value = False + ssl_credentials_mock.return_value = None + expected_host = client.DEFAULT_ENDPOINT + expected_ssl_channel_creds = None + else: + is_mtls_mock.return_value = True + ssl_credentials_mock.return_value = mock.Mock() + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_ssl_channel_creds = ( + ssl_credentials_mock.return_value + ) + + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + ssl_channel_credentials=expected_ssl_channel_creds, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + ): + with mock.patch( + "google.auth.transport.grpc.SslCredentials.is_mtls", + new_callable=mock.PropertyMock, + ) as is_mtls_mock: + is_mtls_mock.return_value = False + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + ssl_channel_credentials=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) @pytest.mark.parametrize( @@ -341,8 +429,7 @@ def test_data_labeling_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -376,8 +463,7 @@ def test_data_labeling_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -396,8 +482,7 @@ def test_data_labeling_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -415,7 +500,7 @@ def test_create_dataset( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcd_dataset.Dataset( name="name_value", @@ -434,6 +519,7 @@ def test_create_dataset( assert args[0] == data_labeling_service.CreateDatasetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcd_dataset.Dataset) assert response.name == "name_value" @@ -452,19 +538,20 @@ def test_create_dataset_from_dict(): @pytest.mark.asyncio -async def test_create_dataset_async(transport: str = "grpc_asyncio"): +async def test_create_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcd_dataset.Dataset( @@ -482,7 +569,7 @@ async def test_create_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcd_dataset.Dataset) @@ -498,6 +585,11 @@ async def test_create_dataset_async(transport: str = "grpc_asyncio"): assert response.data_item_count == 1584 +@pytest.mark.asyncio +async def test_create_dataset_async_from_dict(): + await test_create_dataset_async(request_type=dict) + + def test_create_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -507,7 +599,7 @@ def test_create_dataset_field_headers(): 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: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = gcd_dataset.Dataset() client.create_dataset(request) @@ -534,9 +626,7 @@ async def test_create_dataset_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcd_dataset.Dataset()) await client.create_dataset(request) @@ -555,7 +645,7 @@ def test_create_dataset_flattened(): client = DataLabelingServiceClient(credentials=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: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcd_dataset.Dataset() @@ -595,9 +685,7 @@ async def test_create_dataset_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcd_dataset.Dataset() @@ -646,7 +734,7 @@ def test_get_dataset( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_dataset), "__call__") as call: + 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( name="name_value", @@ -665,6 +753,7 @@ def test_get_dataset( assert args[0] == data_labeling_service.GetDatasetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.Dataset) assert response.name == "name_value" @@ -683,19 +772,20 @@ def test_get_dataset_from_dict(): @pytest.mark.asyncio -async def test_get_dataset_async(transport: str = "grpc_asyncio"): +async def test_get_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.Dataset( @@ -713,7 +803,7 @@ async def test_get_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.Dataset) @@ -729,6 +819,11 @@ async def test_get_dataset_async(transport: str = "grpc_asyncio"): assert response.data_item_count == 1584 +@pytest.mark.asyncio +async def test_get_dataset_async_from_dict(): + await test_get_dataset_async(request_type=dict) + + def test_get_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -738,7 +833,7 @@ def test_get_dataset_field_headers(): 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: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = dataset.Dataset() client.get_dataset(request) @@ -765,9 +860,7 @@ async def test_get_dataset_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_dataset), "__call__" - ) as call: + 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) @@ -786,7 +879,7 @@ def test_get_dataset_flattened(): client = DataLabelingServiceClient(credentials=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: + 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() @@ -820,9 +913,7 @@ async def test_get_dataset_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_dataset), "__call__" - ) as call: + 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() @@ -865,7 +956,7 @@ def test_list_datasets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_datasets), "__call__") as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDatasetsResponse( next_page_token="next_page_token_value", @@ -880,6 +971,7 @@ def test_list_datasets( assert args[0] == data_labeling_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" @@ -890,19 +982,20 @@ def test_list_datasets_from_dict(): @pytest.mark.asyncio -async def test_list_datasets_async(transport: str = "grpc_asyncio"): +async def test_list_datasets_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListDatasetsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListDatasetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_datasets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDatasetsResponse( @@ -916,7 +1009,7 @@ async def test_list_datasets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListDatasetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDatasetsAsyncPager) @@ -924,6 +1017,11 @@ async def test_list_datasets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_datasets_async_from_dict(): + await test_list_datasets_async(request_type=dict) + + def test_list_datasets_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -933,7 +1031,7 @@ def test_list_datasets_field_headers(): 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: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: call.return_value = data_labeling_service.ListDatasetsResponse() client.list_datasets(request) @@ -960,9 +1058,7 @@ async def test_list_datasets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_datasets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDatasetsResponse() ) @@ -983,7 +1079,7 @@ def test_list_datasets_flattened(): client = DataLabelingServiceClient(credentials=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: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDatasetsResponse() @@ -1023,9 +1119,7 @@ async def test_list_datasets_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_datasets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDatasetsResponse() @@ -1068,7 +1162,7 @@ def test_list_datasets_pager(): client = DataLabelingServiceClient(credentials=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: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDatasetsResponse( @@ -1104,7 +1198,7 @@ def test_list_datasets_pages(): client = DataLabelingServiceClient(credentials=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: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDatasetsResponse( @@ -1135,9 +1229,7 @@ async def test_list_datasets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_datasets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_datasets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1174,9 +1266,7 @@ async def test_list_datasets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_datasets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_datasets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1214,7 +1304,7 @@ def test_delete_dataset( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1235,19 +1325,20 @@ def test_delete_dataset_from_dict(): @pytest.mark.asyncio -async def test_delete_dataset_async(transport: str = "grpc_asyncio"): +async def test_delete_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1257,12 +1348,17 @@ async def test_delete_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteDatasetRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_dataset_async_from_dict(): + await test_delete_dataset_async(request_type=dict) + + def test_delete_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1272,7 +1368,7 @@ def test_delete_dataset_field_headers(): 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: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: call.return_value = None client.delete_dataset(request) @@ -1299,9 +1395,7 @@ async def test_delete_dataset_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_dataset(request) @@ -1320,7 +1414,7 @@ def test_delete_dataset_flattened(): client = DataLabelingServiceClient(credentials=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: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1354,9 +1448,7 @@ async def test_delete_dataset_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1399,7 +1491,7 @@ def test_import_data( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_data), "__call__") as call: + 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") @@ -1420,19 +1512,20 @@ def test_import_data_from_dict(): @pytest.mark.asyncio -async def test_import_data_async(transport: str = "grpc_asyncio"): +async def test_import_data_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ImportDataRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ImportDataRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1444,12 +1537,17 @@ async def test_import_data_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ImportDataRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_import_data_async_from_dict(): + await test_import_data_async(request_type=dict) + + def test_import_data_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1459,7 +1557,7 @@ def test_import_data_field_headers(): 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: + 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) @@ -1486,9 +1584,7 @@ async def test_import_data_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1509,7 +1605,7 @@ def test_import_data_flattened(): client = DataLabelingServiceClient(credentials=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: + 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") @@ -1556,9 +1652,7 @@ async def test_import_data_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_data), "__call__" - ) as call: + 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") @@ -1616,7 +1710,7 @@ def test_export_data( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_data), "__call__") as call: + 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") @@ -1637,19 +1731,20 @@ def test_export_data_from_dict(): @pytest.mark.asyncio -async def test_export_data_async(transport: str = "grpc_asyncio"): +async def test_export_data_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ExportDataRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ExportDataRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1661,12 +1756,17 @@ async def test_export_data_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ExportDataRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_export_data_async_from_dict(): + await test_export_data_async(request_type=dict) + + def test_export_data_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1676,7 +1776,7 @@ def test_export_data_field_headers(): 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: + 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) @@ -1703,9 +1803,7 @@ async def test_export_data_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1726,7 +1824,7 @@ def test_export_data_flattened(): client = DataLabelingServiceClient(credentials=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: + 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") @@ -1781,9 +1879,7 @@ async def test_export_data_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_data), "__call__" - ) as call: + 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") @@ -1849,7 +1945,7 @@ def test_get_data_item( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_data_item), "__call__") as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.DataItem( name="name_value", @@ -1865,6 +1961,7 @@ def test_get_data_item( assert args[0] == data_labeling_service.GetDataItemRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.DataItem) assert response.name == "name_value" @@ -1875,19 +1972,20 @@ def test_get_data_item_from_dict(): @pytest.mark.asyncio -async def test_get_data_item_async(transport: str = "grpc_asyncio"): +async def test_get_data_item_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetDataItemRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetDataItemRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_data_item), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.DataItem(name="name_value",) @@ -1899,7 +1997,7 @@ async def test_get_data_item_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetDataItemRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.DataItem) @@ -1907,6 +2005,11 @@ async def test_get_data_item_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_data_item_async_from_dict(): + await test_get_data_item_async(request_type=dict) + + def test_get_data_item_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1916,7 +2019,7 @@ def test_get_data_item_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_data_item), "__call__") as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: call.return_value = dataset.DataItem() client.get_data_item(request) @@ -1943,9 +2046,7 @@ async def test_get_data_item_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_data_item), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.DataItem()) await client.get_data_item(request) @@ -1964,7 +2065,7 @@ def test_get_data_item_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_data_item), "__call__") as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.DataItem() @@ -1998,9 +2099,7 @@ async def test_get_data_item_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_data_item), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.DataItem() @@ -2043,7 +2142,7 @@ def test_list_data_items( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDataItemsResponse( next_page_token="next_page_token_value", @@ -2058,6 +2157,7 @@ def test_list_data_items( assert args[0] == data_labeling_service.ListDataItemsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDataItemsPager) assert response.next_page_token == "next_page_token_value" @@ -2068,19 +2168,20 @@ def test_list_data_items_from_dict(): @pytest.mark.asyncio -async def test_list_data_items_async(transport: str = "grpc_asyncio"): +async def test_list_data_items_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListDataItemsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListDataItemsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_data_items), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDataItemsResponse( @@ -2094,7 +2195,7 @@ async def test_list_data_items_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListDataItemsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDataItemsAsyncPager) @@ -2102,6 +2203,11 @@ async def test_list_data_items_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_data_items_async_from_dict(): + await test_list_data_items_async(request_type=dict) + + def test_list_data_items_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2111,7 +2217,7 @@ def test_list_data_items_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: call.return_value = data_labeling_service.ListDataItemsResponse() client.list_data_items(request) @@ -2138,9 +2244,7 @@ async def test_list_data_items_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_data_items), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDataItemsResponse() ) @@ -2161,7 +2265,7 @@ def test_list_data_items_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDataItemsResponse() @@ -2201,9 +2305,7 @@ async def test_list_data_items_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_data_items), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDataItemsResponse() @@ -2246,7 +2348,7 @@ def test_list_data_items_pager(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDataItemsResponse( @@ -2286,7 +2388,7 @@ def test_list_data_items_pages(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDataItemsResponse( @@ -2321,9 +2423,7 @@ async def test_list_data_items_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_data_items), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_data_items), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2364,9 +2464,7 @@ async def test_list_data_items_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_data_items), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_data_items), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2410,7 +2508,7 @@ def test_get_annotated_dataset( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = dataset.AnnotatedDataset( @@ -2433,6 +2531,7 @@ def test_get_annotated_dataset( assert args[0] == data_labeling_service.GetAnnotatedDatasetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.AnnotatedDataset) assert response.name == "name_value" @@ -2460,18 +2559,21 @@ def test_get_annotated_dataset_from_dict(): @pytest.mark.asyncio -async def test_get_annotated_dataset_async(transport: str = "grpc_asyncio"): +async def test_get_annotated_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetAnnotatedDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetAnnotatedDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2493,7 +2595,7 @@ async def test_get_annotated_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetAnnotatedDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.AnnotatedDataset) @@ -2518,6 +2620,11 @@ async def test_get_annotated_dataset_async(transport: str = "grpc_asyncio"): assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_get_annotated_dataset_async_from_dict(): + await test_get_annotated_dataset_async(request_type=dict) + + def test_get_annotated_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2528,7 +2635,7 @@ def test_get_annotated_dataset_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: call.return_value = dataset.AnnotatedDataset() @@ -2557,7 +2664,7 @@ async def test_get_annotated_dataset_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.AnnotatedDataset() @@ -2580,7 +2687,7 @@ def test_get_annotated_dataset_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = dataset.AnnotatedDataset() @@ -2616,7 +2723,7 @@ async def test_get_annotated_dataset_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = dataset.AnnotatedDataset() @@ -2664,7 +2771,7 @@ def test_list_annotated_datasets( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse( @@ -2680,6 +2787,7 @@ def test_list_annotated_datasets( assert args[0] == data_labeling_service.ListAnnotatedDatasetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAnnotatedDatasetsPager) assert response.next_page_token == "next_page_token_value" @@ -2690,18 +2798,21 @@ def test_list_annotated_datasets_from_dict(): @pytest.mark.asyncio -async def test_list_annotated_datasets_async(transport: str = "grpc_asyncio"): +async def test_list_annotated_datasets_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListAnnotatedDatasetsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListAnnotatedDatasetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2716,7 +2827,7 @@ async def test_list_annotated_datasets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListAnnotatedDatasetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAnnotatedDatasetsAsyncPager) @@ -2724,6 +2835,11 @@ async def test_list_annotated_datasets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_annotated_datasets_async_from_dict(): + await test_list_annotated_datasets_async(request_type=dict) + + def test_list_annotated_datasets_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2734,7 +2850,7 @@ def test_list_annotated_datasets_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2763,7 +2879,7 @@ async def test_list_annotated_datasets_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2786,7 +2902,7 @@ def test_list_annotated_datasets_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2828,7 +2944,7 @@ async def test_list_annotated_datasets_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2873,7 +2989,7 @@ def test_list_annotated_datasets_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2918,7 +3034,7 @@ def test_list_annotated_datasets_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2957,7 +3073,7 @@ async def test_list_annotated_datasets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), + type(client.transport.list_annotated_datasets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -3003,7 +3119,7 @@ async def test_list_annotated_datasets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), + type(client.transport.list_annotated_datasets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -3052,7 +3168,7 @@ def test_delete_annotated_dataset( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -3074,18 +3190,21 @@ def test_delete_annotated_dataset_from_dict(): @pytest.mark.asyncio -async def test_delete_annotated_dataset_async(transport: str = "grpc_asyncio"): +async def test_delete_annotated_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteAnnotatedDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteAnnotatedDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -3096,12 +3215,17 @@ async def test_delete_annotated_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteAnnotatedDatasetRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_annotated_dataset_async_from_dict(): + await test_delete_annotated_dataset_async(request_type=dict) + + def test_delete_annotated_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3112,7 +3236,7 @@ def test_delete_annotated_dataset_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: call.return_value = None @@ -3141,7 +3265,7 @@ async def test_delete_annotated_dataset_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -3169,7 +3293,7 @@ def test_label_image( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_image), "__call__") as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3190,19 +3314,20 @@ def test_label_image_from_dict(): @pytest.mark.asyncio -async def test_label_image_async(transport: str = "grpc_asyncio"): +async def test_label_image_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.LabelImageRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.LabelImageRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_image), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -3214,12 +3339,17 @@ async def test_label_image_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.LabelImageRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_label_image_async_from_dict(): + await test_label_image_async(request_type=dict) + + def test_label_image_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3229,7 +3359,7 @@ def test_label_image_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_image), "__call__") as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.label_image(request) @@ -3256,9 +3386,7 @@ async def test_label_image_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_image), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -3279,7 +3407,7 @@ def test_label_image_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_image), "__call__") as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3333,9 +3461,7 @@ async def test_label_image_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_image), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3400,7 +3526,7 @@ def test_label_video( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_video), "__call__") as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3421,19 +3547,20 @@ def test_label_video_from_dict(): @pytest.mark.asyncio -async def test_label_video_async(transport: str = "grpc_asyncio"): +async def test_label_video_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.LabelVideoRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.LabelVideoRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_video), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -3445,12 +3572,17 @@ async def test_label_video_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.LabelVideoRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_label_video_async_from_dict(): + await test_label_video_async(request_type=dict) + + def test_label_video_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3460,7 +3592,7 @@ def test_label_video_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_video), "__call__") as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.label_video(request) @@ -3487,9 +3619,7 @@ async def test_label_video_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_video), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -3510,7 +3640,7 @@ def test_label_video_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_video), "__call__") as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3564,9 +3694,7 @@ async def test_label_video_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_video), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3631,7 +3759,7 @@ def test_label_text( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_text), "__call__") as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3652,19 +3780,19 @@ def test_label_text_from_dict(): @pytest.mark.asyncio -async def test_label_text_async(transport: str = "grpc_asyncio"): +async def test_label_text_async( + transport: str = "grpc_asyncio", request_type=data_labeling_service.LabelTextRequest +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.LabelTextRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_text), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -3676,12 +3804,17 @@ async def test_label_text_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.LabelTextRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_label_text_async_from_dict(): + await test_label_text_async(request_type=dict) + + def test_label_text_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3691,7 +3824,7 @@ def test_label_text_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_text), "__call__") as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.label_text(request) @@ -3718,9 +3851,7 @@ async def test_label_text_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_text), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -3741,7 +3872,7 @@ def test_label_text_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_text), "__call__") as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3795,9 +3926,7 @@ async def test_label_text_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_text), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3862,7 +3991,7 @@ def test_get_example( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_example), "__call__") as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Example( name="name_value", @@ -3878,6 +4007,7 @@ def test_get_example( assert args[0] == data_labeling_service.GetExampleRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.Example) assert response.name == "name_value" @@ -3888,19 +4018,20 @@ def test_get_example_from_dict(): @pytest.mark.asyncio -async def test_get_example_async(transport: str = "grpc_asyncio"): +async def test_get_example_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetExampleRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetExampleRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_example), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.Example(name="name_value",) @@ -3912,7 +4043,7 @@ async def test_get_example_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetExampleRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.Example) @@ -3920,6 +4051,11 @@ async def test_get_example_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_example_async_from_dict(): + await test_get_example_async(request_type=dict) + + def test_get_example_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3929,7 +4065,7 @@ def test_get_example_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_example), "__call__") as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: call.return_value = dataset.Example() client.get_example(request) @@ -3956,9 +4092,7 @@ async def test_get_example_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_example), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Example()) await client.get_example(request) @@ -3977,7 +4111,7 @@ def test_get_example_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_example), "__call__") as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Example() @@ -4017,9 +4151,7 @@ async def test_get_example_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_example), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Example() @@ -4066,7 +4198,7 @@ def test_list_examples( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListExamplesResponse( next_page_token="next_page_token_value", @@ -4081,6 +4213,7 @@ def test_list_examples( assert args[0] == data_labeling_service.ListExamplesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListExamplesPager) assert response.next_page_token == "next_page_token_value" @@ -4091,19 +4224,20 @@ def test_list_examples_from_dict(): @pytest.mark.asyncio -async def test_list_examples_async(transport: str = "grpc_asyncio"): +async def test_list_examples_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListExamplesRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListExamplesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_examples), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListExamplesResponse( @@ -4117,7 +4251,7 @@ async def test_list_examples_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListExamplesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListExamplesAsyncPager) @@ -4125,6 +4259,11 @@ async def test_list_examples_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_examples_async_from_dict(): + await test_list_examples_async(request_type=dict) + + def test_list_examples_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4134,7 +4273,7 @@ def test_list_examples_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: call.return_value = data_labeling_service.ListExamplesResponse() client.list_examples(request) @@ -4161,9 +4300,7 @@ async def test_list_examples_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_examples), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListExamplesResponse() ) @@ -4184,7 +4321,7 @@ def test_list_examples_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListExamplesResponse() @@ -4224,9 +4361,7 @@ async def test_list_examples_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_examples), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListExamplesResponse() @@ -4269,7 +4404,7 @@ def test_list_examples_pager(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListExamplesResponse( @@ -4305,7 +4440,7 @@ def test_list_examples_pages(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListExamplesResponse( @@ -4336,9 +4471,7 @@ async def test_list_examples_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_examples), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_examples), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4375,9 +4508,7 @@ async def test_list_examples_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_examples), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_examples), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4417,7 +4548,7 @@ def test_create_annotation_spec_set( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_annotation_spec_set.AnnotationSpecSet( @@ -4436,6 +4567,7 @@ def test_create_annotation_spec_set( assert args[0] == data_labeling_service.CreateAnnotationSpecSetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcd_annotation_spec_set.AnnotationSpecSet) assert response.name == "name_value" @@ -4452,18 +4584,21 @@ def test_create_annotation_spec_set_from_dict(): @pytest.mark.asyncio -async def test_create_annotation_spec_set_async(transport: str = "grpc_asyncio"): +async def test_create_annotation_spec_set_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateAnnotationSpecSetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateAnnotationSpecSetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4481,7 +4616,7 @@ async def test_create_annotation_spec_set_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateAnnotationSpecSetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcd_annotation_spec_set.AnnotationSpecSet) @@ -4495,6 +4630,11 @@ async def test_create_annotation_spec_set_async(transport: str = "grpc_asyncio") assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_create_annotation_spec_set_async_from_dict(): + await test_create_annotation_spec_set_async(request_type=dict) + + def test_create_annotation_spec_set_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4505,7 +4645,7 @@ def test_create_annotation_spec_set_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: call.return_value = gcd_annotation_spec_set.AnnotationSpecSet() @@ -4534,7 +4674,7 @@ async def test_create_annotation_spec_set_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcd_annotation_spec_set.AnnotationSpecSet() @@ -4557,7 +4697,7 @@ def test_create_annotation_spec_set_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_annotation_spec_set.AnnotationSpecSet() @@ -4606,7 +4746,7 @@ async def test_create_annotation_spec_set_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_annotation_spec_set.AnnotationSpecSet() @@ -4667,7 +4807,7 @@ def test_get_annotation_spec_set( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec_set.AnnotationSpecSet( @@ -4686,6 +4826,7 @@ def test_get_annotation_spec_set( assert args[0] == data_labeling_service.GetAnnotationSpecSetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, annotation_spec_set.AnnotationSpecSet) assert response.name == "name_value" @@ -4702,18 +4843,21 @@ def test_get_annotation_spec_set_from_dict(): @pytest.mark.asyncio -async def test_get_annotation_spec_set_async(transport: str = "grpc_asyncio"): +async def test_get_annotation_spec_set_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetAnnotationSpecSetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetAnnotationSpecSetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4731,7 +4875,7 @@ async def test_get_annotation_spec_set_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetAnnotationSpecSetRequest() # Establish that the response is the type that we expect. assert isinstance(response, annotation_spec_set.AnnotationSpecSet) @@ -4745,6 +4889,11 @@ async def test_get_annotation_spec_set_async(transport: str = "grpc_asyncio"): assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_get_annotation_spec_set_async_from_dict(): + await test_get_annotation_spec_set_async(request_type=dict) + + def test_get_annotation_spec_set_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4755,7 +4904,7 @@ def test_get_annotation_spec_set_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: call.return_value = annotation_spec_set.AnnotationSpecSet() @@ -4784,7 +4933,7 @@ async def test_get_annotation_spec_set_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( annotation_spec_set.AnnotationSpecSet() @@ -4807,7 +4956,7 @@ def test_get_annotation_spec_set_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec_set.AnnotationSpecSet() @@ -4843,7 +4992,7 @@ async def test_get_annotation_spec_set_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec_set.AnnotationSpecSet() @@ -4891,7 +5040,7 @@ def test_list_annotation_spec_sets( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse( @@ -4907,6 +5056,7 @@ def test_list_annotation_spec_sets( assert args[0] == data_labeling_service.ListAnnotationSpecSetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAnnotationSpecSetsPager) assert response.next_page_token == "next_page_token_value" @@ -4917,18 +5067,21 @@ def test_list_annotation_spec_sets_from_dict(): @pytest.mark.asyncio -async def test_list_annotation_spec_sets_async(transport: str = "grpc_asyncio"): +async def test_list_annotation_spec_sets_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListAnnotationSpecSetsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListAnnotationSpecSetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4943,7 +5096,7 @@ async def test_list_annotation_spec_sets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListAnnotationSpecSetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAnnotationSpecSetsAsyncPager) @@ -4951,6 +5104,11 @@ async def test_list_annotation_spec_sets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_annotation_spec_sets_async_from_dict(): + await test_list_annotation_spec_sets_async(request_type=dict) + + def test_list_annotation_spec_sets_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4961,7 +5119,7 @@ def test_list_annotation_spec_sets_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse() @@ -4990,7 +5148,7 @@ async def test_list_annotation_spec_sets_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListAnnotationSpecSetsResponse() @@ -5013,7 +5171,7 @@ def test_list_annotation_spec_sets_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse() @@ -5055,7 +5213,7 @@ async def test_list_annotation_spec_sets_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse() @@ -5100,7 +5258,7 @@ def test_list_annotation_spec_sets_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -5148,7 +5306,7 @@ def test_list_annotation_spec_sets_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -5188,7 +5346,7 @@ async def test_list_annotation_spec_sets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), + type(client.transport.list_annotation_spec_sets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -5237,7 +5395,7 @@ async def test_list_annotation_spec_sets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), + type(client.transport.list_annotation_spec_sets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -5287,7 +5445,7 @@ def test_delete_annotation_spec_set( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5309,18 +5467,21 @@ def test_delete_annotation_spec_set_from_dict(): @pytest.mark.asyncio -async def test_delete_annotation_spec_set_async(transport: str = "grpc_asyncio"): +async def test_delete_annotation_spec_set_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteAnnotationSpecSetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteAnnotationSpecSetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -5331,12 +5492,17 @@ async def test_delete_annotation_spec_set_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteAnnotationSpecSetRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_annotation_spec_set_async_from_dict(): + await test_delete_annotation_spec_set_async(request_type=dict) + + def test_delete_annotation_spec_set_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5347,7 +5513,7 @@ def test_delete_annotation_spec_set_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: call.return_value = None @@ -5376,7 +5542,7 @@ async def test_delete_annotation_spec_set_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -5397,7 +5563,7 @@ def test_delete_annotation_spec_set_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5433,7 +5599,7 @@ async def test_delete_annotation_spec_set_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5478,7 +5644,7 @@ def test_create_instruction( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -5500,18 +5666,21 @@ def test_create_instruction_from_dict(): @pytest.mark.asyncio -async def test_create_instruction_async(transport: str = "grpc_asyncio"): +async def test_create_instruction_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateInstructionRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateInstructionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5524,12 +5693,17 @@ async def test_create_instruction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateInstructionRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_create_instruction_async_from_dict(): + await test_create_instruction_async(request_type=dict) + + def test_create_instruction_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5540,7 +5714,7 @@ def test_create_instruction_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -5569,7 +5743,7 @@ async def test_create_instruction_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -5592,7 +5766,7 @@ def test_create_instruction_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -5635,7 +5809,7 @@ async def test_create_instruction_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -5688,7 +5862,7 @@ def test_get_instruction( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instruction), "__call__") as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = instruction.Instruction( name="name_value", @@ -5707,6 +5881,7 @@ def test_get_instruction( assert args[0] == data_labeling_service.GetInstructionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, instruction.Instruction) assert response.name == "name_value" @@ -5725,19 +5900,20 @@ def test_get_instruction_from_dict(): @pytest.mark.asyncio -async def test_get_instruction_async(transport: str = "grpc_asyncio"): +async def test_get_instruction_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetInstructionRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetInstructionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instruction), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( instruction.Instruction( @@ -5755,7 +5931,7 @@ async def test_get_instruction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetInstructionRequest() # Establish that the response is the type that we expect. assert isinstance(response, instruction.Instruction) @@ -5771,6 +5947,11 @@ async def test_get_instruction_async(transport: str = "grpc_asyncio"): assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_get_instruction_async_from_dict(): + await test_get_instruction_async(request_type=dict) + + def test_get_instruction_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5780,7 +5961,7 @@ def test_get_instruction_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instruction), "__call__") as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: call.return_value = instruction.Instruction() client.get_instruction(request) @@ -5807,9 +5988,7 @@ async def test_get_instruction_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instruction), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( instruction.Instruction() ) @@ -5830,7 +6009,7 @@ def test_get_instruction_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instruction), "__call__") as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = instruction.Instruction() @@ -5864,9 +6043,7 @@ async def test_get_instruction_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instruction), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = instruction.Instruction() @@ -5912,7 +6089,7 @@ def test_list_instructions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListInstructionsResponse( @@ -5928,6 +6105,7 @@ def test_list_instructions( assert args[0] == data_labeling_service.ListInstructionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstructionsPager) assert response.next_page_token == "next_page_token_value" @@ -5938,18 +6116,21 @@ def test_list_instructions_from_dict(): @pytest.mark.asyncio -async def test_list_instructions_async(transport: str = "grpc_asyncio"): +async def test_list_instructions_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListInstructionsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListInstructionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5964,7 +6145,7 @@ async def test_list_instructions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListInstructionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstructionsAsyncPager) @@ -5972,6 +6153,11 @@ async def test_list_instructions_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_instructions_async_from_dict(): + await test_list_instructions_async(request_type=dict) + + def test_list_instructions_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5982,7 +6168,7 @@ def test_list_instructions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: call.return_value = data_labeling_service.ListInstructionsResponse() @@ -6011,7 +6197,7 @@ async def test_list_instructions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListInstructionsResponse() @@ -6034,7 +6220,7 @@ def test_list_instructions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListInstructionsResponse() @@ -6076,7 +6262,7 @@ async def test_list_instructions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListInstructionsResponse() @@ -6121,7 +6307,7 @@ def test_list_instructions_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6163,7 +6349,7 @@ def test_list_instructions_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6199,7 +6385,7 @@ async def test_list_instructions_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), + type(client.transport.list_instructions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -6242,7 +6428,7 @@ async def test_list_instructions_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), + type(client.transport.list_instructions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -6287,7 +6473,7 @@ def test_delete_instruction( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -6309,18 +6495,21 @@ def test_delete_instruction_from_dict(): @pytest.mark.asyncio -async def test_delete_instruction_async(transport: str = "grpc_asyncio"): +async def test_delete_instruction_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteInstructionRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteInstructionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -6331,12 +6520,17 @@ async def test_delete_instruction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteInstructionRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_instruction_async_from_dict(): + await test_delete_instruction_async(request_type=dict) + + def test_delete_instruction_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -6347,7 +6541,7 @@ def test_delete_instruction_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: call.return_value = None @@ -6376,7 +6570,7 @@ async def test_delete_instruction_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -6397,7 +6591,7 @@ def test_delete_instruction_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -6433,7 +6627,7 @@ async def test_delete_instruction_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -6477,7 +6671,7 @@ def test_get_evaluation( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_evaluation), "__call__") as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = evaluation.Evaluation( name="name_value", @@ -6494,6 +6688,7 @@ def test_get_evaluation( assert args[0] == data_labeling_service.GetEvaluationRequest() # Establish that the response is the type that we expect. + assert isinstance(response, evaluation.Evaluation) assert response.name == "name_value" @@ -6511,19 +6706,20 @@ def test_get_evaluation_from_dict(): @pytest.mark.asyncio -async def test_get_evaluation_async(transport: str = "grpc_asyncio"): +async def test_get_evaluation_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetEvaluationRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetEvaluationRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation.Evaluation( @@ -6539,7 +6735,7 @@ async def test_get_evaluation_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetEvaluationRequest() # Establish that the response is the type that we expect. assert isinstance(response, evaluation.Evaluation) @@ -6554,6 +6750,11 @@ async def test_get_evaluation_async(transport: str = "grpc_asyncio"): assert response.evaluated_item_count == 2129 +@pytest.mark.asyncio +async def test_get_evaluation_async_from_dict(): + await test_get_evaluation_async(request_type=dict) + + def test_get_evaluation_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -6563,7 +6764,7 @@ def test_get_evaluation_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_evaluation), "__call__") as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: call.return_value = evaluation.Evaluation() client.get_evaluation(request) @@ -6590,9 +6791,7 @@ async def test_get_evaluation_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation.Evaluation() ) @@ -6613,7 +6812,7 @@ def test_get_evaluation_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_evaluation), "__call__") as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = evaluation.Evaluation() @@ -6647,9 +6846,7 @@ async def test_get_evaluation_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = evaluation.Evaluation() @@ -6695,7 +6892,7 @@ def test_search_evaluations( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchEvaluationsResponse( @@ -6711,6 +6908,7 @@ def test_search_evaluations( assert args[0] == data_labeling_service.SearchEvaluationsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.SearchEvaluationsPager) assert response.next_page_token == "next_page_token_value" @@ -6721,18 +6919,21 @@ def test_search_evaluations_from_dict(): @pytest.mark.asyncio -async def test_search_evaluations_async(transport: str = "grpc_asyncio"): +async def test_search_evaluations_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.SearchEvaluationsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.SearchEvaluationsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6747,7 +6948,7 @@ async def test_search_evaluations_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.SearchEvaluationsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.SearchEvaluationsAsyncPager) @@ -6755,6 +6956,11 @@ async def test_search_evaluations_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_search_evaluations_async_from_dict(): + await test_search_evaluations_async(request_type=dict) + + def test_search_evaluations_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -6765,7 +6971,7 @@ def test_search_evaluations_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: call.return_value = data_labeling_service.SearchEvaluationsResponse() @@ -6794,7 +7000,7 @@ async def test_search_evaluations_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.SearchEvaluationsResponse() @@ -6817,7 +7023,7 @@ def test_search_evaluations_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchEvaluationsResponse() @@ -6859,7 +7065,7 @@ async def test_search_evaluations_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchEvaluationsResponse() @@ -6904,7 +7110,7 @@ def test_search_evaluations_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6946,7 +7152,7 @@ def test_search_evaluations_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6982,7 +7188,7 @@ async def test_search_evaluations_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), + type(client.transport.search_evaluations), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7025,7 +7231,7 @@ async def test_search_evaluations_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), + type(client.transport.search_evaluations), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7071,7 +7277,7 @@ def test_search_example_comparisons( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchExampleComparisonsResponse( @@ -7087,6 +7293,7 @@ def test_search_example_comparisons( assert args[0] == data_labeling_service.SearchExampleComparisonsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.SearchExampleComparisonsPager) assert response.next_page_token == "next_page_token_value" @@ -7097,18 +7304,21 @@ def test_search_example_comparisons_from_dict(): @pytest.mark.asyncio -async def test_search_example_comparisons_async(transport: str = "grpc_asyncio"): +async def test_search_example_comparisons_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.SearchExampleComparisonsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.SearchExampleComparisonsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7123,7 +7333,7 @@ async def test_search_example_comparisons_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.SearchExampleComparisonsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.SearchExampleComparisonsAsyncPager) @@ -7131,6 +7341,11 @@ async def test_search_example_comparisons_async(transport: str = "grpc_asyncio") assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_search_example_comparisons_async_from_dict(): + await test_search_example_comparisons_async(request_type=dict) + + def test_search_example_comparisons_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -7141,7 +7356,7 @@ def test_search_example_comparisons_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: call.return_value = data_labeling_service.SearchExampleComparisonsResponse() @@ -7170,7 +7385,7 @@ async def test_search_example_comparisons_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.SearchExampleComparisonsResponse() @@ -7193,7 +7408,7 @@ def test_search_example_comparisons_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchExampleComparisonsResponse() @@ -7230,7 +7445,7 @@ async def test_search_example_comparisons_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchExampleComparisonsResponse() @@ -7270,7 +7485,7 @@ def test_search_example_comparisons_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -7324,7 +7539,7 @@ def test_search_example_comparisons_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -7366,7 +7581,7 @@ async def test_search_example_comparisons_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), + type(client.transport.search_example_comparisons), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7421,7 +7636,7 @@ async def test_search_example_comparisons_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), + type(client.transport.search_example_comparisons), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7473,7 +7688,7 @@ def test_create_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob( @@ -7495,6 +7710,7 @@ def test_create_evaluation_job( assert args[0] == data_labeling_service.CreateEvaluationJobRequest() # Establish that the response is the type that we expect. + assert isinstance(response, evaluation_job.EvaluationJob) assert response.name == "name_value" @@ -7517,18 +7733,21 @@ def test_create_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_create_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_create_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7549,7 +7768,7 @@ async def test_create_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateEvaluationJobRequest() # Establish that the response is the type that we expect. assert isinstance(response, evaluation_job.EvaluationJob) @@ -7569,6 +7788,11 @@ async def test_create_evaluation_job_async(transport: str = "grpc_asyncio"): assert response.label_missing_ground_truth is True +@pytest.mark.asyncio +async def test_create_evaluation_job_async_from_dict(): + await test_create_evaluation_job_async(request_type=dict) + + def test_create_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -7579,7 +7803,7 @@ def test_create_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: call.return_value = evaluation_job.EvaluationJob() @@ -7608,7 +7832,7 @@ async def test_create_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation_job.EvaluationJob() @@ -7631,7 +7855,7 @@ def test_create_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -7673,7 +7897,7 @@ async def test_create_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -7727,7 +7951,7 @@ def test_update_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_evaluation_job.EvaluationJob( @@ -7749,6 +7973,7 @@ def test_update_evaluation_job( assert args[0] == data_labeling_service.UpdateEvaluationJobRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcd_evaluation_job.EvaluationJob) assert response.name == "name_value" @@ -7771,18 +7996,21 @@ def test_update_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_update_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_update_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.UpdateEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.UpdateEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7803,7 +8031,7 @@ async def test_update_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.UpdateEvaluationJobRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcd_evaluation_job.EvaluationJob) @@ -7823,6 +8051,11 @@ async def test_update_evaluation_job_async(transport: str = "grpc_asyncio"): assert response.label_missing_ground_truth is True +@pytest.mark.asyncio +async def test_update_evaluation_job_async_from_dict(): + await test_update_evaluation_job_async(request_type=dict) + + def test_update_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -7833,7 +8066,7 @@ def test_update_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: call.return_value = gcd_evaluation_job.EvaluationJob() @@ -7865,7 +8098,7 @@ async def test_update_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcd_evaluation_job.EvaluationJob() @@ -7891,7 +8124,7 @@ def test_update_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_evaluation_job.EvaluationJob() @@ -7936,7 +8169,7 @@ async def test_update_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_evaluation_job.EvaluationJob() @@ -7992,7 +8225,7 @@ def test_get_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob( @@ -8014,6 +8247,7 @@ def test_get_evaluation_job( assert args[0] == data_labeling_service.GetEvaluationJobRequest() # Establish that the response is the type that we expect. + assert isinstance(response, evaluation_job.EvaluationJob) assert response.name == "name_value" @@ -8036,18 +8270,21 @@ def test_get_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_get_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_get_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8068,7 +8305,7 @@ async def test_get_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetEvaluationJobRequest() # Establish that the response is the type that we expect. assert isinstance(response, evaluation_job.EvaluationJob) @@ -8088,6 +8325,11 @@ async def test_get_evaluation_job_async(transport: str = "grpc_asyncio"): assert response.label_missing_ground_truth is True +@pytest.mark.asyncio +async def test_get_evaluation_job_async_from_dict(): + await test_get_evaluation_job_async(request_type=dict) + + def test_get_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8098,7 +8340,7 @@ def test_get_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: call.return_value = evaluation_job.EvaluationJob() @@ -8127,7 +8369,7 @@ async def test_get_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation_job.EvaluationJob() @@ -8150,7 +8392,7 @@ def test_get_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -8186,7 +8428,7 @@ async def test_get_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -8234,7 +8476,7 @@ def test_pause_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8256,18 +8498,21 @@ def test_pause_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_pause_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_pause_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.PauseEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.PauseEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8278,12 +8523,17 @@ async def test_pause_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.PauseEvaluationJobRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_pause_evaluation_job_async_from_dict(): + await test_pause_evaluation_job_async(request_type=dict) + + def test_pause_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8294,7 +8544,7 @@ def test_pause_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: call.return_value = None @@ -8323,7 +8573,7 @@ async def test_pause_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8344,7 +8594,7 @@ def test_pause_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8380,7 +8630,7 @@ async def test_pause_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8426,7 +8676,7 @@ def test_resume_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8448,18 +8698,21 @@ def test_resume_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_resume_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_resume_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ResumeEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ResumeEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8470,12 +8723,17 @@ async def test_resume_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ResumeEvaluationJobRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_resume_evaluation_job_async_from_dict(): + await test_resume_evaluation_job_async(request_type=dict) + + def test_resume_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8486,7 +8744,7 @@ def test_resume_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: call.return_value = None @@ -8515,7 +8773,7 @@ async def test_resume_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8536,7 +8794,7 @@ def test_resume_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8572,7 +8830,7 @@ async def test_resume_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8618,7 +8876,7 @@ def test_delete_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8640,18 +8898,21 @@ def test_delete_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_delete_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_delete_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8662,12 +8923,17 @@ async def test_delete_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteEvaluationJobRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_evaluation_job_async_from_dict(): + await test_delete_evaluation_job_async(request_type=dict) + + def test_delete_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8678,7 +8944,7 @@ def test_delete_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: call.return_value = None @@ -8707,7 +8973,7 @@ async def test_delete_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8728,7 +8994,7 @@ def test_delete_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8764,7 +9030,7 @@ async def test_delete_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8810,7 +9076,7 @@ def test_list_evaluation_jobs( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListEvaluationJobsResponse( @@ -8826,6 +9092,7 @@ def test_list_evaluation_jobs( assert args[0] == data_labeling_service.ListEvaluationJobsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListEvaluationJobsPager) assert response.next_page_token == "next_page_token_value" @@ -8836,18 +9103,21 @@ def test_list_evaluation_jobs_from_dict(): @pytest.mark.asyncio -async def test_list_evaluation_jobs_async(transport: str = "grpc_asyncio"): +async def test_list_evaluation_jobs_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListEvaluationJobsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListEvaluationJobsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8862,7 +9132,7 @@ async def test_list_evaluation_jobs_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListEvaluationJobsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListEvaluationJobsAsyncPager) @@ -8870,6 +9140,11 @@ async def test_list_evaluation_jobs_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_evaluation_jobs_async_from_dict(): + await test_list_evaluation_jobs_async(request_type=dict) + + def test_list_evaluation_jobs_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8880,7 +9155,7 @@ def test_list_evaluation_jobs_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: call.return_value = data_labeling_service.ListEvaluationJobsResponse() @@ -8909,7 +9184,7 @@ async def test_list_evaluation_jobs_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListEvaluationJobsResponse() @@ -8932,7 +9207,7 @@ def test_list_evaluation_jobs_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListEvaluationJobsResponse() @@ -8974,7 +9249,7 @@ async def test_list_evaluation_jobs_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListEvaluationJobsResponse() @@ -9019,7 +9294,7 @@ def test_list_evaluation_jobs_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -9065,7 +9340,7 @@ def test_list_evaluation_jobs_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -9105,7 +9380,7 @@ async def test_list_evaluation_jobs_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), + type(client.transport.list_evaluation_jobs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -9152,7 +9427,7 @@ async def test_list_evaluation_jobs_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), + type(client.transport.list_evaluation_jobs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -9224,7 +9499,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = DataLabelingServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -9242,10 +9517,25 @@ def test_transport_get_channel(): assert channel +@pytest.mark.parametrize( + "transport_class", + [ + transports.DataLabelingServiceGrpcTransport, + transports.DataLabelingServiceGrpcAsyncIOTransport, + ], +) +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) + transport_class() + adc.assert_called_once() + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.DataLabelingServiceGrpcTransport,) + assert isinstance(client.transport, transports.DataLabelingServiceGrpcTransport,) def test_data_labeling_service_base_transport_error(): @@ -9334,6 +9624,17 @@ def test_data_labeling_service_base_transport_with_credentials_file(): ) +def test_data_labeling_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( + "google.cloud.datalabeling_v1beta1.services.data_labeling_service.transports.DataLabelingServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (credentials.AnonymousCredentials(), None) + transport = transports.DataLabelingServiceTransport() + adc.assert_called_once() + + def test_data_labeling_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(auth, "default") as adc: @@ -9366,7 +9667,7 @@ def test_data_labeling_service_host_no_port(): api_endpoint="datalabeling.googleapis.com" ), ) - assert client._transport._host == "datalabeling.googleapis.com:443" + assert client.transport._host == "datalabeling.googleapis.com:443" def test_data_labeling_service_host_with_port(): @@ -9376,192 +9677,126 @@ def test_data_labeling_service_host_with_port(): api_endpoint="datalabeling.googleapis.com:8000" ), ) - assert client._transport._host == "datalabeling.googleapis.com:8000" + assert client.transport._host == "datalabeling.googleapis.com:8000" def test_data_labeling_service_grpc_transport_channel(): channel = grpc.insecure_channel("http://localhost/") - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() + # Check that channel is used if provided. transport = transports.DataLabelingServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" - assert not callback.called + assert transport._ssl_channel_credentials == None def test_data_labeling_service_grpc_asyncio_transport_channel(): channel = aio.insecure_channel("http://localhost/") - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() + # Check that channel is used if provided. transport = transports.DataLabelingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" - assert not callback.called - - -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_data_labeling_service_grpc_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred -): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() - - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - transport = transports.DataLabelingServiceGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel - - -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) -def test_data_labeling_service_grpc_asyncio_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred -): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() - - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - transport = transports.DataLabelingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] + "transport_class", + [ + transports.DataLabelingServiceGrpcTransport, + transports.DataLabelingServiceGrpcAsyncIOTransport, + ], ) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_data_labeling_service_grpc_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint +def test_data_labeling_service_transport_channel_mtls_with_client_cert_source( + transport_class, ): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - # Mock google.auth.transport.grpc.SslCredentials class. - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - mock_cred = mock.Mock() - transport = transports.DataLabelingServiceGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel", autospec=True + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] + "transport_class", + [ + transports.DataLabelingServiceGrpcTransport, + transports.DataLabelingServiceGrpcAsyncIOTransport, + ], ) -@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) -def test_data_labeling_service_grpc_asyncio_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint -): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - # Mock google.auth.transport.grpc.SslCredentials class. +def test_data_labeling_service_transport_channel_mtls_with_adc(transport_class): mock_ssl_cred = mock.Mock() with mock.patch.multiple( "google.auth.transport.grpc.SslCredentials", __init__=mock.Mock(return_value=None), ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): - mock_cred = mock.Mock() - transport = transports.DataLabelingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + with mock.patch.object( + transport_class, "create_channel", autospec=True + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + ) + assert transport.grpc_channel == mock_grpc_channel def test_data_labeling_service_grpc_lro_client(): client = DataLabelingServiceClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -9574,7 +9809,7 @@ def test_data_labeling_service_grpc_lro_async_client(): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -9583,9 +9818,86 @@ def test_data_labeling_service_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_dataset_path(): +def test_annotated_dataset_path(): project = "squid" dataset = "clam" + annotated_dataset = "whelk" + + expected = "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( + project=project, dataset=dataset, annotated_dataset=annotated_dataset, + ) + actual = DataLabelingServiceClient.annotated_dataset_path( + project, dataset, annotated_dataset + ) + assert expected == actual + + +def test_parse_annotated_dataset_path(): + expected = { + "project": "octopus", + "dataset": "oyster", + "annotated_dataset": "nudibranch", + } + path = DataLabelingServiceClient.annotated_dataset_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_annotated_dataset_path(path) + assert expected == actual + + +def test_annotation_spec_set_path(): + project = "cuttlefish" + annotation_spec_set = "mussel" + + expected = "projects/{project}/annotationSpecSets/{annotation_spec_set}".format( + project=project, annotation_spec_set=annotation_spec_set, + ) + actual = DataLabelingServiceClient.annotation_spec_set_path( + project, annotation_spec_set + ) + assert expected == actual + + +def test_parse_annotation_spec_set_path(): + expected = { + "project": "winkle", + "annotation_spec_set": "nautilus", + } + path = DataLabelingServiceClient.annotation_spec_set_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_annotation_spec_set_path(path) + assert expected == actual + + +def test_data_item_path(): + project = "scallop" + dataset = "abalone" + data_item = "squid" + + expected = "projects/{project}/datasets/{dataset}/dataItems/{data_item}".format( + project=project, dataset=dataset, data_item=data_item, + ) + actual = DataLabelingServiceClient.data_item_path(project, dataset, data_item) + assert expected == actual + + +def test_parse_data_item_path(): + expected = { + "project": "clam", + "dataset": "whelk", + "data_item": "octopus", + } + path = DataLabelingServiceClient.data_item_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_data_item_path(path) + assert expected == actual + + +def test_dataset_path(): + project = "oyster" + dataset = "nudibranch" expected = "projects/{project}/datasets/{dataset}".format( project=project, dataset=dataset, @@ -9596,8 +9908,8 @@ def test_dataset_path(): def test_parse_dataset_path(): expected = { - "project": "whelk", - "dataset": "octopus", + "project": "cuttlefish", + "dataset": "mussel", } path = DataLabelingServiceClient.dataset_path(**expected) @@ -9606,32 +9918,34 @@ def test_parse_dataset_path(): assert expected == actual -def test_instruction_path(): - project = "squid" - instruction = "clam" +def test_evaluation_path(): + project = "winkle" + dataset = "nautilus" + evaluation = "scallop" - expected = "projects/{project}/instructions/{instruction}".format( - project=project, instruction=instruction, + expected = "projects/{project}/datasets/{dataset}/evaluations/{evaluation}".format( + project=project, dataset=dataset, evaluation=evaluation, ) - actual = DataLabelingServiceClient.instruction_path(project, instruction) + actual = DataLabelingServiceClient.evaluation_path(project, dataset, evaluation) assert expected == actual -def test_parse_instruction_path(): +def test_parse_evaluation_path(): expected = { - "project": "whelk", - "instruction": "octopus", + "project": "abalone", + "dataset": "squid", + "evaluation": "clam", } - path = DataLabelingServiceClient.instruction_path(**expected) + path = DataLabelingServiceClient.evaluation_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_instruction_path(path) + actual = DataLabelingServiceClient.parse_evaluation_path(path) assert expected == actual def test_evaluation_job_path(): - project = "squid" - evaluation_job = "clam" + project = "whelk" + evaluation_job = "octopus" expected = "projects/{project}/evaluationJobs/{evaluation_job}".format( project=project, evaluation_job=evaluation_job, @@ -9642,8 +9956,8 @@ def test_evaluation_job_path(): def test_parse_evaluation_job_path(): expected = { - "project": "whelk", - "evaluation_job": "octopus", + "project": "oyster", + "evaluation_job": "nudibranch", } path = DataLabelingServiceClient.evaluation_job_path(**expected) @@ -9652,28 +9966,159 @@ def test_parse_evaluation_job_path(): assert expected == actual -def test_annotation_spec_set_path(): - project = "squid" - annotation_spec_set = "clam" +def test_example_path(): + project = "cuttlefish" + dataset = "mussel" + annotated_dataset = "winkle" + example = "nautilus" - expected = "projects/{project}/annotationSpecSets/{annotation_spec_set}".format( - project=project, annotation_spec_set=annotation_spec_set, + expected = "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}/examples/{example}".format( + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, + example=example, ) - actual = DataLabelingServiceClient.annotation_spec_set_path( - project, annotation_spec_set + actual = DataLabelingServiceClient.example_path( + project, dataset, annotated_dataset, example ) assert expected == actual -def test_parse_annotation_spec_set_path(): +def test_parse_example_path(): expected = { - "project": "whelk", - "annotation_spec_set": "octopus", + "project": "scallop", + "dataset": "abalone", + "annotated_dataset": "squid", + "example": "clam", } - path = DataLabelingServiceClient.annotation_spec_set_path(**expected) + path = DataLabelingServiceClient.example_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_annotation_spec_set_path(path) + actual = DataLabelingServiceClient.parse_example_path(path) + assert expected == actual + + +def test_instruction_path(): + project = "whelk" + instruction = "octopus" + + expected = "projects/{project}/instructions/{instruction}".format( + project=project, instruction=instruction, + ) + actual = DataLabelingServiceClient.instruction_path(project, instruction) + assert expected == actual + + +def test_parse_instruction_path(): + expected = { + "project": "oyster", + "instruction": "nudibranch", + } + path = DataLabelingServiceClient.instruction_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_instruction_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "cuttlefish" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = DataLabelingServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = DataLabelingServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "winkle" + + expected = "folders/{folder}".format(folder=folder,) + actual = DataLabelingServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = DataLabelingServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "scallop" + + expected = "organizations/{organization}".format(organization=organization,) + actual = DataLabelingServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = DataLabelingServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "squid" + + expected = "projects/{project}".format(project=project,) + actual = DataLabelingServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = DataLabelingServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "whelk" + location = "octopus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = DataLabelingServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = DataLabelingServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_location_path(path) assert expected == actual