def YouCompleteMe_OnPeriodicTick_DontRetry_test(post_data_to_handler_async, validate_response_object, filetype_completer_exists, ycm): 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() assert ycm._message_poll_requests['ycmtest'] is not None post_data_to_handler_async.reset_mock() # OK that sent the request, now poll to check if it is complete (say it is # not) with MockVimBuffers([current_buffer], [current_buffer], (1, 1)) as v: mock_response = MockAsyncServerResponseInProgress() 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 poll_again = ycm.OnPeriodicTick() mock_future.done.assert_called() mock_future.result.assert_not_called() assert_that(poll_again, equal_to(True)) # Poll again, but return a response (telling us to stop polling) with MockVimBuffers([current_buffer], [current_buffer], (1, 1)) as v: mock_response = MockAsyncServerResponseDone(False) 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 poll_again = ycm.OnPeriodicTick() 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) assert_that(poll_again, equal_to(False))
def YouCompleteMe_OnPeriodicTick_DontRetry_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() assert ycm._message_poll_request is not None post_data_to_handler_async.reset_mock() # OK that sent the request, now poll to check if it is complete (say it is # not) with patch.object( ycm._message_poll_request, '_response_future', new = MockAsyncServerResponseInProgress() ) as mock_future: poll_again = ycm.OnPeriodicTick() mock_future.done.assert_called() mock_future.result.assert_not_called() assert_that( poll_again, equal_to( True ) ) # Poll again, but return a response (telling us to stop polling) with patch.object( ycm._message_poll_request, '_response_future', new = MockAsyncServerResponseDone( False ) ) \ as mock_future: poll_again = ycm.OnPeriodicTick() 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 ) assert_that( poll_again, equal_to( False ) )