def batch_annotate_images( self, requests, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Run image detection and annotation for a batch of images. Example: >>> from google.cloud import vision_v1p3beta1 >>> >>> client = vision_v1p3beta1.ImageAnnotatorClient() >>> >>> # TODO: Initialize `requests`: >>> requests = [] >>> >>> response = client.batch_annotate_images(requests) Args: requests (list[Union[dict, ~google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]]): Individual image annotation requests for this batch. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.vision_v1p3beta1.types.AnnotateImageRequest` retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will be retried using a default configuration. timeout (Optional[float]): The amount of time, in seconds, to wait for the request to complete. Note that if ``retry`` is specified, the timeout applies to each individual attempt. metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata that is provided to the method. Returns: A :class:`~google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse` instance. Raises: google.api_core.exceptions.GoogleAPICallError: If the request failed for any reason. google.api_core.exceptions.RetryError: If the request failed due to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. if "batch_annotate_images" not in self._inner_api_calls: self._inner_api_calls[ "batch_annotate_images"] = google.api_core.gapic_v1.method.wrap_method( self.transport.batch_annotate_images, default_retry=self._method_configs["BatchAnnotateImages"]. retry, default_timeout=self. _method_configs["BatchAnnotateImages"].timeout, client_info=self._client_info, ) request = image_annotator_pb2.BatchAnnotateImagesRequest( requests=requests) return self._inner_api_calls["batch_annotate_images"]( request, retry=retry, timeout=timeout, metadata=metadata)
def test_batch_annotate_images(self): # Setup Expected Response expected_response = {} expected_response = image_annotator_pb2.BatchAnnotateImagesResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = vision_v1p3beta1.ImageAnnotatorClient(channel=channel) # Setup Request requests = [] response = client.batch_annotate_images(requests) assert expected_response == response assert len(channel.requests) == 1 expected_request = image_annotator_pb2.BatchAnnotateImagesRequest( requests=requests) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_batch_annotate_images(self): # Setup Expected Response expected_response = {} expected_response = image_annotator_pb2.BatchAnnotateImagesResponse( **expected_response ) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = vision_v1p3beta1.ImageAnnotatorClient() response = client.batch_annotate_images() assert expected_response == response assert len(channel.requests) == 1 expected_request = image_annotator_pb2.BatchAnnotateImagesRequest() actual_request = channel.requests[0][1] assert expected_request == actual_request