示例#1
0
    def test_batch_annotate_files(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = image_annotator_pb2.BatchAnnotateFilesResponse(
            **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_v1p4beta1.ImageAnnotatorClient()

        # Setup Request
        requests = []

        response = client.batch_annotate_files(requests)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = image_annotator_pb2.BatchAnnotateFilesRequest(
            requests=requests)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def batch_annotate_files(
        self,
        requests,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Service that performs image detection and annotation for a batch of files.
        Now only "application/pdf", "image/tiff" and "image/gif" are supported.

        This service will extract at most 5 (customers can specify which 5 in
        AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each
        file provided and perform detection and annotation for each image
        extracted.

        Example:
            >>> from google.cloud import vision_v1p4beta1
            >>>
            >>> client = vision_v1p4beta1.ImageAnnotatorClient()
            >>>
            >>> # TODO: Initialize `requests`:
            >>> requests = []
            >>>
            >>> response = client.batch_annotate_files(requests)

        Args:
            requests (list[Union[dict, ~google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]]): Required. The list of file annotation requests. Right now we support only
                one AnnotateFileRequest in BatchAnnotateFilesRequest.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.vision_v1p4beta1.types.AnnotateFileRequest`
            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_v1p4beta1.types.BatchAnnotateFilesResponse` 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_files" not in self._inner_api_calls:
            self._inner_api_calls[
                "batch_annotate_files"
            ] = google.api_core.gapic_v1.method.wrap_method(
                self.transport.batch_annotate_files,
                default_retry=self._method_configs["BatchAnnotateFiles"].retry,
                default_timeout=self._method_configs["BatchAnnotateFiles"].timeout,
                client_info=self._client_info,
            )

        request = image_annotator_pb2.BatchAnnotateFilesRequest(requests=requests)
        return self._inner_api_calls["batch_annotate_files"](
            request, retry=retry, timeout=timeout, metadata=metadata
        )