def test_streaming_recognize(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = cloud_speech_pb2.StreamingRecognizeResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[iter([expected_response])])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = speech_v1.SpeechClient()

        # Setup Request
        request = {}
        request = cloud_speech_pb2.StreamingRecognizeRequest(**request)
        requests = [request]

        response = client.streaming_recognize(requests)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        actual_requests = channel.requests[0][1]
        assert len(actual_requests) == 1
        actual_request = list(actual_requests)[0]
        assert request == actual_request
예제 #2
0
    def test_streaming_recognize(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = cloud_speech_pb2.StreamingRecognizeResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[iter([expected_response])])
        client = speech_v1.SpeechClient(channel=channel)

        # Setup Request
        request = {}
        request = cloud_speech_pb2.StreamingRecognizeRequest(**request)
        requests = [request]

        response = client.streaming_recognize(requests)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        actual_requests = channel.requests[0][1]
        assert len(actual_requests) == 1
        actual_request = list(actual_requests)[0]
        assert request == actual_request
예제 #3
0
    def test_streaming_recognize_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = speech_v1.SpeechClient(channel=channel)

        # Setup request
        request = {}

        request = cloud_speech_pb2.StreamingRecognizeRequest(**request)
        requests = [request]

        with pytest.raises(CustomException):
            client.streaming_recognize(requests)
    def test_streaming_recognize_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = speech_v1.SpeechClient()

        # Setup request
        request = {}

        request = cloud_speech_pb2.StreamingRecognizeRequest(**request)
        requests = [request]

        with pytest.raises(CustomException):
            client.streaming_recognize(requests)