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)
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 RunNotifyUserIfServerCrashed(ycm, test, post_vim_message): StopServer(ycm) ycm._logger = MagicMock(autospec=True) ycm._server_popen = MagicMock(autospec=True) ycm._server_popen.poll.return_value = test['return_code'] ycm.OnFileReadyToParse() assert_that(ycm._logger.error.call_args[0][0], test['expected_message']) assert_that(post_vim_message.call_args[0][0], test['expected_message'])
def YouCompleteMe_DebugInfo_ServerNotRunning_test(ycm): StopServer(ycm) current_buffer = VimBuffer('current_buffer') with MockVimBuffers([current_buffer], current_buffer): assert_that( ycm.DebugInfo(), matches_regexp('Client logfile: .+\n' 'Server errored, no debug info from server\n' 'Server running at: .+\n' 'Server process ID: \d+\n' 'Server logfiles:\n' ' .+\n' ' .+'))
def RunNotifyUserIfServerCrashed(ycm, test, post_vim_message): StopServer(ycm) ycm._logger = MagicMock(autospec=True) ycm._server_popen = MagicMock(autospec=True) ycm._server_popen.poll.return_value = test['return_code'] ycm._NotifyUserIfServerCrashed() assert_that(ycm._logger.method_calls, has_length(len(test['expected_logs']))) ycm._logger.error.assert_has_calls( [call(log) for log in test['expected_logs']]) post_vim_message.assert_has_exact_calls( [call(test['expected_vim_message'])])