Auto merge of #2386 - micbou:refactor-tests, r=Valloric

[READY] Refactor tests using a YouCompleteMe instance

This PR adds a decorator function, similar to the `IsolatedYcmd` and `SharedYcmd` decorators from ycmd, that passes a YouCompleteMe object to tests. Its options can be customized with the parameter of the decorator. I need this to write new tests.

There is one thing annoying with this change is that Vim does not highlight a decorator function with no character between the parentheses so `@YouCompleteMeInstance()` will not be highlighted. I've contacted the maintainer of the Python syntax file about this bug. Anyway, that's not a good reason to not make this change.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2386)
<!-- Reviewable:end -->
This commit is contained in:
Homu 2016-10-15 10:30:12 +09:00
commit 5cf5f04dd7
6 changed files with 1262 additions and 1284 deletions

View File

@ -0,0 +1,105 @@
# Copyright (C) 2016 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 __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()
import functools
import requests
import time
from ycm.client.base_request import BaseRequest
from ycm.youcompleteme import YouCompleteMe
from ycmd import user_options_store
from ycmd.utils import WaitUntilProcessIsTerminated
# The default options which are only relevant to the client, not the server and
# thus are not part of default_options.json, but are required for a working
# YouCompleteMe object.
DEFAULT_CLIENT_OPTIONS = {
'server_log_level': 'info',
'extra_conf_vim_data': [],
'show_diagnostics_ui': 1,
'enable_diagnostic_signs': 1,
'enable_diagnostic_highlighting': 0,
'always_populate_location_list': 0,
}
def _MakeUserOptions( custom_options = {} ):
options = dict( user_options_store.DefaultOptions() )
options.update( DEFAULT_CLIENT_OPTIONS )
options.update( custom_options )
return options
def _IsReady():
return BaseRequest.GetDataFromHandler( 'ready' )
def _WaitUntilReady( timeout = 5 ):
expiration = time.time() + timeout
while True:
try:
if time.time() > expiration:
raise RuntimeError( 'Waited for the server to be ready '
'for {0} seconds, aborting.'.format( timeout ) )
if _IsReady():
return
except requests.exceptions.ConnectionError:
pass
finally:
time.sleep( 0.1 )
def YouCompleteMeInstance( custom_options = {} ):
"""Defines a decorator function for tests that passes a unique YouCompleteMe
instance as a parameter. This instance is initialized with the default options
`DEFAULT_CLIENT_OPTIONS`. Use the optional parameter |custom_options| to give
additional options and/or override the already existing ones.
Do NOT attach it to test generators but directly to the yielded tests.
Example usage:
from ycm.tests import YouCompleteMeInstance
@YouCompleteMeInstance( { 'server_log_level': 'debug',
'server_keep_logfiles': 1 } )
def Debug_test( ycm ):
...
"""
def Decorator( test ):
@functools.wraps( test )
def Wrapper( *args, **kwargs ):
ycm = YouCompleteMe( _MakeUserOptions( custom_options ) )
_WaitUntilReady()
try:
test( ycm, *args, **kwargs )
finally:
ycm.OnVimLeave()
WaitUntilProcessIsTerminated( ycm._server_popen )
return Wrapper
return Decorator

View File

