|
@@ -25,13 +25,15 @@ from future import standard_library
|
|
|
standard_library.install_aliases()
|
|
|
from builtins import * # noqa
|
|
|
|
|
|
-from ycm.tests.test_utils import ( CurrentWorkingDirectory, MockVimModule,
|
|
|
- MockVimBuffers, VimBuffer )
|
|
|
+from ycm.tests.test_utils import ( CurrentWorkingDirectory, ExtendedMock,
|
|
|
+ MockVimModule, MockVimBuffers, VimBuffer )
|
|
|
MockVimModule()
|
|
|
|
|
|
-from hamcrest import assert_that, empty, has_entries
|
|
|
+from hamcrest import assert_that, contains, empty, has_entries
|
|
|
+from mock import call, patch
|
|
|
|
|
|
from ycm.tests import PathToTestFile, YouCompleteMeInstance
|
|
|
+from ycmd.responses import ServerError
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
|
@@ -40,7 +42,7 @@ def CreateCompletionRequest_UnicodeWorkingDirectory_test( ycm ):
|
|
|
current_buffer = VimBuffer( PathToTestFile( 'uni¢𐍈d€', 'current_buffer' ) )
|
|
|
|
|
|
with CurrentWorkingDirectory( unicode_dir ):
|
|
|
- with MockVimBuffers( [ current_buffer ], current_buffer, ( 5, 2 ) ):
|
|
|
+ with MockVimBuffers( [ current_buffer ], current_buffer ):
|
|
|
ycm.CreateCompletionRequest(),
|
|
|
|
|
|
results = ycm.GetCompletions()
|
|
@@ -52,3 +54,86 @@ def CreateCompletionRequest_UnicodeWorkingDirectory_test( ycm ):
|
|
|
'refresh': 'always'
|
|
|
} )
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+@YouCompleteMeInstance()
|
|
|
+@patch( 'ycm.client.base_request._logger', autospec = True )
|
|
|
+@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
|
|
+def CreateCompletionRequest_ResponseContainingError_test( ycm,
|
|
|
+ post_vim_message,
|
|
|
+ logger ):
|
|
|
+ current_buffer = VimBuffer( 'buffer' )
|
|
|
+ with MockVimBuffers( [ current_buffer ], current_buffer ):
|
|
|
+ ycm.CreateCompletionRequest(),
|
|
|
+
|
|
|
+ response = {
|
|
|
+ 'completions': [ {
|
|
|
+ 'insertion_text': 'insertion_text',
|
|
|
+ 'menu_text': 'menu_text',
|
|
|
+ 'extra_menu_info': 'extra_menu_info',
|
|
|
+ 'detailed_info': 'detailed_info',
|
|
|
+ 'kind': 'kind',
|
|
|
+ 'extra_data': {
|
|
|
+ 'doc_string': 'doc_string'
|
|
|
+ }
|
|
|
+ } ],
|
|
|
+ 'completion_start_column': 3,
|
|
|
+ 'errors': [ {
|
|
|
+ 'exception': {
|
|
|
+ 'TYPE': 'Exception'
|
|
|
+ },
|
|
|
+ 'message': 'message',
|
|
|
+ 'traceback': 'traceback'
|
|
|
+ } ]
|
|
|
+ }
|
|
|
+
|
|
|
+ with patch( 'ycm.client.completion_request.JsonFromFuture',
|
|
|
+ return_value = response ):
|
|
|
+ results = ycm.GetCompletions()
|
|
|
+
|
|
|
+ logger.exception.assert_called_with( 'Error while handling server response' )
|
|
|
+ post_vim_message.assert_has_exact_calls( [
|
|
|
+ call( 'Exception: message', truncate = True )
|
|
|
+ ] )
|
|
|
+ assert_that(
|
|
|
+ results,
|
|
|
+ has_entries( {
|
|
|
+ 'words': contains( has_entries( {
|
|
|
+ 'word': 'insertion_text',
|
|
|
+ 'abbr': 'menu_text',
|
|
|
+ 'menu': 'extra_menu_info',
|
|
|
+ 'info': 'detailed_info\ndoc_string',
|
|
|
+ 'kind': 'k',
|
|
|
+ 'dup': 1,
|
|
|
+ 'empty': 1
|
|
|
+ } ) ),
|
|
|
+ 'refresh': 'always'
|
|
|
+ } )
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+@YouCompleteMeInstance()
|
|
|
+@patch( 'ycm.client.base_request._logger', autospec = True )
|
|
|
+@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
|
|
+def CreateCompletionRequest_ErrorFromServer_test( ycm,
|
|
|
+ post_vim_message,
|
|
|
+ logger ):
|
|
|
+ current_buffer = VimBuffer( 'buffer' )
|
|
|
+ with MockVimBuffers( [ current_buffer ], current_buffer ):
|
|
|
+ ycm.CreateCompletionRequest(),
|
|
|
+
|
|
|
+ with patch( 'ycm.client.completion_request.JsonFromFuture',
|
|
|
+ side_effect = ServerError( 'Server error' ) ):
|
|
|
+ results = ycm.GetCompletions()
|
|
|
+
|
|
|
+ logger.exception.assert_called_with( 'Error while handling server response' )
|
|
|
+ post_vim_message.assert_has_exact_calls( [
|
|
|
+ call( 'Server error', truncate = True )
|
|
|
+ ] )
|
|
|
+ assert_that(
|
|
|
+ results,
|
|
|
+ has_entries( {
|
|
|
+ 'words': empty(),
|
|
|
+ 'refresh': 'always'
|
|
|
+ } )
|
|
|
+ )
|