示例#1
0
    def test_batch_annotate_images(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = image_annotator_client.ImageAnnotatorClient()

        # Mock request
        requests = []

        # Mock response
        expected_response = image_annotator_pb2.BatchAnnotateImagesResponse()
        grpc_stub.BatchAnnotateImages.return_value = expected_response

        response = client.batch_annotate_images(requests)
        self.assertEqual(expected_response, response)

        grpc_stub.BatchAnnotateImages.assert_called_once()
        args, kwargs = grpc_stub.BatchAnnotateImages.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = image_annotator_pb2.BatchAnnotateImagesRequest(
            requests=requests)
        self.assertEqual(expected_request, actual_request)
示例#2
0
    def test_batch_annotate_images_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = image_annotator_client.ImageAnnotatorClient()

        # Mock request
        requests = []

        # Mock exception response
        grpc_stub.BatchAnnotateImages.side_effect = CustomException()

        self.assertRaises(errors.GaxError, client.batch_annotate_images,
                          requests)
示例#3
0
 def __init__(self, client=None):
     self._client = client
     self._annotator_client = image_annotator_client.ImageAnnotatorClient(
         credentials=client._credentials,
         lib_name='gccl',
         lib_version=__version__)
示例#4
0
 def __init__(self, client=None):
     self._client = client
     self._annotator_client = image_annotator_client.ImageAnnotatorClient()