def YouCompleteMe_NoPythonInterpreterFound_test(post_vim_message, *args): with UserOptions({}): try: with patch('ycmd.utils.ReadFile', side_effect=IOError): ycm = YouCompleteMe() assert_that(ycm.IsServerAlive(), equal_to(False)) post_vim_message.assert_called_once_with( "Unable to start the ycmd server. Cannot find Python 2.7 or 3.4+. " "Set the 'g:ycm_server_python_interpreter' option to a Python " "interpreter path. " "Correct the error then restart the server with ':YcmRestartServer'." ) post_vim_message.reset_mock() SetVariableValue('g:ycm_server_python_interpreter', _PathToPythonUsedDuringBuild()) ycm.RestartServer() assert_that(ycm.IsServerAlive(), equal_to(True)) post_vim_message.assert_called_once_with( 'Restarting ycmd server...') finally: WaitUntilReady() StopServer(ycm)
def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test( capture_vim_command, ycm ): current_buffer = VimBuffer( name = 'current_buffer', filetype = 'some_filetype' ) with patch( 'ycm.client.event_notification.EventNotification.' 'PostDataToHandlerAsync' ) as post_data_to_handler_async: with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): ycm.OnFileReadyToParse() assert_that( # Positional arguments passed to PostDataToHandlerAsync. post_data_to_handler_async.call_args[ 0 ], contains_exactly( has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ), 'event_notification' ) ) # Send again the syntax keywords after restarting the server. ycm.RestartServer() WaitUntilReady() ycm.OnFileReadyToParse() assert_that( # Positional arguments passed to PostDataToHandlerAsync. post_data_to_handler_async.call_args[ 0 ], contains_exactly( has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ), 'event_notification' ) )
def YouCompleteMe_InvalidPythonInterpreterPath_test(post_vim_message): with UserOptions( {'g:ycm_server_python_interpreter': '/invalid/python/path'}): try: ycm = YouCompleteMe() assert_that(ycm.IsServerAlive(), equal_to(False)) post_vim_message.assert_called_once_with( "Unable to start the ycmd server. " "Path in 'g:ycm_server_python_interpreter' option does not point " "to a valid Python 2.7 or 3.4+. " "Correct the error then restart the server with ':YcmRestartServer'." ) post_vim_message.reset_mock() SetVariableValue('g:ycm_server_python_interpreter', _PathToPythonUsedDuringBuild()) ycm.RestartServer() assert_that(ycm.IsServerAlive(), equal_to(True)) post_vim_message.assert_called_once_with( 'Restarting ycmd server...') finally: WaitUntilReady() StopServer(ycm)