def analyze_syntax(self, document, encoding_type, options=None): """ Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties. Example: >>> from google.cloud.gapic.language.v1 import language_service_client >>> from google.cloud.gapic.language.v1 import enums >>> from google.cloud.proto.language.v1 import language_service_pb2 >>> client = language_service_client.LanguageServiceClient() >>> document = language_service_pb2.Document() >>> encoding_type = enums.EncodingType.NONE >>> response = client.analyze_syntax(document, encoding_type) Args: document (:class:`google.cloud.proto.language.v1.language_service_pb2.Document`): Input document. encoding_type (enum :class:`google.cloud.gapic.language.v1.enums.EncodingType`): The encoding type used by the API to calculate offsets. options (:class:`google.gax.CallOptions`): Overrides the default settings for this call, e.g, timeout, retries etc. Returns: A :class:`google.cloud.proto.language.v1.language_service_pb2.AnalyzeSyntaxResponse` instance. Raises: :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ # Create the request object. request = language_service_pb2.AnalyzeSyntaxRequest( document=document, encoding_type=encoding_type) return self._analyze_syntax(request, options)
def test_analyze_syntax(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = language_service_client.LanguageServiceClient() # Mock request document = language_service_pb2.Document() # Mock response language = 'language-1613589672' expected_response = language_service_pb2.AnalyzeSyntaxResponse( language=language) grpc_stub.AnalyzeSyntax.return_value = expected_response response = client.analyze_syntax(document) self.assertEqual(expected_response, response) grpc_stub.AnalyzeSyntax.assert_called_once() args, kwargs = grpc_stub.AnalyzeSyntax.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = language_service_pb2.AnalyzeSyntaxRequest( document=document) self.assertEqual(expected_request, actual_request)