123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296 |
- # Copyright (C) 2016-2018 YouCompleteMe contributors
- #
- # This file is part of YouCompleteMe.
- #
- # YouCompleteMe is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # YouCompleteMe is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
- from ycm.client.messages_request import MessagesPoll
- from ycm.tests.test_utils import ( ExtendedMock,
- MockVimBuffers,
- MockVimModule,
- Version,
- VimBuffer,
- VimMatch,
- VimSign )
- MockVimModule()
- import os
- import sys
- from hamcrest import ( assert_that, contains_exactly, empty, equal_to,
- has_entries, is_in, is_not, matches_regexp )
- from unittest.mock import call, MagicMock, patch
- from ycm import vimsupport
- from ycm.paths import _PathToPythonUsedDuringBuild
- from ycm.vimsupport import ( SetVariableValue,
- SIGN_BUFFER_ID_INITIAL_VALUE )
- from ycm.tests import ( StopServer,
- test_utils,
- UserOptions,
- WaitUntilReady,
- YouCompleteMeInstance )
- from ycm.client.base_request import _LoadExtraConfFile
- from ycm.youcompleteme import YouCompleteMe
- from ycmd.responses import ServerError
- from ycm.tests.mock_utils import ( MockAsyncServerResponseDone,
- MockAsyncServerResponseInProgress,
- MockAsyncServerResponseException )
- @YouCompleteMeInstance()
- def YouCompleteMe_YcmCoreNotImported_test( ycm ):
- assert_that( 'ycm_core', is_not( is_in( sys.modules ) ) )
- @patch( 'ycm.vimsupport.PostVimMessage' )
- 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 3.6+. "
- "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 )
- @patch( 'ycmd.utils.PathToFirstExistingExecutable', return_value = None )
- @patch( 'ycm.paths._EndsWithPython', return_value = False )
- @patch( 'ycm.vimsupport.PostVimMessage' )
- 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 3.6+. "
- "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, post_vim_message, test ):
- 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' ] )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedCore_test(
- post_vim_message, ycm ):
- message = (
- "The ycmd server SHUT DOWN \\(restart with ':YcmRestartServer'\\). "
- "Unexpected error while loading the YCM core library. Type "
- "':YcmToggleLogs ycmd_\\d+_stderr_.+.log' to check the logs." )
- RunNotifyUserIfServerCrashed( ycm, post_vim_message, {
- 'return_code': 3,
- 'expected_message': matches_regexp( message )
- } )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_NotifyUserIfServerCrashed_MissingCore_test(
- post_vim_message, ycm ):
- message = ( "The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
- "YCM core library not detected; you need to compile YCM before "
- "using it. Follow the instructions in the documentation." )
- RunNotifyUserIfServerCrashed( ycm, post_vim_message, {
- 'return_code': 4,
- 'expected_message': equal_to( message )
- } )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_NotifyUserIfServerCrashed_OutdatedCore_test(
- post_vim_message, ycm ):
- message = ( "The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
- "YCM core library too old; PLEASE RECOMPILE by running the "
- "install.py script. See the documentation for more details." )
- RunNotifyUserIfServerCrashed( ycm, post_vim_message, {
- 'return_code': 7,
- 'expected_message': equal_to( message )
- } )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedExitCode_test(
- post_vim_message, ycm ):
- message = (
- "The ycmd server SHUT DOWN \\(restart with ':YcmRestartServer'\\). "
- "Unexpected exit code 1. Type "
- "':YcmToggleLogs ycmd_\\d+_stderr_.+.log' to check the logs." )
- RunNotifyUserIfServerCrashed( ycm, post_vim_message, {
- 'return_code': 1,
- 'expected_message': matches_regexp( message )
- } )
- @YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'tempname()' ] } )
- def YouCompleteMe_DebugInfo_ServerRunning_test( ycm ):
- dir_of_script = os.path.dirname( os.path.abspath( __file__ ) )
- buf_name = os.path.join( dir_of_script, 'testdata', 'test.cpp' )
- extra_conf = os.path.join( dir_of_script, 'testdata', '.ycm_extra_conf.py' )
- _LoadExtraConfFile( extra_conf )
- current_buffer = VimBuffer( buf_name, filetype = 'cpp' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- assert_that(
- ycm.DebugInfo(),
- matches_regexp(
- 'Client logfile: .+\n'
- 'Server Python interpreter: .+\n'
- 'Server Python version: .+\n'
- 'Server has Clang support compiled in: (False|True)\n'
- 'Clang version: .+\n'
- 'Extra configuration file found and loaded\n'
- 'Extra configuration path: .*testdata[/\\\\]\\.ycm_extra_conf\\.py\n'
- '[\\w\\W]*'
- 'Server running at: .+\n'
- 'Server process ID: \\d+\n'
- 'Server logfiles:\n'
- ' .+\n'
- ' .+' )
- )
- @YouCompleteMeInstance()
- 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'
- ' .+' )
- )
- @YouCompleteMeInstance()
- def YouCompleteMe_OnVimLeave_RemoveClientLogfileByDefault_test( ycm ):
- client_logfile = ycm._client_logfile
- assert_that( os.path.isfile( client_logfile ),
- f'Logfile { client_logfile } does not exist.' )
- ycm.OnVimLeave()
- assert_that( not os.path.isfile( client_logfile ),
- f'Logfile { client_logfile } was not removed.' )
- @YouCompleteMeInstance( { 'g:ycm_keep_logfiles': 1 } )
- def YouCompleteMe_OnVimLeave_KeepClientLogfile_test( ycm ):
- client_logfile = ycm._client_logfile
- assert_that( os.path.isfile( client_logfile ),
- f'Logfile { client_logfile } does not exist.' )
- ycm.OnVimLeave()
- assert_that( os.path.isfile( client_logfile ),
- f'Logfile { client_logfile } was removed.' )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.CloseBuffersForFilename', new_callable = ExtendedMock )
- @patch( 'ycm.vimsupport.OpenFilename', new_callable = ExtendedMock )
- def YouCompleteMe_ToggleLogs_WithParameters_test( open_filename,
- close_buffers_for_filename,
- ycm ):
- logfile_buffer = VimBuffer( ycm._client_logfile )
- with MockVimBuffers( [ logfile_buffer ], [ logfile_buffer ] ):
- ycm.ToggleLogs( 90,
- 'botright vertical',
- os.path.basename( ycm._client_logfile ),
- 'nonexisting_logfile',
- os.path.basename( ycm._server_stdout ) )
- open_filename.assert_has_exact_calls( [
- call( ycm._server_stdout, { 'size': 90,
- 'watch': True,
- 'fix': True,
- 'focus': False,
- 'position': 'end',
- 'mods': 'botright vertical' } )
- ] )
- close_buffers_for_filename.assert_has_exact_calls( [
- call( ycm._client_logfile )
- ] )
- @YouCompleteMeInstance()
- # Select the second item of the list which is the ycmd stderr logfile.
- @patch( 'ycm.vimsupport.SelectFromList', return_value = 1 )
- @patch( 'ycm.vimsupport.OpenFilename', new_callable = ExtendedMock )
- def YouCompleteMe_ToggleLogs_WithoutParameters_SelectLogfileNotAlreadyOpen_test(
- open_filename, select_from_list, ycm ):
- current_buffer = VimBuffer( 'current_buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- ycm.ToggleLogs( 0, '' )
- open_filename.assert_has_exact_calls( [
- call( ycm._server_stderr, { 'size': 12,
- 'watch': True,
- 'fix': True,
- 'focus': False,
- 'position': 'end',
- 'mods': '' } )
- ] )
- @YouCompleteMeInstance()
- # Select the third item of the list which is the ycmd stdout logfile.
- @patch( 'ycm.vimsupport.SelectFromList', return_value = 2 )
- @patch( 'ycm.vimsupport.CloseBuffersForFilename', new_callable = ExtendedMock )
- def YouCompleteMe_ToggleLogs_WithoutParameters_SelectLogfileAlreadyOpen_test(
- close_buffers_for_filename, select_from_list, ycm ):
- logfile_buffer = VimBuffer( ycm._server_stdout )
- with MockVimBuffers( [ logfile_buffer ], [ logfile_buffer ] ):
- ycm.ToggleLogs( 0, '' )
- close_buffers_for_filename.assert_has_exact_calls( [
- call( ycm._server_stdout )
- ] )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.SelectFromList',
- side_effect = RuntimeError( 'Error message' ) )
- @patch( 'ycm.vimsupport.PostVimMessage' )
- def YouCompleteMe_ToggleLogs_WithoutParameters_NoSelection_test(
- post_vim_message, select_from_list, ycm ):
- current_buffer = VimBuffer( 'current_buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- ycm.ToggleLogs( 0, '' )
- assert_that(
- # Argument passed to PostVimMessage.
- post_vim_message.call_args[ 0 ][ 0 ],
- equal_to( 'Error message' )
- )
- @YouCompleteMeInstance()
- def YouCompleteMe_GetDefinedSubcommands_ListFromServer_test( ycm ):
- current_buffer = VimBuffer( 'buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.base_request._JsonFromFuture',
- return_value = [ 'SomeCommand', 'AnotherCommand' ] ):
- assert_that(
- ycm.GetDefinedSubcommands(),
- contains_exactly(
- 'SomeCommand',
- 'AnotherCommand'
- )
- )
- @YouCompleteMeInstance()
- @patch( 'ycm.client.base_request._logger', autospec = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_GetDefinedSubcommands_ErrorFromServer_test( post_vim_message,
- logger,
- ycm ):
- current_buffer = VimBuffer( 'buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.base_request._JsonFromFuture',
- side_effect = ServerError( 'Server error' ) ):
- result = ycm.GetDefinedSubcommands()
- logger.exception.assert_called_with( 'Error while handling server response' )
- post_vim_message.assert_has_exact_calls( [
- call( 'Server error', truncate = False )
- ] )
- assert_that( result, empty() )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_ShowDetailedDiagnostic_MessageFromServer_test(
- post_vim_message, ycm ):
- current_buffer = VimBuffer( 'buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.base_request._JsonFromFuture',
- return_value = { 'message': 'some_detailed_diagnostic' } ):
- ycm.ShowDetailedDiagnostic(),
- post_vim_message.assert_has_exact_calls( [
- call( 'some_detailed_diagnostic', warning = False )
- ] )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_ShowDetailedDiagnostic_Exception_test(
- post_vim_message, ycm ):
- current_buffer = VimBuffer( 'buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.base_request._JsonFromFuture',
- side_effect = RuntimeError( 'Some exception' ) ):
- ycm.ShowDetailedDiagnostic(),
- post_vim_message.assert_has_exact_calls( [
- call( 'Some exception', truncate = False )
- ] )
- @YouCompleteMeInstance()
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_ShowDiagnostics_FiletypeNotSupported_test( post_vim_message,
- ycm ):
- current_buffer = VimBuffer( 'buffer', filetype = 'not_supported' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- ycm.ShowDiagnostics()
- post_vim_message.assert_called_once_with(
- 'Native filetype completion not supported for current file, '
- 'cannot force recompilation.', warning = False )
- @YouCompleteMeInstance()
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- @patch( 'ycm.vimsupport.SetLocationListForWindow', new_callable = ExtendedMock )
- def YouCompleteMe_ShowDiagnostics_NoDiagnosticsDetected_test(
- set_location_list_for_window,
- post_vim_message,
- filetype_completer_exists,
- ycm ):
- current_buffer = VimBuffer( 'buffer', filetype = 'cpp' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.event_notification.EventNotification.Response',
- return_value = {} ):
- ycm.ShowDiagnostics()
- post_vim_message.assert_has_exact_calls( [
- call( 'Forcing compilation, this will block Vim until done.',
- warning = False ),
- call( 'Diagnostics refreshed', warning = False ),
- call( 'No warnings or errors detected.', warning = False )
- ] )
- set_location_list_for_window.assert_called_once_with( 1, [] )
- @YouCompleteMeInstance( { 'g:ycm_log_level': 'debug',
- 'g:ycm_keep_logfiles': 1,
- 'g:ycm_open_loclist_on_ycm_diags': 0 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- @patch( 'ycm.vimsupport.SetLocationListForWindow', new_callable = ExtendedMock )
- def YouCompleteMe_ShowDiagnostics_DiagnosticsFound_DoNotOpenLocationList_test(
- set_location_list_for_window,
- post_vim_message,
- filetype_completer_exists,
- ycm ):
- diagnostic = {
- 'kind': 'ERROR',
- 'text': 'error text',
- 'location': {
- 'filepath': 'buffer',
- 'line_num': 19,
- 'column_num': 2
- }
- }
- current_buffer = VimBuffer( 'buffer',
- filetype = 'cpp',
- number = 3 )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.event_notification.EventNotification.Response',
- return_value = [ diagnostic ] ):
- ycm.ShowDiagnostics()
- post_vim_message.assert_has_exact_calls( [
- call( 'Forcing compilation, this will block Vim until done.',
- warning = False ),
- call( 'Diagnostics refreshed', warning = False )
- ] )
- set_location_list_for_window.assert_called_once_with( 1, [ {
- 'bufnr': 3,
- 'lnum': 19,
- 'col': 2,
- 'text': 'error text',
- 'type': 'E',
- 'valid': 1
- } ] )
- @YouCompleteMeInstance( { 'g:ycm_open_loclist_on_ycm_diags': 1 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- @patch( 'ycm.vimsupport.SetLocationListForWindow', new_callable = ExtendedMock )
- @patch( 'ycm.vimsupport.OpenLocationList', new_callable = ExtendedMock )
- def YouCompleteMe_ShowDiagnostics_DiagnosticsFound_OpenLocationList_test(
- open_location_list,
- set_location_list_for_window,
- post_vim_message,
- filetype_completer_exists,
- ycm ):
- diagnostic = {
- 'kind': 'ERROR',
- 'text': 'error text',
- 'location': {
- 'filepath': 'buffer',
- 'line_num': 19,
- 'column_num': 2
- }
- }
- current_buffer = VimBuffer( 'buffer',
- filetype = 'cpp',
- number = 3 )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- with patch( 'ycm.client.event_notification.EventNotification.Response',
- return_value = [ diagnostic ] ):
- ycm.ShowDiagnostics()
- post_vim_message.assert_has_exact_calls( [
- call( 'Forcing compilation, this will block Vim until done.',
- warning = False ),
- call( 'Diagnostics refreshed', warning = False )
- ] )
- set_location_list_for_window.assert_called_once_with( 1, [ {
- 'bufnr': 3,
- 'lnum': 19,
- 'col': 2,
- 'text': 'error text',
- 'type': 'E',
- 'valid': 1
- } ] )
- open_location_list.assert_called_once_with( focus = True )
- def YouCompleteMe_UpdateDiagnosticInterface( ycm, post_vim_message, *args ):
- contents = """int main() {
- int x, y;
- x == y
- }"""
- # List of diagnostics returned by ycmd for the above code.
- diagnostics = [ {
- 'kind': 'ERROR',
- 'text': "expected ';' after expression",
- 'location': {
- 'filepath': 'buffer',
- 'line_num': 3,
- 'column_num': 9
- },
- # Looks strange but this is really what ycmd is returning.
- 'location_extent': {
- 'start': {
- 'filepath': '',
- 'line_num': 0,
- 'column_num': 0,
- },
- 'end': {
- 'filepath': '',
- 'line_num': 0,
- 'column_num': 0,
- }
- },
- 'ranges': [],
- 'fixit_available': True
- }, {
- 'kind': 'WARNING',
- 'text': 'equality comparison result unused',
- 'location': {
- 'filepath': 'buffer',
- 'line_num': 3,
- 'column_num': 7,
- },
- 'location_extent': {
- 'start': {
- 'filepath': 'buffer',
- 'line_num': 3,
- 'column_num': 5,
- },
- 'end': {
- 'filepath': 'buffer',
- 'line_num': 3,
- 'column_num': 7,
- }
- },
- 'ranges': [ {
- 'start': {
- 'filepath': 'buffer',
- 'line_num': 3,
- 'column_num': 3,
- },
- 'end': {
- 'filepath': 'buffer',
- 'line_num': 3,
- 'column_num': 9,
- }
- } ],
- 'fixit_available': True
- } ]
- current_buffer = VimBuffer( 'buffer',
- filetype = 'c',
- contents = contents.splitlines(),
- number = 5 )
- test_utils.VIM_SIGNS = []
- vimsupport.SIGN_ID_FOR_BUFFER.clear()
- with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 3, 1 ) ):
- with patch( 'ycm.client.event_notification.EventNotification.Response',
- return_value = diagnostics ):
- ycm.OnFileReadyToParse()
- ycm.HandleFileParseRequest( block = True )
- # The error on the current line is echoed, not the warning.
- post_vim_message.assert_called_once_with(
- "expected ';' after expression (FixIt)",
- truncate = True, warning = False )
- # Error match is added after warning matches.
- assert_that(
- test_utils.VIM_MATCHES_FOR_WINDOW,
- has_entries( {
- 1: contains_exactly(
- VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ),
- VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' ),
- VimMatch( 'YcmErrorSection', '\\%3l\\%8c' )
- )
- } )
- )
- # Only the error sign is placed.
- assert_that(
- test_utils.VIM_SIGNS,
- contains_exactly(
- VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 3, 'YcmError', 5 )
- )
- )
- # The error is not echoed again when moving the cursor along the line.
- with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 3, 2 ) ):
- post_vim_message.reset_mock()
- ycm.OnCursorMoved()
- post_vim_message.assert_not_called()
- # The error is cleared when moving the cursor to another line.
- with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 2, 2 ) ):
- post_vim_message.reset_mock()
- ycm.OnCursorMoved()
- post_vim_message.assert_called_once_with( "", warning = False )
- # The error is echoed when moving the cursor back.
- with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 3, 2 ) ):
- post_vim_message.reset_mock()
- ycm.OnCursorMoved()
- post_vim_message.assert_called_once_with(
- "expected ';' after expression (FixIt)",
- truncate = True, warning = False )
- with patch( 'ycm.client.event_notification.EventNotification.Response',
- return_value = diagnostics[ 1 : ] ):
- ycm.OnFileReadyToParse()
- ycm.HandleFileParseRequest( block = True )
- assert_that(
- test_utils.VIM_MATCHES_FOR_WINDOW,
- has_entries( {
- 1: contains_exactly(
- VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ),
- VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' )
- )
- } )
- )
- assert_that(
- test_utils.VIM_SIGNS,
- contains_exactly(
- VimSign( SIGN_BUFFER_ID_INITIAL_VALUE + 1, 3, 'YcmWarning', 5 )
- )
- )
- @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
- 'g:ycm_enable_diagnostic_signs': 1,
- 'g:ycm_enable_diagnostic_highlighting': 1 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- @patch( 'ycm.client.event_notification.EventNotification.Done',
- return_value = True )
- def YouCompleteMe_UpdateDiagnosticInterface_OldVim_test(
- request_done, post_vim_message, filetype_completer_exists, ycm ):
- YouCompleteMe_UpdateDiagnosticInterface( ycm, post_vim_message )
- @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
- 'g:ycm_enable_diagnostic_signs': 1,
- 'g:ycm_enable_diagnostic_highlighting': 1 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- @patch( 'ycm.tests.test_utils.VIM_VERSION', Version( 8, 1, 614 ) )
- @patch( 'ycm.client.event_notification.EventNotification.Done',
- return_value = True )
- def YouCompleteMe_UpdateDiagnosticInterface_NewVim_test(
- request_done, post_vim_message, filetype_completer_exists, ycm ):
- YouCompleteMe_UpdateDiagnosticInterface( ycm, post_vim_message )
- @YouCompleteMeInstance( { 'g:ycm_enable_diagnostic_highlighting': 1 } )
- def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ):
- current_buffer = VimBuffer( 'buffer',
- filetype = 'c',
- number = 5 )
- test_utils.VIM_MATCHES_FOR_WINDOW[ 1 ] = [
- VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ),
- VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' ),
- VimMatch( 'YcmErrorSection', '\\%3l\\%8c' )
- ]
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- ycm.UpdateMatches()
- assert_that( test_utils.VIM_MATCHES_FOR_WINDOW,
- has_entries( { 1: empty() } ) )
- @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
- 'g:ycm_always_populate_location_list': 1,
- 'g:ycm_show_diagnostics_ui': 0,
- 'g:ycm_enable_diagnostic_highlighting': 1 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_AsyncDiagnosticUpdate_UserDisabled_test(
- post_vim_message,
- filetype_completer_exists,
- ycm ):
- diagnostics = [
- {
- 'kind': 'ERROR',
- 'text': 'error text in current buffer',
- 'location': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1,
- },
- 'end': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1,
- }
- },
- 'ranges': []
- },
- ]
- current_buffer = VimBuffer( '/current',
- filetype = 'ycmtest',
- contents = [ 'current' ] * 10,
- number = 1 )
- buffers = [ current_buffer ]
- windows = [ current_buffer ]
- # Register each buffer internally with YCM
- for current in buffers:
- with MockVimBuffers( buffers, [ current ] ):
- ycm.OnFileReadyToParse()
- with patch( 'ycm.vimsupport.SetLocationListForWindow',
- new_callable = ExtendedMock ) as set_location_list_for_window:
- with MockVimBuffers( buffers, windows ):
- ycm.UpdateWithNewDiagnosticsForFile( '/current', diagnostics )
- post_vim_message.assert_has_exact_calls( [] )
- set_location_list_for_window.assert_has_exact_calls( [] )
- assert_that(
- test_utils.VIM_MATCHES_FOR_WINDOW,
- empty()
- )
- @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
- 'g:ycm_always_populate_location_list': 1,
- 'g:ycm_enable_diagnostic_highlighting': 1 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_AsyncDiagnosticUpdate_SingleFile_test(
- post_vim_message,
- filetype_completer_exists,
- ycm ):
- # This test simulates asynchronous diagnostic updates associated with a single
- # file (e.g. Translation Unit), but where the actual errors refer to other
- # open files and other non-open files. This is not strictly invalid, nor is it
- # completely normal, but it is supported and does work.
- # Contrast with the next test which sends the diagnostics filewise, which is
- # what the language server protocol will do.
- diagnostics = [
- {
- 'kind': 'ERROR',
- 'text': 'error text in current buffer',
- 'location': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1,
- },
- 'end': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1,
- }
- },
- 'ranges': []
- },
- {
- 'kind': 'ERROR',
- 'text': 'error text in hidden buffer',
- 'location': {
- 'filepath': '/has_diags',
- 'line_num': 4,
- 'column_num': 2
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/has_diags',
- 'line_num': 4,
- 'column_num': 2,
- },
- 'end': {
- 'filepath': '/has_diags',
- 'line_num': 4,
- 'column_num': 2,
- }
- },
- 'ranges': []
- },
- {
- 'kind': 'ERROR',
- 'text': 'error text in buffer not open in Vim',
- 'location': {
- 'filepath': '/not_open',
- 'line_num': 8,
- 'column_num': 4
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/not_open',
- 'line_num': 8,
- 'column_num': 4,
- },
- 'end': {
- 'filepath': '/not_open',
- 'line_num': 8,
- 'column_num': 4,
- }
- },
- 'ranges': []
- }
- ]
- current_buffer = VimBuffer( '/current',
- filetype = 'ycmtest',
- contents = [ 'current' ] * 10,
- number = 1 )
- no_diags_buffer = VimBuffer( '/no_diags',
- filetype = 'ycmtest',
- contents = [ 'nodiags' ] * 10,
- number = 2 )
- hidden_buffer = VimBuffer( '/has_diags',
- filetype = 'ycmtest',
- contents = [ 'hasdiags' ] * 10,
- number = 3 )
- buffers = [ current_buffer, no_diags_buffer, hidden_buffer ]
- windows = [ current_buffer, no_diags_buffer ]
- # Register each buffer internally with YCM
- for current in buffers:
- with MockVimBuffers( buffers, [ current ] ):
- ycm.OnFileReadyToParse()
- with patch( 'ycm.vimsupport.SetLocationListForWindow',
- new_callable = ExtendedMock ) as set_location_list_for_window:
- with MockVimBuffers( buffers, windows ):
- ycm.UpdateWithNewDiagnosticsForFile( '/current', diagnostics )
- # We update the diagnostic on the current cursor position
- post_vim_message.assert_has_exact_calls( [
- call( "error text in current buffer", truncate = True, warning = False ),
- ] )
- # Ensure we included all the diags though
- set_location_list_for_window.assert_has_exact_calls( [
- call( 1, [
- {
- 'lnum': 1,
- 'col': 1,
- 'bufnr': 1,
- 'valid': 1,
- 'type': 'E',
- 'text': 'error text in current buffer',
- },
- {
- 'lnum': 4,
- 'col': 2,
- 'bufnr': 3,
- 'valid': 1,
- 'type': 'E',
- 'text': 'error text in hidden buffer',
- },
- {
- 'lnum': 8,
- 'col': 4,
- 'bufnr': -1, # sic: Our mocked bufnr function actually returns -1,
- # even though YCM is passing "create if needed".
- # FIXME? we shouldn't do that, and we should pass
- # filename instead
- 'valid': 1,
- 'type': 'E',
- 'text': 'error text in buffer not open in Vim'
- }
- ] )
- ] )
- assert_that(
- test_utils.VIM_MATCHES_FOR_WINDOW,
- has_entries( {
- 1: contains_exactly(
- VimMatch( 'YcmErrorSection', '\\%1l\\%1c\\_.\\{-}\\%1l\\%1c' )
- )
- } )
- )
- @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
- 'g:ycm_always_populate_location_list': 1,
- 'g:ycm_enable_diagnostic_highlighting': 1 } )
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
- def YouCompleteMe_AsyncDiagnosticUpdate_PerFile_test(
- post_vim_message,
- filetype_completer_exists,
- ycm ):
- # This test simulates asynchronous diagnostic updates which are delivered per
- # file, including files which are open and files which are not.
- # Ordered to ensure that the calls to update are deterministic
- diagnostics_per_file = [
- ( '/current', [ {
- 'kind': 'ERROR',
- 'text': 'error text in current buffer',
- 'location': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1,
- },
- 'end': {
- 'filepath': '/current',
- 'line_num': 1,
- 'column_num': 1,
- }
- },
- 'ranges': [],
- } ] ),
- ( '/separate_window', [ {
- 'kind': 'ERROR',
- 'text': 'error text in a buffer open in a separate window',
- 'location': {
- 'filepath': '/separate_window',
- 'line_num': 3,
- 'column_num': 3
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/separate_window',
- 'line_num': 3,
- 'column_num': 3,
- },
- 'end': {
- 'filepath': '/separate_window',
- 'line_num': 3,
- 'column_num': 3,
- }
- },
- 'ranges': []
- } ] ),
- ( '/hidden', [ {
- 'kind': 'ERROR',
- 'text': 'error text in hidden buffer',
- 'location': {
- 'filepath': '/hidden',
- 'line_num': 4,
- 'column_num': 2
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/hidden',
- 'line_num': 4,
- 'column_num': 2,
- },
- 'end': {
- 'filepath': '/hidden',
- 'line_num': 4,
- 'column_num': 2,
- }
- },
- 'ranges': []
- } ] ),
- ( '/not_open', [ {
- 'kind': 'ERROR',
- 'text': 'error text in buffer not open in Vim',
- 'location': {
- 'filepath': '/not_open',
- 'line_num': 8,
- 'column_num': 4
- },
- 'location_extent': {
- 'start': {
- 'filepath': '/not_open',
- 'line_num': 8,
- 'column_num': 4,
- },
- 'end': {
- 'filepath': '/not_open',
- 'line_num': 8,
- 'column_num': 4,
- }
- },
- 'ranges': []
- } ] )
- ]
- current_buffer = VimBuffer( '/current',
- filetype = 'ycmtest',
- contents = [ 'current' ] * 10,
- number = 1 )
- no_diags_buffer = VimBuffer( '/no_diags',
- filetype = 'ycmtest',
- contents = [ 'no_diags' ] * 10,
- number = 2 )
- separate_window = VimBuffer( '/separate_window',
- filetype = 'ycmtest',
- contents = [ 'separate_window' ] * 10,
- number = 3 )
- hidden_buffer = VimBuffer( '/hidden',
- filetype = 'ycmtest',
- contents = [ 'hidden' ] * 10,
- number = 4 )
- buffers = [
- current_buffer,
- no_diags_buffer,
- separate_window,
- hidden_buffer
- ]
- windows = [
- current_buffer,
- no_diags_buffer,
- separate_window
- ]
- # Register each buffer internally with YCM
- for current in buffers:
- with MockVimBuffers( buffers, [ current ] ):
- ycm.OnFileReadyToParse()
- with patch( 'ycm.vimsupport.SetLocationListForWindow',
- new_callable = ExtendedMock ) as set_location_list_for_window:
- with MockVimBuffers( buffers, windows ):
- for filename, diagnostics in diagnostics_per_file:
- ycm.UpdateWithNewDiagnosticsForFile( filename, diagnostics )
- # We update the diagnostic on the current cursor position
- post_vim_message.assert_has_exact_calls( [
- call( "error text in current buffer", truncate = True, warning = False ),
- ] )
- # Ensure we included all the diags though
- set_location_list_for_window.assert_has_exact_calls( [
- call( 1, [
- {
- 'lnum': 1,
- 'col': 1,
- 'bufnr': 1,
- 'valid': 1,
- 'type': 'E',
- 'text': 'error text in current buffer',
- },
- ] ),
- call( 3, [
- {
- 'lnum': 3,
- 'col': 3,
- 'bufnr': 3,
- 'valid': 1,
- 'type': 'E',
- 'text': 'error text in a buffer open in a separate window',
- },
- ] )
- ] )
- # FIXME: diagnostic matches in windows other than the current one are not
- # updated.
- assert_that(
- test_utils.VIM_MATCHES_FOR_WINDOW,
- has_entries( {
- 1: contains_exactly(
- VimMatch( 'YcmErrorSection', '\\%1l\\%1c\\_.\\{-}\\%1l\\%1c' )
- )
- } )
- )
- @YouCompleteMeInstance()
- def YouCompleteMe_OnPeriodicTick_ServerNotRunning_test( ycm ):
- with patch.object( ycm, 'IsServerAlive', return_value = False ):
- assert_that( ycm.OnPeriodicTick(), equal_to( False ) )
- @YouCompleteMeInstance()
- def YouCompleteMe_OnPeriodicTick_ServerNotReady_test( ycm ):
- with patch.object( ycm, 'IsServerAlive', return_value = True ):
- with patch.object( ycm, 'IsServerReady', return_value = False ):
- assert_that( ycm.OnPeriodicTick(), equal_to( True ) )
- @YouCompleteMeInstance()
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.client.base_request._ValidateResponseObject', return_value = True )
- @patch( 'ycm.client.base_request.BaseRequest.PostDataToHandlerAsync' )
- 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 ) )
- @YouCompleteMeInstance()
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.client.base_request._ValidateResponseObject', return_value = True )
- @patch( 'ycm.client.base_request.BaseRequest.PostDataToHandlerAsync' )
- def YouCompleteMe_OnPeriodicTick_Exception_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()
- 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 )
- @YouCompleteMeInstance()
- @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
- return_value = True )
- @patch( 'ycm.client.base_request._ValidateResponseObject', return_value = True )
- @patch( 'ycm.client.base_request.BaseRequest.PostDataToHandlerAsync' )
- @patch( 'ycm.client.messages_request._HandlePollResponse' )
- def YouCompleteMe_OnPeriodicTick_ValidResponse_test( handle_poll_response,
- 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()
- post_data_to_handler_async.reset_mock()
- # Poll again, and return a _proper_ response (finally!).
- # Note, _HandlePollResponse is tested independently (for simplicity)
- with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 1, 1 ) ) as v:
- mock_response = MockAsyncServerResponseDone( [] )
- 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( True ) )
- handle_poll_response.assert_called()
- mock_future.done.assert_called()
- mock_future.result.assert_called()
- post_data_to_handler_async.assert_called() # Poll again!
- assert_that( ycm._message_poll_requests[ 'ycmtest' ] is not None )
- @YouCompleteMeInstance()
- @patch( 'ycm.client.completion_request.CompletionRequest.OnCompleteDone' )
- def YouCompleteMe_OnCompleteDone_CompletionRequest_test( on_complete_done,
- ycm ):
- current_buffer = VimBuffer( 'current_buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 1, 1 ) ):
- ycm.SendCompletionRequest()
- ycm.OnCompleteDone()
- on_complete_done.assert_called()
- @YouCompleteMeInstance()
- @patch( 'ycm.client.completion_request.CompletionRequest.OnCompleteDone' )
- def YouCompleteMe_OnCompleteDone_NoCompletionRequest_test( on_complete_done,
- ycm ):
- ycm.OnCompleteDone()
- on_complete_done.assert_not_called()
- @YouCompleteMeInstance()
- def YouCompleteMe_ShouldResendFileParseRequest_NoParseRequest_test( ycm ):
- current_buffer = VimBuffer( 'current_buffer' )
- with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
- assert_that( ycm.ShouldResendFileParseRequest(), equal_to( False ) )
|