Ejemplo n.º 1
0
def YouCompleteMe_OnPeriodicTick_Exception_test( ycm,
                                                 post_data_to_handler_async,
                                                 *args ):

  current_buffer = VimBuffer( '/current',
                              filetype = 'ycmtest',
                              number = 1,
                              window = 10 )
  buffers = [ current_buffer ]

  # Create the request and make the first poll; we expect no response
  with MockVimBuffers( buffers, current_buffer, ( 1, 1 ) ):
    assert_that( ycm.OnPeriodicTick(), equal_to( True ) )
    post_data_to_handler_async.assert_called()

  post_data_to_handler_async.reset_mock()

  # Poll again, but return an exception response
  mock_response = MockAsyncServerResponseException( RuntimeError( 'test' ) )
  with patch.object( ycm._message_poll_request,
                     '_response_future',
                     new = mock_response ) as mock_future:
    assert_that( ycm.OnPeriodicTick(), equal_to( False ) )
    mock_future.done.assert_called()
    mock_future.result.assert_called()
    post_data_to_handler_async.assert_not_called()
    # We reset and don't poll anymore
    assert_that( ycm._message_poll_request is None )
Ejemplo n.º 2
0
def YouCompleteMe_OnPeriodicTick_Exception_test(ycm,
                                                post_data_to_handler_async,
                                                *args):

    current_buffer = VimBuffer('/current', filetype='ycmtest', number=1)

    # Create the request and make the first poll; we expect no response
    with MockVimBuffers([current_buffer], [current_buffer], (1, 1)):
        assert_that(ycm.OnPeriodicTick(), equal_to(True))
        post_data_to_handler_async.assert_called()

    post_data_to_handler_async.reset_mock()

    # Poll again, but return an exception response
    with MockVimBuffers([current_buffer], [current_buffer], (1, 1)) as v:
        mock_response = MockAsyncServerResponseException(RuntimeError('test'))
        with patch.dict(ycm._message_poll_requests, {}):
            ycm._message_poll_requests['ycmtest'] = MessagesPoll(
                v.current.buffer)
            ycm._message_poll_requests[
                'ycmtest']._response_future = mock_response
            mock_future = ycm._message_poll_requests[
                'ycmtest']._response_future
            assert_that(ycm.OnPeriodicTick(), equal_to(False))
            mock_future.done.assert_called()
            mock_future.result.assert_called()
            post_data_to_handler_async.assert_not_called()
            # We reset and don't poll anymore
            assert_that(ycm._message_poll_requests['ycmtest'] is None)