@ -1,4 +1,4 @@
# Copyright (C) 2015 YouCompleteMe contributors
# Copyright (C) 2015-2016 YouCompleteMe contributors
#
# This file is part of YouCompleteMe.
#
@ -29,7 +29,7 @@ MockVimModule()
import contextlib
import os
from ycm.tests.server_test import Server_test
from ycm.tests import YouCompleteMeInstance
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
UnknownExtraConf, ServerError )
@ -110,10 +110,11 @@ def MockEventNotification( response_method, native_filetype_completer = True ):
yield
class EventNotification_test( Server_test ):
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
def FileReadyToParse_NonDiagnostic_Error_test( self, post_vim_message ):
@YouCompleteMeInstance()
def EventNotification_FileReadyToParse_NonDiagnostic_Error_test(
ycm, post_vim_message ):
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
# raises an exception handling FileReadyToParse event notification
@ -124,9 +125,9 @@ class EventNotification_test( Server_test ):
with MockArbitraryBuffer( 'javascript' ):
with MockEventNotification( ErrorResponse ):
self._server_state.OnFileReadyToParse()
assert self._server_state.FileParseRequestReady()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
# The first call raises a warning
post_vim_message.assert_has_exact_calls( [
@ -134,15 +135,15 @@ class EventNotification_test( Server_test ):
] )
# Subsequent calls don't re-raise the warning
self._server_state.HandleFileParseRequest()
ycm.HandleFileParseRequest()
post_vim_message.assert_has_exact_calls( [
call( ERROR_TEXT, truncate = False )
] )
# But it does if a subsequent event raises again
self._server_state.OnFileReadyToParse()
assert self._server_state.FileParseRequestReady()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
post_vim_message.assert_has_exact_calls( [
call( ERROR_TEXT, truncate = False ),
call( ERROR_TEXT, truncate = False )
@ -150,11 +151,14 @@ class EventNotification_test( Server_test ):
@patch( 'vim.command' )
def FileReadyToParse_NonDiagnostic_Error_NonNative_test( self, vim_command ):
@YouCompleteMeInstance()
def EventNotification_FileReadyToParse_NonDiagnostic_Error_NonNative_test(
ycm, vim_command ):
with MockArbitraryBuffer( 'javascript' ):
with MockEventNotification( None, False ):
self._server_state.OnFileReadyToParse()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ycm.HandleFileParseRequest()
vim_command.assert_not_called()
@ -162,11 +166,9 @@ class EventNotification_test( Server_test ):
new_callable = ExtendedMock )
@patch( 'ycm.client.event_notification._IgnoreExtraConfFile',
new_callable = ExtendedMock )
def FileReadyToParse_NonDiagnostic_ConfirmExtraConf_test(
self,
ignore_extra_conf,
load_extra_conf,
*args ):
@YouCompleteMeInstance()
def EventNotification_FileReadyToParse_NonDiagnostic_ConfirmExtraConf_test(
ycm, ignore_extra_conf, load_extra_conf ):
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
@ -186,9 +188,9 @@ class EventNotification_test( Server_test ):
with patch( 'ycm.vimsupport.PresentDialog',
return_value = 0,
new_callable = ExtendedMock ) as present_dialog:
self._server_state.OnFileReadyToParse()
assert self._server_state.FileParseRequestReady()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
present_dialog.assert_has_exact_calls( [
PresentDialog_Confirm_Call( MESSAGE ),
@ -198,7 +200,7 @@ class EventNotification_test( Server_test ):
] )
# Subsequent calls don't re-raise the warning
self._server_state.HandleFileParseRequest()
ycm.HandleFileParseRequest()
present_dialog.assert_has_exact_calls( [
PresentDialog_Confirm_Call( MESSAGE )
@ -208,9 +210,9 @@ class EventNotification_test( Server_test ):
] )
# But it does if a subsequent event raises again
self._server_state.OnFileReadyToParse()
assert self._server_state.FileParseRequestReady()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
present_dialog.assert_has_exact_calls( [
PresentDialog_Confirm_Call( MESSAGE ),
@ -225,9 +227,9 @@ class EventNotification_test( Server_test ):
with patch( 'ycm.vimsupport.PresentDialog',
return_value = 1,
new_callable = ExtendedMock ) as present_dialog:
self._server_state.OnFileReadyToParse()
assert self._server_state.FileParseRequestReady()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
present_dialog.assert_has_exact_calls( [
PresentDialog_Confirm_Call( MESSAGE ),
@ -237,7 +239,7 @@ class EventNotification_test( Server_test ):
] )
# Subsequent calls don't re-raise the warning
self._server_state.HandleFileParseRequest()
ycm.HandleFileParseRequest()
present_dialog.assert_has_exact_calls( [
PresentDialog_Confirm_Call( MESSAGE )
@ -247,9 +249,9 @@ class EventNotification_test( Server_test ):
] )
# But it does if a subsequent event raises again
self._server_state.OnFileReadyToParse()
assert self._server_state.FileParseRequestReady()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
present_dialog.assert_has_exact_calls( [
PresentDialog_Confirm_Call( MESSAGE ),
@ -261,14 +263,15 @@ class EventNotification_test( Server_test ):
] )
def FileReadyToParse_Diagnostic_Error_Native_test( self ):
self._Check_FileReadyToParse_Diagnostic_Error()
self._Check_FileReadyToParse_Diagnostic_Warning()
self._Check_FileReadyToParse_Diagnostic_Clean()
@YouCompleteMeInstance()
def EventNotification_FileReadyToParse_Diagnostic_Error_Native_test( ycm ):
_Check_FileReadyToParse_Diagnostic_Error( ycm )
_Check_FileReadyToParse_Diagnostic_Warning( ycm )
_Check_FileReadyToParse_Diagnostic_Clean( ycm )
@patch( 'vim.command' )
def _Check_FileReadyToParse_Diagnostic_Error( self, vim_command ):
def _Check_FileReadyToParse_Diagnostic_Error( ycm, vim_command ):
# Tests Vim sign placement and error/warning count python API
# when one error is returned.
def DiagnosticResponse( *args ):
@ -280,27 +283,27 @@ class EventNotification_test( Server_test ):
with MockArbitraryBuffer( 'cpp' ):
with MockEventNotification( DiagnosticResponse ):
self._server_state.OnFileReadyToParse()
ok_( self._server_state.FileParseRequestReady() )
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
vim_command.assert_has_calls( [
PlaceSign_Call( 1, 1, 1, True )
] )
eq_( self._server_state.GetErrorCount(), 1 )
eq_( self._server_state.GetWarningCount(), 0 )
eq_( ycm.GetErrorCount(), 1 )
eq_( ycm.GetWarningCount(), 0 )
# Consequent calls to HandleFileParseRequest shouldn't mess with
# existing diagnostics, when there is no new parse request.
vim_command.reset_mock()
ok_( not self._server_state.FileParseRequestReady() )
self._server_state.HandleFileParseRequest()
ok_( not ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
vim_command.assert_not_called()
eq_( self._server_state.GetErrorCount(), 1 )
eq_( self._server_state.GetWarningCount(), 0 )
eq_( ycm.GetErrorCount(), 1 )
eq_( ycm.GetWarningCount(), 0 )
@patch( 'vim.command' )
def _Check_FileReadyToParse_Diagnostic_Warning( self, vim_command ):
def _Check_FileReadyToParse_Diagnostic_Warning( ycm, vim_command ):
# Tests Vim sign placement/unplacement and error/warning count python API
# when one warning is returned.
# Should be called after _Check_FileReadyToParse_Diagnostic_Error
@ -313,75 +316,76 @@ class EventNotification_test( Server_test ):
with MockArbitraryBuffer( 'cpp' ):
with MockEventNotification( DiagnosticResponse ):
self._server_state.OnFileReadyToParse()
ok_( self._server_state.FileParseRequestReady() )
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ok_( ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
vim_command.assert_has_calls( [
PlaceSign_Call( 2, 2, 1, False ),
UnplaceSign_Call( 1, 1 )
] )
eq_( self._server_state.GetErrorCount(), 0 )
eq_( self._server_state.GetWarningCount(), 1 )
eq_( ycm.GetErrorCount(), 0 )
eq_( ycm.GetWarningCount(), 1 )
# Consequent calls to HandleFileParseRequest shouldn't mess with
# existing diagnostics, when there is no new parse request.
vim_command.reset_mock()
ok_( not self._server_state.FileParseRequestReady() )
self._server_state.HandleFileParseRequest()
ok_( not ycm.FileParseRequestReady() )
ycm.HandleFileParseRequest()
vim_command.assert_not_called()
eq_( self._server_state.GetErrorCount(), 0 )
eq_( self._server_state.GetWarningCount(), 1 )
eq_( ycm.GetErrorCount(), 0 )
eq_( ycm.GetWarningCount(), 1 )
@patch( 'vim.command' )
def _Check_FileReadyToParse_Diagnostic_Clean( self, vim_command ):
def _Check_FileReadyToParse_Diagnostic_Clean( ycm, vim_command ):
# Tests Vim sign unplacement and error/warning count python API
# when there are no errors/warnings left.
# Should be called after _Check_FileReadyToParse_Diagnostic_Warning
with MockArbitraryBuffer( 'cpp' ):
with MockEventNotification( MagicMock( return_value = [] ) ):
self._server_state.OnFileReadyToParse()
self._server_state.HandleFileParseRequest()
ycm.OnFileReadyToParse()
ycm.HandleFileParseRequest()
vim_command.assert_has_calls( [
UnplaceSign_Call( 2, 1 )
] )
eq_( self._server_state.GetErrorCount(), 0 )
eq_( self._server_state.GetWarningCount(), 0 )
eq_( ycm.GetErrorCount(), 0 )
eq_( ycm.GetWarningCount(), 0 )
@patch( 'ycm.youcompleteme.YouCompleteMe._AddUltiSnipsDataIfNeeded' )
@patch( 'ycm.client.base_request.BaseRequest.PostDataToHandlerAsync',
new_callable = ExtendedMock )
def BufferVisit_BuildRequestForCurrentAndUnsavedBuffers_test(
self, post_data_to_handler_async, *args ):
@YouCompleteMeInstance()
def EventNotification_BufferVisit_BuildRequestForCurrentAndUnsavedBuffers_test(
ycm, *args ):
current_buffer_file = os.path.realpath( 'current_buffer' )
current_buffer = VimBuffer( name = current_buffer_file,
number = 1,
contents = [ 'current_buffer_content' ],
contents = [ 'current_buffer_contents' ],
filetype = 'some_filetype',
modified = False )
modified_buffer_file = os.path.realpath( 'modified_buffer' )
modified_buffer = VimBuffer( name = modified_buffer_file,
number = 2,
contents = [ 'modified_buffer_content' ],
contents = [ 'modified_buffer_contents' ],
filetype = 'some_filetype',
modified = True )
unmodified_buffer_file = os.path.realpath( 'unmodified_buffer' )
unmodified_buffer = VimBuffer( name = unmodified_buffer_file,
number = 3,
contents = [ 'unmodified_buffer_content' ],
contents = [ 'unmodified_buffer_contents' ],
filetype = 'some_filetype',
modified = False )
with patch( 'ycm.client.base_request.BaseRequest.'
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
with patch( 'vim.buffers', [ current_buffer,
modified_buffer,
unmodified_buffer ] ):
with patch( 'vim.current.buffer', current_buffer ):
with patch( 'vim.current.window.cursor', ( 3, 5 ) ):
self._server_state.OnBufferVisit()
ycm.OnBufferVisit()
assert_that(
# Positional arguments passed to PostDataToHandlerAsync.
@ -393,11 +397,11 @@ class EventNotification_test( Server_test ):
'column_num': 6,
'file_data': has_entries( {
current_buffer_file: has_entries( {
'contents': 'current_buffer_content\n',
'contents': 'current_buffer_contents\n',
'filetypes': [ 'some_filetype' ]
} ),
modified_buffer_file: has_entries( {
'contents': 'modified_buffer_content\n',
'contents': 'modified_buffer_contents\n',
'filetypes': [ 'some_filetype' ]
} )
} ),
@ -408,28 +412,28 @@ class EventNotification_test( Server_test ):
)
@patch( 'ycm.client.base_request.BaseRequest.PostDataToHandlerAsync',
new_callable = ExtendedMock )
def BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
self, post_data_to_handler_async ):
@YouCompleteMeInstance()
def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
ycm ):
current_buffer_file = os.path.realpath( 'current_buffer' )
current_buffer = VimBuffer( name = current_buffer_file,
number = 1,
contents = [ 'current_buffer_content' ],
contents = [ 'current_buffer_contents' ],
filetype = 'some_filetype',
modified = True )
deleted_buffer_file = os.path.realpath( 'deleted_buffer' )
deleted_buffer = VimBuffer( name = deleted_buffer_file,
number = 2,
contents = [ 'deleted_buffer_content' ],
contents = [ 'deleted_buffer_contents' ],
filetype = 'some_filetype',
modified = False )
with patch( 'ycm.client.base_request.BaseRequest.'
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
with patch( 'vim.buffers', [ current_buffer, deleted_buffer ] ):
with patch( 'vim.current.buffer', current_buffer ):
self._server_state.OnBufferUnload( deleted_buffer_file )
ycm.OnBufferUnload( deleted_buffer_file )
assert_that(
# Positional arguments passed to PostDataToHandlerAsync.
@ -441,11 +445,11 @@ class EventNotification_test( Server_test ):
'column_num': 1,
'file_data': has_entries( {
current_buffer_file: has_entries( {
'contents': 'current_buffer_content\n',
'contents': 'current_buffer_contents\n',
'filetypes': [ 'some_filetype' ]
} ),
deleted_buffer_file: has_entries( {
'contents': 'deleted_buffer_content\n',
'contents': 'deleted_buffer_contents\n',
'filetypes': [ 'some_filetype' ]
} )
} ),

View File

@ -33,9 +33,8 @@ from hamcrest import contains_string
from ycm.test_utils import MockVimModule, ExtendedMock
MockVimModule()
from ycm.omni_completer import OmniCompleter
from ycm.test_utils import ExpectedFailure
from ycm.tests.server_test import MakeUserOptions, Server_test
from ycm.tests import YouCompleteMeInstance
from ycmd.utils import ToBytes
from ycmd.request_wrap import RequestWrap
@ -74,22 +73,16 @@ def BuildRequestWrap( line_num, column_num, contents ):
return RequestWrap( BuildRequest( line_num, column_num, contents ) )
class OmniCompleter_test( Server_test ):
def OmniCompleter_GetCompletions_Cache_List_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_List_test( ycm ):
contents = 'test.'
request_data = BuildRequestWrap( line_num = 1,
column_num = 6,
contents = contents )
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( 'a' ),
ToBytesOnPY2( 'b' ),
@ -100,7 +93,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'')" ),
@ -109,11 +102,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, omnifunc_result )
def OmniCompleter_GetCompletions_Cache_ListFilter_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_ListFilter_test( ycm ):
contents = 'test.t'
request_data = BuildRequestWrap( line_num = 1,
column_num = 7,
@ -123,7 +113,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( 'a' ),
ToBytesOnPY2( 'b' ),
@ -134,7 +124,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'t')" ),
@ -143,11 +133,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, [] )
def OmniCompleter_GetCompletions_NoCache_List_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 0
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_List_test( ycm ):
contents = 'test.'
request_data = BuildRequestWrap( line_num = 1,
column_num = 6,
@ -156,7 +143,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( 'a' ),
ToBytesOnPY2( 'b' ),
@ -167,7 +154,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'')" ),
@ -176,11 +163,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, omnifunc_result )
def OmniCompleter_GetCompletions_NoCache_ListFilter_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 0
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_ListFilter_test( ycm ):
contents = 'test.t'
request_data = BuildRequestWrap( line_num = 1,
column_num = 7,
@ -190,7 +174,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( 'a' ),
ToBytesOnPY2( 'b' ),
@ -201,7 +185,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'t')" ),
@ -215,11 +199,8 @@ class OmniCompleter_test( Server_test ):
@ExpectedFailure( 'We ignore the result of the call to findstart and use our '
'own interpretation of where the identifier should be',
contains_string( "test_omnifunc(0,'t')" ) )
def OmniCompleter_GetCompletsions_UseFindStart_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletsions_UseFindStart_test( ycm ):
contents = 'test.t'
request_data = BuildRequestWrap( line_num = 1,
column_num = 7,
@ -229,7 +210,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( 'a' ),
ToBytesOnPY2( 'b' ),
@ -239,7 +220,7 @@ class OmniCompleter_test( Server_test ):
with patch( 'vim.eval',
new_callable = ExtendedMock,
side_effect = [ 1, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -252,11 +233,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, omnifunc_result )
def OmniCompleter_GetCompletions_Cache_Object_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_Object_test( ycm ):
contents = 'test.t'
request_data = BuildRequestWrap( line_num = 1,
column_num = 7,
@ -266,7 +244,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = {
'words': [
@ -281,7 +259,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -291,11 +269,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, [ ToBytesOnPY2( 'CDtEF' ) ] )
def OmniCompleter_GetCompletions_Cache_ObjectList_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_ObjectList_test( ycm ):
contents = 'test.tt'
request_data = BuildRequestWrap( line_num = 1,
column_num = 8,
@ -305,7 +280,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [
{
@ -329,7 +304,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -339,11 +314,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, [ omnifunc_result[ 1 ] ] )
def OmniCompleter_GetCompletions_NoCache_ObjectList_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 0
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_ObjectList_test( ycm ):
contents = 'test.tt'
request_data = BuildRequestWrap( line_num = 1,
column_num = 8,
@ -353,7 +325,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [
{
@ -377,7 +349,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -389,11 +361,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, omnifunc_result )
def OmniCompleter_GetCompletions_Cache_ObjectListObject_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_ObjectListObject_test( ycm ):
contents = 'test.tt'
request_data = BuildRequestWrap( line_num = 1,
column_num = 8,
@ -403,7 +372,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = {
'words': [
@ -429,7 +398,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -439,11 +408,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, [ omnifunc_result[ 'words' ][ 1 ] ] )
def OmniCompleter_GetCompletions_NoCache_ObjectListObject_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 0
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_ObjectListObject_test( ycm ):
contents = 'test.tt'
request_data = BuildRequestWrap( line_num = 1,
column_num = 8,
@ -453,7 +419,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = {
'words': [
@ -479,7 +445,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -491,11 +457,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, omnifunc_result[ 'words' ] )
def OmniCompleter_GetCompletions_Cache_List_Unicode_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_List_Unicode_test( ycm ):
contents = '†åsty_π.'
request_data = BuildRequestWrap( line_num = 1,
column_num = 13,
@ -504,7 +467,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( '†est' ),
ToBytesOnPY2( 'å_unicode_identifier' ),
@ -515,7 +478,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'')" ),
@ -524,11 +487,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, omnifunc_result )
def OmniCompleter_GetCompletions_NoCache_List_Unicode_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 0
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_NoCache_List_Unicode_test( ycm ):
contents = '†åsty_π.'
request_data = BuildRequestWrap( line_num = 1,
column_num = 13,
@ -537,7 +497,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( '†est' ),
ToBytesOnPY2( 'å_unicode_identifier' ),
@ -548,7 +508,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'')" ),
@ -558,11 +518,8 @@ class OmniCompleter_test( Server_test ):
@ExpectedFailure( 'Filtering on unicode is not supported by the server' )
def OmniCompleter_GetCompletions_Cache_List_Filter_Unicode_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_List_Filter_Unicode_test( ycm ):
contents = '†åsty_π.ππ'
request_data = BuildRequestWrap( line_num = 1,
column_num = 17,
@ -571,7 +528,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( '†est' ),
ToBytesOnPY2( 'å_unicode_identifier' ),
@ -582,7 +539,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'ππ')" ),
@ -592,11 +549,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, [ omnifunc_result[ 2 ] ] )
def OmniCompleter_GetCompletions_NoCache_List_Filter_Unicode_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 0
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_List_Filter_Unicode_test( ycm ):
contents = '†åsty_π.ππ'
request_data = BuildRequestWrap( line_num = 1,
column_num = 17,
@ -605,7 +559,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [ ToBytesOnPY2( 'πππππππ yummy πie' ) ]
@ -614,7 +568,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
call( "test_omnifunc(0,'ππ')" ),
@ -624,11 +578,8 @@ class OmniCompleter_test( Server_test ):
@ExpectedFailure( 'Filtering on unicode is not supported by the server' )
def OmniCompleter_GetCompletions_Cache_ObjectList_Unicode_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_ObjectList_Unicode_test( ycm ):
contents = '†åsty_π.ππ'
request_data = BuildRequestWrap( line_num = 1,
column_num = 17,
@ -639,7 +590,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = [
{
@ -663,7 +614,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),
@ -674,11 +625,8 @@ class OmniCompleter_test( Server_test ):
eq_( results, [ omnifunc_result[ 1 ] ] )
def OmniCompleter_GetCompletions_Cache_ObjectListObject_Unicode_test( self ):
omni_completer = OmniCompleter( MakeUserOptions( {
'cache_omnifunc': 1
} ) )
@YouCompleteMeInstance( { 'cache_omnifunc': 1 } )
def OmniCompleter_GetCompletions_Cache_ObjectListObject_Unicode_test( ycm ):
contents = '†åsty_π.t'
request_data = BuildRequestWrap( line_num = 1,
column_num = 14,
@ -689,7 +637,7 @@ class OmniCompleter_test( Server_test ):
# Make sure there is an omnifunc set up.
with patch( 'vim.eval', return_value = ToBytesOnPY2( 'test_omnifunc' ) ):
omni_completer.OnFileReadyToParse( request_data )
ycm._omnicomp.OnFileReadyToParse( request_data )
omnifunc_result = {
'words': [
@ -722,7 +670,7 @@ class OmniCompleter_test( Server_test ):
new_callable = ExtendedMock,
side_effect = [ 6, omnifunc_result ] ) as vim_eval:
results = omni_completer.ComputeCandidates( request_data )
results = ycm._omnicomp.ComputeCandidates( request_data )
vim_eval.assert_has_exact_calls( [
call( 'test_omnifunc(1,"")' ),

View File

@ -34,7 +34,7 @@ from mock import MagicMock, DEFAULT, patch
from nose.tools import eq_, ok_
from ycm import vimsupport
from ycm.tests.server_test import Server_test
from ycm.tests import YouCompleteMeInstance
from ycmd.utils import ToBytes
@ -66,189 +66,188 @@ def BuildCompletion( namespace = None, insertion_text = 'Test',
}
class PostComplete_test( Server_test ):
@contextlib.contextmanager
def _SetupForCsharpCompletionDone( self, completions ):
def _SetupForCsharpCompletionDone( ycm, completions ):
with patch( 'ycm.vimsupport.InsertNamespace' ):
with patch( 'ycm.vimsupport.TextBeforeCursor',
return_value = ' Test' ):
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' ):
request = MagicMock()
request.Done = MagicMock( return_value = True )
request.RawResponse = MagicMock( return_value = completions )
self._server_state._latest_completion_request = request
ycm._latest_completion_request = request
yield
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
def GetCompleteDoneHooks_ResultOnCsharp_test( self, *args ):
result = self._server_state.GetCompleteDoneHooks()
@YouCompleteMeInstance()
def GetCompleteDoneHooks_ResultOnCsharp_test( ycm, *args ):
result = ycm.GetCompleteDoneHooks()
eq_( 1, len( list( result ) ) )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( self, *args ):
result = self._server_state.GetCompleteDoneHooks()
@YouCompleteMeInstance()
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( ycm, *args ):
result = ycm.GetCompleteDoneHooks()
eq_( 0, len( list( result ) ) )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
def OnCompleteDone_WithActionCallsIt_test( self, *args ):
@YouCompleteMeInstance()
def OnCompleteDone_WithActionCallsIt_test( ycm, *args ):
action = MagicMock()
self._server_state._complete_done_hooks[ 'txt' ] = action
self._server_state.OnCompleteDone()
ycm._complete_done_hooks[ 'txt' ] = action
ycm.OnCompleteDone()
ok_( action.called )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
def OnCompleteDone_NoActionNoError_test( self, *args ):
self._server_state.OnCompleteDone()
@YouCompleteMeInstance()
def OnCompleteDone_NoActionNoError_test( ycm, *args ):
ycm.OnCompleteDone()
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( self, *args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
eq_( list( result ), completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'A' ) )
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( self,
*args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
self._server_state._FilterToMatchingCompletions( completions, False )
ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( self,
*args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
eq_( list( result ), completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( ' Quote' ) )
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( self,
*args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'A' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
assert_that( list( result ), empty() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( '†es†' ) )
def FilterToCompletedCompletions_NewVim_Unicode_test( self, *args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_NewVim_Unicode_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = '†es†' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
eq_( list( result ), completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' )
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( self, *args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
eq_( list( result ), completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' )
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( self,
@YouCompleteMeInstance()
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( ycm,
*args ):
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
self._server_state._FilterToMatchingCompletions( completions, False )
ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' )
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( self,
@YouCompleteMeInstance()
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( ycm,
*args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
eq_( list( result ), completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( self,
@YouCompleteMeInstance()
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( ycm,
*args ):
completions = [ BuildCompletion( insertion_text = 'A' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
assert_that( list( result ), empty() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniçø∂¢' )
def FilterToCompletedCompletions_OldVim_Unicode_test( self, *args ):
@YouCompleteMeInstance()
def FilterToCompletedCompletions_OldVim_Unicode_test( ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
result = self._server_state._FilterToMatchingCompletions( completions,
False )
result = ycm._FilterToMatchingCompletions( completions, False )
assert_that( list( result ), empty() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, True )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = "AAA" ) ]
self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'A' ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_Unicode_test(
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, True )
@ -256,11 +255,11 @@ class PostComplete_test( Server_test ):
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Te' ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, True )
@ -268,22 +267,22 @@ class PostComplete_test( Server_test ):
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'X' ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False )
@ -291,11 +290,11 @@ class PostComplete_test( Server_test ):
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( ' Quote' ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( insertion_text = "A" ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False )
@ -303,142 +302,151 @@ class PostComplete_test( Server_test ):
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Uniç' ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
@YouCompleteMeInstance()
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_Unicode_test(
self, *args ):
completions = [ BuildCompletion( insertion_text = "Uniçø∂¢" ) ]
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
completions )
ycm, *args ):
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, True )
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( self ):
eq_( None, self._server_state._GetRequiredNamespaceImport( {} ) )
@YouCompleteMeInstance()
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( ycm ):
eq_( None, ycm._GetRequiredNamespaceImport( {} ) )
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( self ):
@YouCompleteMeInstance()
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( ycm ):
namespace = 'A_NAMESPACE'
eq_( namespace, self._server_state._GetRequiredNamespaceImport(
eq_( namespace, ycm._GetRequiredNamespaceImport(
BuildCompletion( namespace )
) )
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( self ):
with self._SetupForCsharpCompletionDone( [] ):
self._server_state._latest_completion_request.Done = MagicMock(
return_value = False )
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( ycm ):
with _SetupForCsharpCompletionDone( ycm, [] ):
ycm._latest_completion_request.Done = MagicMock( return_value = False )
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Te' ) )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( None ) ]
with self._SetupForCsharpCompletionDone( completions ):
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
with _SetupForCsharpCompletionDone( ycm, completions ):
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( None ) ]
with self._SetupForCsharpCompletionDone( completions ):
with _SetupForCsharpCompletionDone( ycm, completions ):
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' ):
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test(
self, *args ):
ycm, *args ):
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
completions = [ BuildCompletion( *info ) ]
with self._SetupForCsharpCompletionDone( completions ):
with _SetupForCsharpCompletionDone( ycm, completions ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( completions,
self._server_state.GetCompletionsUserMayHaveCompleted() )
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa
self, *args ):
ycm, *args ):
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
completions = [ BuildCompletion( *info ),
BuildCompletion( insertion_text = 'TestTest' ) ]
with self._SetupForCsharpCompletionDone( completions ):
with _SetupForCsharpCompletionDone( ycm, completions ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( [ completions[ 0 ] ],
self._server_state.GetCompletionsUserMayHaveCompleted() )
eq_( [ completions[ 0 ] ], ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa
self, *args ):
ycm, *args ):
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
BuildCompletion( insertion_text = 'TestTest' ) ]
with self._SetupForCsharpCompletionDone( completions ):
with _SetupForCsharpCompletionDone( ycm, completions ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test(
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( None ) ]
with self._SetupForCsharpCompletionDone( completions ):
eq_( completions,
self._server_state.GetCompletionsUserMayHaveCompleted() )
with _SetupForCsharpCompletionDone( ycm, completions ):
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@YouCompleteMeInstance()
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test(
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( None ) ]
with self._SetupForCsharpCompletionDone( completions ):
eq_( completions,
self._server_state.GetCompletionsUserMayHaveCompleted() )
with _SetupForCsharpCompletionDone( ycm, completions ):
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( self, *args ):
with self._SetupForCsharpCompletionDone( [] ):
self._server_state._OnCompleteDone_Csharp()
@YouCompleteMeInstance()
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( ycm, *args ):
with _SetupForCsharpCompletionDone( ycm, [] ):
ycm._OnCompleteDone_Csharp()
ok_( not vimsupport.InsertNamespace.called )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@YouCompleteMeInstance()
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
self, *args ):
ycm, *args ):
completions = [ BuildCompletion( None ) ]
with self._SetupForCsharpCompletionDone( completions ):
self._server_state._OnCompleteDone_Csharp()
with _SetupForCsharpCompletionDone( ycm, completions ):
ycm._OnCompleteDone_Csharp()
ok_( not vimsupport.InsertNamespace.called )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
def PostCompleteCsharp_ValueDoesInsertNamespace_test( self, *args ):
@YouCompleteMeInstance()
def PostCompleteCsharp_ValueDoesInsertNamespace_test( ycm, *args ):
namespace = 'A_NAMESPACE'
completions = [ BuildCompletion( namespace ) ]
with self._SetupForCsharpCompletionDone( completions ):
self._server_state._OnCompleteDone_Csharp()
with _SetupForCsharpCompletionDone( ycm, completions ):
ycm._OnCompleteDone_Csharp()
vimsupport.InsertNamespace.assert_called_once_with( namespace )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.PresentDialog', return_value = 1 )
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( self, *args ):
@YouCompleteMeInstance()
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( ycm, *args ):
namespace = 'A_NAMESPACE'
namespace2 = 'ANOTHER_NAMESPACE'
completions = [
BuildCompletion( namespace ),
BuildCompletion( namespace2 ),
]
with self._SetupForCsharpCompletionDone( completions ):
self._server_state._OnCompleteDone_Csharp()
with _SetupForCsharpCompletionDone( ycm, completions ):
ycm._OnCompleteDone_Csharp()
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )

View File

@ -1,86 +0,0 @@
# Copyright (C) 2016 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 __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()
import requests
import time
from ycm.client.base_request import BaseRequest
from ycm.youcompleteme import YouCompleteMe
from ycmd import user_options_store
# The default options which are only relevant to the client, not the server and
# thus are not part of default_options.json, but are required for a working
# YouCompleteMe or OmniCompleter object.
DEFAULT_CLIENT_OPTIONS = {
'server_log_level': 'info',
'extra_conf_vim_data': [],
'show_diagnostics_ui': 1,
'enable_diagnostic_signs': 1,
'enable_diagnostic_highlighting': 0,
'always_populate_location_list': 0,
}
def MakeUserOptions( custom_options = {} ):
options = dict( user_options_store.DefaultOptions() )
options.update( DEFAULT_CLIENT_OPTIONS )
options.update( custom_options )
return options
class Server_test():
def _IsReady( self ):
return BaseRequest.GetDataFromHandler( 'ready' )
def _WaitUntilReady( self, timeout = 5 ):
total_slept = 0
while True:
try:
if total_slept > timeout:
raise RuntimeError( 'Waited for the server to be ready '
'for {0} seconds, aborting.'.format(
timeout ) )
if self._IsReady():
return
except requests.exceptions.ConnectionError:
pass
finally:
time.sleep( 0.1 )
total_slept += 0.1
def setUp( self ):
self._server_state = YouCompleteMe( MakeUserOptions() )
self._WaitUntilReady()
def tearDown( self ):
self._server_state.OnVimLeave()

View File

@ -29,10 +29,9 @@ MockVimModule()
import sys
from hamcrest import assert_that, is_in, is_not
from ycm.tests.server_test import Server_test
from ycm.tests import YouCompleteMeInstance
class YouCompleteMe_test( Server_test ):
def YcmCoreNotImported_test( self ):
@YouCompleteMeInstance()
def YouCompleteMe_YcmCoreNotImported_test( ycm ):
assert_that( 'ycm_core', is_not( is_in( sys.modules ) ) )