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:
commit
5cf5f04dd7
@ -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
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2015 YouCompleteMe contributors
|
# Copyright (C) 2015-2016 YouCompleteMe contributors
|
||||||
#
|
#
|
||||||
# This file is part of YouCompleteMe.
|
# This file is part of YouCompleteMe.
|
||||||
#
|
#
|
||||||
@ -29,7 +29,7 @@ MockVimModule()
|
|||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ycm.tests.server_test import Server_test
|
from ycm.tests import YouCompleteMeInstance
|
||||||
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
|
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
|
||||||
UnknownExtraConf, ServerError )
|
UnknownExtraConf, ServerError )
|
||||||
|
|
||||||
@ -110,278 +110,282 @@ def MockEventNotification( response_method, native_filetype_completer = True ):
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
class EventNotification_test( Server_test ):
|
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
def EventNotification_FileReadyToParse_NonDiagnostic_Error_test(
|
||||||
|
ycm, post_vim_message ):
|
||||||
|
|
||||||
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
|
||||||
def FileReadyToParse_NonDiagnostic_Error_test( self, post_vim_message ):
|
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
|
||||||
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
|
# raises an exception handling FileReadyToParse event notification
|
||||||
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
|
ERROR_TEXT = 'Some completer response text'
|
||||||
# raises an exception handling FileReadyToParse event notification
|
|
||||||
ERROR_TEXT = 'Some completer response text'
|
|
||||||
|
|
||||||
def ErrorResponse( *args ):
|
def ErrorResponse( *args ):
|
||||||
raise ServerError( ERROR_TEXT )
|
raise ServerError( ERROR_TEXT )
|
||||||
|
|
||||||
with MockArbitraryBuffer( 'javascript' ):
|
with MockArbitraryBuffer( 'javascript' ):
|
||||||
with MockEventNotification( ErrorResponse ):
|
with MockEventNotification( ErrorResponse ):
|
||||||
self._server_state.OnFileReadyToParse()
|
ycm.OnFileReadyToParse()
|
||||||
assert self._server_state.FileParseRequestReady()
|
ok_( ycm.FileParseRequestReady() )
|
||||||
self._server_state.HandleFileParseRequest()
|
ycm.HandleFileParseRequest()
|
||||||
|
|
||||||
# The first call raises a warning
|
# The first call raises a warning
|
||||||
post_vim_message.assert_has_exact_calls( [
|
post_vim_message.assert_has_exact_calls( [
|
||||||
call( ERROR_TEXT, truncate = False )
|
call( ERROR_TEXT, truncate = False )
|
||||||
|
] )
|
||||||
|
|
||||||
|
# Subsequent calls don't re-raise the warning
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
post_vim_message.assert_has_exact_calls( [
|
||||||
|
call( ERROR_TEXT, truncate = False )
|
||||||
|
] )
|
||||||
|
|
||||||
|
# But it does if a subsequent event raises again
|
||||||
|
ycm.OnFileReadyToParse()
|
||||||
|
ok_( ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
post_vim_message.assert_has_exact_calls( [
|
||||||
|
call( ERROR_TEXT, truncate = False ),
|
||||||
|
call( ERROR_TEXT, truncate = False )
|
||||||
|
] )
|
||||||
|
|
||||||
|
|
||||||
|
@patch( 'vim.command' )
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
def EventNotification_FileReadyToParse_NonDiagnostic_Error_NonNative_test(
|
||||||
|
ycm, vim_command ):
|
||||||
|
|
||||||
|
with MockArbitraryBuffer( 'javascript' ):
|
||||||
|
with MockEventNotification( None, False ):
|
||||||
|
ycm.OnFileReadyToParse()
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
vim_command.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
@patch( 'ycm.client.event_notification._LoadExtraConfFile',
|
||||||
|
new_callable = ExtendedMock )
|
||||||
|
@patch( 'ycm.client.event_notification._IgnoreExtraConfFile',
|
||||||
|
new_callable = ExtendedMock )
|
||||||
|
@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
|
||||||
|
# raises the (special) UnknownExtraConf exception
|
||||||
|
|
||||||
|
FILE_NAME = 'a_file'
|
||||||
|
MESSAGE = ( 'Found ' + FILE_NAME + '. Load? \n\n(Question can be '
|
||||||
|
'turned off with options, see YCM docs)' )
|
||||||
|
|
||||||
|
def UnknownExtraConfResponse( *args ):
|
||||||
|
raise UnknownExtraConf( FILE_NAME )
|
||||||
|
|
||||||
|
with MockArbitraryBuffer( 'javascript' ):
|
||||||
|
with MockEventNotification( UnknownExtraConfResponse ):
|
||||||
|
|
||||||
|
# When the user accepts the extra conf, we load it
|
||||||
|
with patch( 'ycm.vimsupport.PresentDialog',
|
||||||
|
return_value = 0,
|
||||||
|
new_callable = ExtendedMock ) as present_dialog:
|
||||||
|
ycm.OnFileReadyToParse()
|
||||||
|
ok_( ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
|
||||||
|
present_dialog.assert_has_exact_calls( [
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE ),
|
||||||
|
] )
|
||||||
|
load_extra_conf.assert_has_exact_calls( [
|
||||||
|
call( FILE_NAME ),
|
||||||
] )
|
] )
|
||||||
|
|
||||||
# Subsequent calls don't re-raise the warning
|
# 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 )
|
present_dialog.assert_has_exact_calls( [
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE )
|
||||||
|
] )
|
||||||
|
load_extra_conf.assert_has_exact_calls( [
|
||||||
|
call( FILE_NAME ),
|
||||||
] )
|
] )
|
||||||
|
|
||||||
# But it does if a subsequent event raises again
|
# But it does if a subsequent event raises again
|
||||||
self._server_state.OnFileReadyToParse()
|
ycm.OnFileReadyToParse()
|
||||||
assert self._server_state.FileParseRequestReady()
|
ok_( ycm.FileParseRequestReady() )
|
||||||
self._server_state.HandleFileParseRequest()
|
ycm.HandleFileParseRequest()
|
||||||
post_vim_message.assert_has_exact_calls( [
|
|
||||||
call( ERROR_TEXT, truncate = False ),
|
present_dialog.assert_has_exact_calls( [
|
||||||
call( ERROR_TEXT, truncate = False )
|
PresentDialog_Confirm_Call( MESSAGE ),
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE ),
|
||||||
|
] )
|
||||||
|
load_extra_conf.assert_has_exact_calls( [
|
||||||
|
call( FILE_NAME ),
|
||||||
|
call( FILE_NAME ),
|
||||||
|
] )
|
||||||
|
|
||||||
|
# When the user rejects the extra conf, we reject it
|
||||||
|
with patch( 'ycm.vimsupport.PresentDialog',
|
||||||
|
return_value = 1,
|
||||||
|
new_callable = ExtendedMock ) as present_dialog:
|
||||||
|
ycm.OnFileReadyToParse()
|
||||||
|
ok_( ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
|
||||||
|
present_dialog.assert_has_exact_calls( [
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE ),
|
||||||
|
] )
|
||||||
|
ignore_extra_conf.assert_has_exact_calls( [
|
||||||
|
call( FILE_NAME ),
|
||||||
|
] )
|
||||||
|
|
||||||
|
# Subsequent calls don't re-raise the warning
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
|
||||||
|
present_dialog.assert_has_exact_calls( [
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE )
|
||||||
|
] )
|
||||||
|
ignore_extra_conf.assert_has_exact_calls( [
|
||||||
|
call( FILE_NAME ),
|
||||||
|
] )
|
||||||
|
|
||||||
|
# But it does if a subsequent event raises again
|
||||||
|
ycm.OnFileReadyToParse()
|
||||||
|
ok_( ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
|
||||||
|
present_dialog.assert_has_exact_calls( [
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE ),
|
||||||
|
PresentDialog_Confirm_Call( MESSAGE ),
|
||||||
|
] )
|
||||||
|
ignore_extra_conf.assert_has_exact_calls( [
|
||||||
|
call( FILE_NAME ),
|
||||||
|
call( FILE_NAME ),
|
||||||
] )
|
] )
|
||||||
|
|
||||||
|
|
||||||
@patch( 'vim.command' )
|
@YouCompleteMeInstance()
|
||||||
def FileReadyToParse_NonDiagnostic_Error_NonNative_test( self, vim_command ):
|
def EventNotification_FileReadyToParse_Diagnostic_Error_Native_test( ycm ):
|
||||||
with MockArbitraryBuffer( 'javascript' ):
|
_Check_FileReadyToParse_Diagnostic_Error( ycm )
|
||||||
with MockEventNotification( None, False ):
|
_Check_FileReadyToParse_Diagnostic_Warning( ycm )
|
||||||
self._server_state.OnFileReadyToParse()
|
_Check_FileReadyToParse_Diagnostic_Clean( ycm )
|
||||||
self._server_state.HandleFileParseRequest()
|
|
||||||
vim_command.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.client.event_notification._LoadExtraConfFile',
|
@patch( 'vim.command' )
|
||||||
new_callable = ExtendedMock )
|
def _Check_FileReadyToParse_Diagnostic_Error( ycm, vim_command ):
|
||||||
@patch( 'ycm.client.event_notification._IgnoreExtraConfFile',
|
# Tests Vim sign placement and error/warning count python API
|
||||||
new_callable = ExtendedMock )
|
# when one error is returned.
|
||||||
def FileReadyToParse_NonDiagnostic_ConfirmExtraConf_test(
|
def DiagnosticResponse( *args ):
|
||||||
self,
|
start = Location( 1, 2, 'TEST_BUFFER' )
|
||||||
ignore_extra_conf,
|
end = Location( 1, 4, 'TEST_BUFFER' )
|
||||||
load_extra_conf,
|
extent = Range( start, end )
|
||||||
*args ):
|
diagnostic = Diagnostic( [], start, extent, 'expected ;', 'ERROR' )
|
||||||
|
return [ BuildDiagnosticData( diagnostic ) ]
|
||||||
|
|
||||||
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
|
with MockArbitraryBuffer( 'cpp' ):
|
||||||
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
|
with MockEventNotification( DiagnosticResponse ):
|
||||||
# raises the (special) UnknownExtraConf exception
|
ycm.OnFileReadyToParse()
|
||||||
|
ok_( ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
vim_command.assert_has_calls( [
|
||||||
|
PlaceSign_Call( 1, 1, 1, True )
|
||||||
|
] )
|
||||||
|
eq_( ycm.GetErrorCount(), 1 )
|
||||||
|
eq_( ycm.GetWarningCount(), 0 )
|
||||||
|
|
||||||
FILE_NAME = 'a_file'
|
# Consequent calls to HandleFileParseRequest shouldn't mess with
|
||||||
MESSAGE = ( 'Found ' + FILE_NAME + '. Load? \n\n(Question can be '
|
# existing diagnostics, when there is no new parse request.
|
||||||
'turned off with options, see YCM docs)' )
|
vim_command.reset_mock()
|
||||||
|
ok_( not ycm.FileParseRequestReady() )
|
||||||
def UnknownExtraConfResponse( *args ):
|
ycm.HandleFileParseRequest()
|
||||||
raise UnknownExtraConf( FILE_NAME )
|
vim_command.assert_not_called()
|
||||||
|
eq_( ycm.GetErrorCount(), 1 )
|
||||||
with MockArbitraryBuffer( 'javascript' ):
|
eq_( ycm.GetWarningCount(), 0 )
|
||||||
with MockEventNotification( UnknownExtraConfResponse ):
|
|
||||||
|
|
||||||
# When the user accepts the extra conf, we load it
|
|
||||||
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()
|
|
||||||
|
|
||||||
present_dialog.assert_has_exact_calls( [
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE ),
|
|
||||||
] )
|
|
||||||
load_extra_conf.assert_has_exact_calls( [
|
|
||||||
call( FILE_NAME ),
|
|
||||||
] )
|
|
||||||
|
|
||||||
# Subsequent calls don't re-raise the warning
|
|
||||||
self._server_state.HandleFileParseRequest()
|
|
||||||
|
|
||||||
present_dialog.assert_has_exact_calls( [
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE )
|
|
||||||
] )
|
|
||||||
load_extra_conf.assert_has_exact_calls( [
|
|
||||||
call( FILE_NAME ),
|
|
||||||
] )
|
|
||||||
|
|
||||||
# But it does if a subsequent event raises again
|
|
||||||
self._server_state.OnFileReadyToParse()
|
|
||||||
assert self._server_state.FileParseRequestReady()
|
|
||||||
self._server_state.HandleFileParseRequest()
|
|
||||||
|
|
||||||
present_dialog.assert_has_exact_calls( [
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE ),
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE ),
|
|
||||||
] )
|
|
||||||
load_extra_conf.assert_has_exact_calls( [
|
|
||||||
call( FILE_NAME ),
|
|
||||||
call( FILE_NAME ),
|
|
||||||
] )
|
|
||||||
|
|
||||||
# When the user rejects the extra conf, we reject it
|
|
||||||
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()
|
|
||||||
|
|
||||||
present_dialog.assert_has_exact_calls( [
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE ),
|
|
||||||
] )
|
|
||||||
ignore_extra_conf.assert_has_exact_calls( [
|
|
||||||
call( FILE_NAME ),
|
|
||||||
] )
|
|
||||||
|
|
||||||
# Subsequent calls don't re-raise the warning
|
|
||||||
self._server_state.HandleFileParseRequest()
|
|
||||||
|
|
||||||
present_dialog.assert_has_exact_calls( [
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE )
|
|
||||||
] )
|
|
||||||
ignore_extra_conf.assert_has_exact_calls( [
|
|
||||||
call( FILE_NAME ),
|
|
||||||
] )
|
|
||||||
|
|
||||||
# But it does if a subsequent event raises again
|
|
||||||
self._server_state.OnFileReadyToParse()
|
|
||||||
assert self._server_state.FileParseRequestReady()
|
|
||||||
self._server_state.HandleFileParseRequest()
|
|
||||||
|
|
||||||
present_dialog.assert_has_exact_calls( [
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE ),
|
|
||||||
PresentDialog_Confirm_Call( MESSAGE ),
|
|
||||||
] )
|
|
||||||
ignore_extra_conf.assert_has_exact_calls( [
|
|
||||||
call( FILE_NAME ),
|
|
||||||
call( FILE_NAME ),
|
|
||||||
] )
|
|
||||||
|
|
||||||
|
|
||||||
def FileReadyToParse_Diagnostic_Error_Native_test( self ):
|
@patch( 'vim.command' )
|
||||||
self._Check_FileReadyToParse_Diagnostic_Error()
|
def _Check_FileReadyToParse_Diagnostic_Warning( ycm, vim_command ):
|
||||||
self._Check_FileReadyToParse_Diagnostic_Warning()
|
# Tests Vim sign placement/unplacement and error/warning count python API
|
||||||
self._Check_FileReadyToParse_Diagnostic_Clean()
|
# when one warning is returned.
|
||||||
|
# Should be called after _Check_FileReadyToParse_Diagnostic_Error
|
||||||
|
def DiagnosticResponse( *args ):
|
||||||
|
start = Location( 2, 2, 'TEST_BUFFER' )
|
||||||
|
end = Location( 2, 4, 'TEST_BUFFER' )
|
||||||
|
extent = Range( start, end )
|
||||||
|
diagnostic = Diagnostic( [], start, extent, 'cast', 'WARNING' )
|
||||||
|
return [ BuildDiagnosticData( diagnostic ) ]
|
||||||
|
|
||||||
|
with MockArbitraryBuffer( 'cpp' ):
|
||||||
|
with MockEventNotification( DiagnosticResponse ):
|
||||||
|
ycm.OnFileReadyToParse()
|
||||||
|
ok_( ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
vim_command.assert_has_calls( [
|
||||||
|
PlaceSign_Call( 2, 2, 1, False ),
|
||||||
|
UnplaceSign_Call( 1, 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 ycm.FileParseRequestReady() )
|
||||||
|
ycm.HandleFileParseRequest()
|
||||||
|
vim_command.assert_not_called()
|
||||||
|
eq_( ycm.GetErrorCount(), 0 )
|
||||||
|
eq_( ycm.GetWarningCount(), 1 )
|
||||||
|
|
||||||
|
|
||||||
@patch( 'vim.command' )
|
@patch( 'vim.command' )
|
||||||
def _Check_FileReadyToParse_Diagnostic_Error( self, vim_command ):
|
def _Check_FileReadyToParse_Diagnostic_Clean( ycm, vim_command ):
|
||||||
# Tests Vim sign placement and error/warning count python API
|
# Tests Vim sign unplacement and error/warning count python API
|
||||||
# when one error is returned.
|
# when there are no errors/warnings left.
|
||||||
def DiagnosticResponse( *args ):
|
# Should be called after _Check_FileReadyToParse_Diagnostic_Warning
|
||||||
start = Location( 1, 2, 'TEST_BUFFER' )
|
with MockArbitraryBuffer( 'cpp' ):
|
||||||
end = Location( 1, 4, 'TEST_BUFFER' )
|
with MockEventNotification( MagicMock( return_value = [] ) ):
|
||||||
extent = Range( start, end )
|
ycm.OnFileReadyToParse()
|
||||||
diagnostic = Diagnostic( [], start, extent, 'expected ;', 'ERROR' )
|
ycm.HandleFileParseRequest()
|
||||||
return [ BuildDiagnosticData( diagnostic ) ]
|
vim_command.assert_has_calls( [
|
||||||
|
UnplaceSign_Call( 2, 1 )
|
||||||
with MockArbitraryBuffer( 'cpp' ):
|
] )
|
||||||
with MockEventNotification( DiagnosticResponse ):
|
eq_( ycm.GetErrorCount(), 0 )
|
||||||
self._server_state.OnFileReadyToParse()
|
eq_( ycm.GetWarningCount(), 0 )
|
||||||
ok_( self._server_state.FileParseRequestReady() )
|
|
||||||
self._server_state.HandleFileParseRequest()
|
|
||||||
vim_command.assert_has_calls( [
|
|
||||||
PlaceSign_Call( 1, 1, 1, True )
|
|
||||||
] )
|
|
||||||
eq_( self._server_state.GetErrorCount(), 1 )
|
|
||||||
eq_( self._server_state.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()
|
|
||||||
vim_command.assert_not_called()
|
|
||||||
eq_( self._server_state.GetErrorCount(), 1 )
|
|
||||||
eq_( self._server_state.GetWarningCount(), 0 )
|
|
||||||
|
|
||||||
|
|
||||||
@patch( 'vim.command' )
|
@patch( 'ycm.youcompleteme.YouCompleteMe._AddUltiSnipsDataIfNeeded' )
|
||||||
def _Check_FileReadyToParse_Diagnostic_Warning( self, vim_command ):
|
@YouCompleteMeInstance()
|
||||||
# Tests Vim sign placement/unplacement and error/warning count python API
|
def EventNotification_BufferVisit_BuildRequestForCurrentAndUnsavedBuffers_test(
|
||||||
# when one warning is returned.
|
ycm, *args ):
|
||||||
# Should be called after _Check_FileReadyToParse_Diagnostic_Error
|
|
||||||
def DiagnosticResponse( *args ):
|
|
||||||
start = Location( 2, 2, 'TEST_BUFFER' )
|
|
||||||
end = Location( 2, 4, 'TEST_BUFFER' )
|
|
||||||
extent = Range( start, end )
|
|
||||||
diagnostic = Diagnostic( [], start, extent, 'cast', 'WARNING' )
|
|
||||||
return [ BuildDiagnosticData( diagnostic ) ]
|
|
||||||
|
|
||||||
with MockArbitraryBuffer( 'cpp' ):
|
current_buffer_file = os.path.realpath( 'current_buffer' )
|
||||||
with MockEventNotification( DiagnosticResponse ):
|
current_buffer = VimBuffer( name = current_buffer_file,
|
||||||
self._server_state.OnFileReadyToParse()
|
number = 1,
|
||||||
ok_( self._server_state.FileParseRequestReady() )
|
contents = [ 'current_buffer_contents' ],
|
||||||
self._server_state.HandleFileParseRequest()
|
filetype = 'some_filetype',
|
||||||
vim_command.assert_has_calls( [
|
modified = False )
|
||||||
PlaceSign_Call( 2, 2, 1, False ),
|
|
||||||
UnplaceSign_Call( 1, 1 )
|
|
||||||
] )
|
|
||||||
eq_( self._server_state.GetErrorCount(), 0 )
|
|
||||||
eq_( self._server_state.GetWarningCount(), 1 )
|
|
||||||
|
|
||||||
# Consequent calls to HandleFileParseRequest shouldn't mess with
|
modified_buffer_file = os.path.realpath( 'modified_buffer' )
|
||||||
# existing diagnostics, when there is no new parse request.
|
modified_buffer = VimBuffer( name = modified_buffer_file,
|
||||||
vim_command.reset_mock()
|
number = 2,
|
||||||
ok_( not self._server_state.FileParseRequestReady() )
|
contents = [ 'modified_buffer_contents' ],
|
||||||
self._server_state.HandleFileParseRequest()
|
filetype = 'some_filetype',
|
||||||
vim_command.assert_not_called()
|
modified = True )
|
||||||
eq_( self._server_state.GetErrorCount(), 0 )
|
|
||||||
eq_( self._server_state.GetWarningCount(), 1 )
|
|
||||||
|
|
||||||
|
unmodified_buffer_file = os.path.realpath( 'unmodified_buffer' )
|
||||||
@patch( 'vim.command' )
|
unmodified_buffer = VimBuffer( name = unmodified_buffer_file,
|
||||||
def _Check_FileReadyToParse_Diagnostic_Clean( self, vim_command ):
|
number = 3,
|
||||||
# Tests Vim sign unplacement and error/warning count python API
|
contents = [ 'unmodified_buffer_contents' ],
|
||||||
# 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()
|
|
||||||
vim_command.assert_has_calls( [
|
|
||||||
UnplaceSign_Call( 2, 1 )
|
|
||||||
] )
|
|
||||||
eq_( self._server_state.GetErrorCount(), 0 )
|
|
||||||
eq_( self._server_state.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 ):
|
|
||||||
|
|
||||||
current_buffer_file = os.path.realpath( 'current_buffer' )
|
|
||||||
current_buffer = VimBuffer( name = current_buffer_file,
|
|
||||||
number = 1,
|
|
||||||
contents = [ 'current_buffer_content' ],
|
|
||||||
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' ],
|
|
||||||
filetype = 'some_filetype',
|
filetype = 'some_filetype',
|
||||||
modified = True )
|
modified = False )
|
||||||
|
|
||||||
unmodified_buffer_file = os.path.realpath( 'unmodified_buffer' )
|
|
||||||
unmodified_buffer = VimBuffer( name = unmodified_buffer_file,
|
|
||||||
number = 3,
|
|
||||||
contents = [ 'unmodified_buffer_content' ],
|
|
||||||
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,
|
with patch( 'vim.buffers', [ current_buffer,
|
||||||
modified_buffer,
|
modified_buffer,
|
||||||
unmodified_buffer ] ):
|
unmodified_buffer ] ):
|
||||||
with patch( 'vim.current.buffer', current_buffer ):
|
with patch( 'vim.current.buffer', current_buffer ):
|
||||||
with patch( 'vim.current.window.cursor', ( 3, 5 ) ):
|
with patch( 'vim.current.window.cursor', ( 3, 5 ) ):
|
||||||
self._server_state.OnBufferVisit()
|
ycm.OnBufferVisit()
|
||||||
|
|
||||||
assert_that(
|
assert_that(
|
||||||
# Positional arguments passed to PostDataToHandlerAsync.
|
# Positional arguments passed to PostDataToHandlerAsync.
|
||||||
@ -393,11 +397,11 @@ class EventNotification_test( Server_test ):
|
|||||||
'column_num': 6,
|
'column_num': 6,
|
||||||
'file_data': has_entries( {
|
'file_data': has_entries( {
|
||||||
current_buffer_file: has_entries( {
|
current_buffer_file: has_entries( {
|
||||||
'contents': 'current_buffer_content\n',
|
'contents': 'current_buffer_contents\n',
|
||||||
'filetypes': [ 'some_filetype' ]
|
'filetypes': [ 'some_filetype' ]
|
||||||
} ),
|
} ),
|
||||||
modified_buffer_file: has_entries( {
|
modified_buffer_file: has_entries( {
|
||||||
'contents': 'modified_buffer_content\n',
|
'contents': 'modified_buffer_contents\n',
|
||||||
'filetypes': [ 'some_filetype' ]
|
'filetypes': [ 'some_filetype' ]
|
||||||
} )
|
} )
|
||||||
} ),
|
} ),
|
||||||
@ -408,49 +412,49 @@ class EventNotification_test( Server_test ):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.client.base_request.BaseRequest.PostDataToHandlerAsync',
|
@YouCompleteMeInstance()
|
||||||
new_callable = ExtendedMock )
|
def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
|
||||||
def BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
|
ycm ):
|
||||||
self, post_data_to_handler_async ):
|
current_buffer_file = os.path.realpath( 'current_buffer' )
|
||||||
|
current_buffer = VimBuffer( name = current_buffer_file,
|
||||||
|
number = 1,
|
||||||
|
contents = [ 'current_buffer_contents' ],
|
||||||
|
filetype = 'some_filetype',
|
||||||
|
modified = True )
|
||||||
|
|
||||||
current_buffer_file = os.path.realpath( 'current_buffer' )
|
deleted_buffer_file = os.path.realpath( 'deleted_buffer' )
|
||||||
current_buffer = VimBuffer( name = current_buffer_file,
|
deleted_buffer = VimBuffer( name = deleted_buffer_file,
|
||||||
number = 1,
|
number = 2,
|
||||||
contents = [ 'current_buffer_content' ],
|
contents = [ 'deleted_buffer_contents' ],
|
||||||
filetype = 'some_filetype',
|
filetype = 'some_filetype',
|
||||||
modified = True )
|
modified = False )
|
||||||
|
|
||||||
deleted_buffer_file = os.path.realpath( 'deleted_buffer' )
|
|
||||||
deleted_buffer = VimBuffer( name = deleted_buffer_file,
|
|
||||||
number = 2,
|
|
||||||
contents = [ 'deleted_buffer_content' ],
|
|
||||||
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.buffers', [ current_buffer, deleted_buffer ] ):
|
||||||
with patch( 'vim.current.buffer', current_buffer ):
|
with patch( 'vim.current.buffer', current_buffer ):
|
||||||
self._server_state.OnBufferUnload( deleted_buffer_file )
|
ycm.OnBufferUnload( deleted_buffer_file )
|
||||||
|
|
||||||
assert_that(
|
assert_that(
|
||||||
# Positional arguments passed to PostDataToHandlerAsync.
|
# Positional arguments passed to PostDataToHandlerAsync.
|
||||||
post_data_to_handler_async.call_args[ 0 ],
|
post_data_to_handler_async.call_args[ 0 ],
|
||||||
contains(
|
contains(
|
||||||
has_entries( {
|
has_entries( {
|
||||||
'filepath': deleted_buffer_file,
|
'filepath': deleted_buffer_file,
|
||||||
'line_num': 1,
|
'line_num': 1,
|
||||||
'column_num': 1,
|
'column_num': 1,
|
||||||
'file_data': has_entries( {
|
'file_data': has_entries( {
|
||||||
current_buffer_file: has_entries( {
|
current_buffer_file: has_entries( {
|
||||||
'contents': 'current_buffer_content\n',
|
'contents': 'current_buffer_contents\n',
|
||||||
'filetypes': [ 'some_filetype' ]
|
'filetypes': [ 'some_filetype' ]
|
||||||
} ),
|
|
||||||
deleted_buffer_file: has_entries( {
|
|
||||||
'contents': 'deleted_buffer_content\n',
|
|
||||||
'filetypes': [ 'some_filetype' ]
|
|
||||||
} )
|
|
||||||
} ),
|
} ),
|
||||||
'event_name': 'BufferUnload'
|
deleted_buffer_file: has_entries( {
|
||||||
|
'contents': 'deleted_buffer_contents\n',
|
||||||
|
'filetypes': [ 'some_filetype' ]
|
||||||
|
} )
|
||||||
} ),
|
} ),
|
||||||
'event_notification'
|
'event_name': 'BufferUnload'
|
||||||
)
|
} ),
|
||||||
|
'event_notification'
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -34,7 +34,7 @@ from mock import MagicMock, DEFAULT, patch
|
|||||||
from nose.tools import eq_, ok_
|
from nose.tools import eq_, ok_
|
||||||
|
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
from ycm.tests.server_test import Server_test
|
from ycm.tests import YouCompleteMeInstance
|
||||||
from ycmd.utils import ToBytes
|
from ycmd.utils import ToBytes
|
||||||
|
|
||||||
|
|
||||||
@ -66,379 +66,387 @@ def BuildCompletion( namespace = None, insertion_text = 'Test',
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PostComplete_test( Server_test ):
|
@contextlib.contextmanager
|
||||||
|
def _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
@contextlib.contextmanager
|
with patch( 'ycm.vimsupport.InsertNamespace' ):
|
||||||
def _SetupForCsharpCompletionDone( self, completions ):
|
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' ):
|
||||||
with patch( 'ycm.vimsupport.InsertNamespace' ):
|
request = MagicMock()
|
||||||
with patch( 'ycm.vimsupport.TextBeforeCursor',
|
request.Done = MagicMock( return_value = True )
|
||||||
return_value = ' Test' ):
|
request.RawResponse = MagicMock( return_value = completions )
|
||||||
request = MagicMock()
|
ycm._latest_completion_request = request
|
||||||
request.Done = MagicMock( return_value = True )
|
yield
|
||||||
request.RawResponse = MagicMock( return_value = completions )
|
|
||||||
self._server_state._latest_completion_request = request
|
|
||||||
yield
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
def GetCompleteDoneHooks_ResultOnCsharp_test( ycm, *args ):
|
||||||
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
|
result = ycm.GetCompleteDoneHooks()
|
||||||
def GetCompleteDoneHooks_ResultOnCsharp_test( self, *args ):
|
eq_( 1, len( list( result ) ) )
|
||||||
result = self._server_state.GetCompleteDoneHooks()
|
|
||||||
eq_( 1, len( list( result ) ) )
|
|
||||||
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
|
||||||
|
@YouCompleteMeInstance()
|
||||||
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
|
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( ycm, *args ):
|
||||||
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( self, *args ):
|
result = ycm.GetCompleteDoneHooks()
|
||||||
result = self._server_state.GetCompleteDoneHooks()
|
eq_( 0, len( list( result ) ) )
|
||||||
eq_( 0, len( list( result ) ) )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
|
||||||
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
|
@YouCompleteMeInstance()
|
||||||
def OnCompleteDone_WithActionCallsIt_test( self, *args ):
|
def OnCompleteDone_WithActionCallsIt_test( ycm, *args ):
|
||||||
action = MagicMock()
|
action = MagicMock()
|
||||||
self._server_state._complete_done_hooks[ 'txt' ] = action
|
ycm._complete_done_hooks[ 'txt' ] = action
|
||||||
self._server_state.OnCompleteDone()
|
ycm.OnCompleteDone()
|
||||||
|
ok_( action.called )
|
||||||
ok_( action.called )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
|
||||||
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'txt' ] )
|
@YouCompleteMeInstance()
|
||||||
def OnCompleteDone_NoActionNoError_test( self, *args ):
|
def OnCompleteDone_NoActionNoError_test( ycm, *args ):
|
||||||
self._server_state.OnCompleteDone()
|
ycm.OnCompleteDone()
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
GetVariableValue_CompleteItemIs( 'Test' ) )
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
||||||
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( self, *args ):
|
@YouCompleteMeInstance()
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( ycm, *args ):
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
False )
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
eq_( list( result ), completions )
|
eq_( list( result ), completions )
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
GetVariableValue_CompleteItemIs( 'A' ) )
|
GetVariableValue_CompleteItemIs( 'A' ) )
|
||||||
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( self,
|
@YouCompleteMeInstance()
|
||||||
*args ):
|
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
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.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
GetVariableValue_CompleteItemIs( 'Test' ) )
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
||||||
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( self,
|
@YouCompleteMeInstance()
|
||||||
*args ):
|
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
False )
|
eq_( list( result ), completions )
|
||||||
eq_( list( result ), completions )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
GetVariableValue_CompleteItemIs( ' Quote' ) )
|
||||||
GetVariableValue_CompleteItemIs( ' Quote' ) )
|
@YouCompleteMeInstance()
|
||||||
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( self,
|
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( ycm, *args ):
|
||||||
*args ):
|
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
||||||
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
assert_that( list( result ), empty() )
|
||||||
False )
|
|
||||||
assert_that( list( result ), empty() )
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
GetVariableValue_CompleteItemIs( '†es†' ) )
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
@YouCompleteMeInstance()
|
||||||
GetVariableValue_CompleteItemIs( '†es†' ) )
|
def FilterToCompletedCompletions_NewVim_Unicode_test( ycm, *args ):
|
||||||
def FilterToCompletedCompletions_NewVim_Unicode_test( self, *args ):
|
completions = [ BuildCompletion( insertion_text = '†es†' ) ]
|
||||||
completions = [ BuildCompletion( insertion_text = '†es†' ) ]
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
eq_( list( result ), completions )
|
||||||
False )
|
|
||||||
eq_( list( result ), completions )
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@YouCompleteMeInstance()
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' )
|
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( ycm, *args ):
|
||||||
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( self, *args ):
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
eq_( list( result ), completions )
|
||||||
False )
|
|
||||||
eq_( list( result ), completions )
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@YouCompleteMeInstance()
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' )
|
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( ycm,
|
||||||
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( self,
|
*args ):
|
||||||
*args ):
|
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
||||||
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
ycm._FilterToMatchingCompletions( completions, False )
|
||||||
self._server_state._FilterToMatchingCompletions( completions, False )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' )
|
@YouCompleteMeInstance()
|
||||||
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( self,
|
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( ycm,
|
||||||
*args ):
|
*args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
False )
|
eq_( list( result ), completions )
|
||||||
eq_( list( result ), completions )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
@YouCompleteMeInstance()
|
||||||
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( self,
|
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( ycm,
|
||||||
*args ):
|
*args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
False )
|
assert_that( list( result ), empty() )
|
||||||
assert_that( list( result ), empty() )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniçø∂¢' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniçø∂¢' )
|
@YouCompleteMeInstance()
|
||||||
def FilterToCompletedCompletions_OldVim_Unicode_test( self, *args ):
|
def FilterToCompletedCompletions_OldVim_Unicode_test( ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
|
||||||
result = self._server_state._FilterToMatchingCompletions( completions,
|
result = ycm._FilterToMatchingCompletions( completions, False )
|
||||||
False )
|
assert_that( list( result ), empty() )
|
||||||
assert_that( list( result ), empty() )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, True )
|
||||||
eq_( result, True )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = "AAA" ) ]
|
completions = [ BuildCompletion( insertion_text = "AAA" ) ]
|
||||||
self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, False )
|
||||||
eq_( result, False )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, False )
|
||||||
eq_( result, False )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_Unicode_test(
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_Unicode_test(
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, True )
|
||||||
eq_( result, True )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
GetVariableValue_CompleteItemIs( 'Te' ) )
|
||||||
GetVariableValue_CompleteItemIs( 'Te' ) )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, True )
|
||||||
eq_( result, True )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
GetVariableValue_CompleteItemIs( 'X' ) )
|
||||||
GetVariableValue_CompleteItemIs( 'X' ) )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
||||||
self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
||||||
GetVariableValue_CompleteItemIs( 'Test' ) )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, False )
|
||||||
eq_( result, False )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
GetVariableValue_CompleteItemIs( ' Quote' ) )
|
||||||
GetVariableValue_CompleteItemIs( ' Quote' ) )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = "A" ) ]
|
completions = [ BuildCompletion( insertion_text = "A" ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, False )
|
||||||
eq_( result, False )
|
|
||||||
|
|
||||||
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
GetVariableValue_CompleteItemIs( 'Uniç' ) )
|
||||||
GetVariableValue_CompleteItemIs( 'Uniç' ) )
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
|
||||||
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
|
@YouCompleteMeInstance()
|
||||||
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_Unicode_test(
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_Unicode_test(
|
||||||
self, *args ):
|
ycm, *args ):
|
||||||
completions = [ BuildCompletion( insertion_text = "Uniçø∂¢" ) ]
|
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
|
||||||
result = self._server_state._HasCompletionsThatCouldBeCompletedWithMoreText(
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
||||||
completions )
|
eq_( result, True )
|
||||||
eq_( result, True )
|
|
||||||
|
|
||||||
|
@YouCompleteMeInstance()
|
||||||
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( self ):
|
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( ycm ):
|
||||||
eq_( None, self._server_state._GetRequiredNamespaceImport( {} ) )
|
eq_( None, ycm._GetRequiredNamespaceImport( {} ) )
|
||||||
|
|
||||||
|
|
||||||
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( self ):
|
@YouCompleteMeInstance()
|
||||||
namespace = 'A_NAMESPACE'
|
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( ycm ):
|
||||||
eq_( namespace, self._server_state._GetRequiredNamespaceImport(
|
namespace = 'A_NAMESPACE'
|
||||||
BuildCompletion( namespace )
|
eq_( namespace, ycm._GetRequiredNamespaceImport(
|
||||||
) )
|
BuildCompletion( namespace )
|
||||||
|
) )
|
||||||
|
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( self ):
|
|
||||||
with self._SetupForCsharpCompletionDone( [] ):
|
@YouCompleteMeInstance()
|
||||||
self._server_state._latest_completion_request.Done = MagicMock(
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( ycm ):
|
||||||
return_value = False )
|
with _SetupForCsharpCompletionDone( ycm, [] ):
|
||||||
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
|
ycm._latest_completion_request.Done = MagicMock( return_value = False )
|
||||||
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
|
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
GetVariableValue_CompleteItemIs( 'Te' ) )
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa
|
GetVariableValue_CompleteItemIs( 'Te' ) )
|
||||||
self, *args ):
|
@YouCompleteMeInstance()
|
||||||
completions = [ BuildCompletion( None ) ]
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
ycm, *args ):
|
||||||
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
|
completions = [ BuildCompletion( None ) ]
|
||||||
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa
|
|
||||||
self, *args ):
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
completions = [ BuildCompletion( None ) ]
|
@YouCompleteMeInstance()
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa
|
||||||
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' ):
|
ycm, *args ):
|
||||||
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
|
completions = [ BuildCompletion( None ) ]
|
||||||
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
|
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' ):
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test(
|
|
||||||
self, *args ):
|
|
||||||
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
completions = [ BuildCompletion( *info ) ]
|
@YouCompleteMeInstance()
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test(
|
||||||
with patch( 'ycm.vimsupport.GetVariableValue',
|
ycm, *args ):
|
||||||
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
||||||
eq_( completions,
|
completions = [ BuildCompletion( *info ) ]
|
||||||
self._server_state.GetCompletionsUserMayHaveCompleted() )
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa
|
|
||||||
self, *args ):
|
|
||||||
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
completions = [ BuildCompletion( *info ),
|
@YouCompleteMeInstance()
|
||||||
BuildCompletion( insertion_text = 'TestTest' ) ]
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
ycm, *args ):
|
||||||
with patch( 'ycm.vimsupport.GetVariableValue',
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
||||||
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
completions = [ BuildCompletion( *info ),
|
||||||
eq_( [ completions[ 0 ] ],
|
BuildCompletion( insertion_text = 'TestTest' ) ]
|
||||||
self._server_state.GetCompletionsUserMayHaveCompleted() )
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
eq_( [ completions[ 0 ] ], ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa
|
|
||||||
self, *args ):
|
|
||||||
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
|
@YouCompleteMeInstance()
|
||||||
BuildCompletion( insertion_text = 'TestTest' ) ]
|
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
ycm, *args ):
|
||||||
with patch( 'ycm.vimsupport.GetVariableValue',
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
||||||
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
|
||||||
eq_( [], self._server_state.GetCompletionsUserMayHaveCompleted() )
|
BuildCompletion( insertion_text = 'TestTest' ) ]
|
||||||
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
||||||
@patch( 'ycm.vimsupport.GetVariableValue',
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test(
|
|
||||||
self, *args ):
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
||||||
completions = [ BuildCompletion( None ) ]
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
||||||
eq_( completions,
|
@YouCompleteMeInstance()
|
||||||
self._server_state.GetCompletionsUserMayHaveCompleted() )
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test(
|
||||||
|
ycm, *args ):
|
||||||
|
completions = [ BuildCompletion( None ) ]
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test(
|
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
self, *args ):
|
|
||||||
completions = [ BuildCompletion( None ) ]
|
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
eq_( completions,
|
@YouCompleteMeInstance()
|
||||||
self._server_state.GetCompletionsUserMayHaveCompleted() )
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test(
|
||||||
|
ycm, *args ):
|
||||||
|
completions = [ BuildCompletion( None ) ]
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( self, *args ):
|
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
|
||||||
with self._SetupForCsharpCompletionDone( [] ):
|
|
||||||
self._server_state._OnCompleteDone_Csharp()
|
|
||||||
ok_( not vimsupport.InsertNamespace.called )
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( ycm, *args ):
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
with _SetupForCsharpCompletionDone( ycm, [] ):
|
||||||
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
|
ycm._OnCompleteDone_Csharp()
|
||||||
self, *args ):
|
ok_( not vimsupport.InsertNamespace.called )
|
||||||
completions = [ BuildCompletion( None ) ]
|
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
|
||||||
self._server_state._OnCompleteDone_Csharp()
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
ok_( not vimsupport.InsertNamespace.called )
|
@YouCompleteMeInstance()
|
||||||
|
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
|
||||||
|
ycm, *args ):
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
completions = [ BuildCompletion( None ) ]
|
||||||
def PostCompleteCsharp_ValueDoesInsertNamespace_test( self, *args ):
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
namespace = 'A_NAMESPACE'
|
ycm._OnCompleteDone_Csharp()
|
||||||
completions = [ BuildCompletion( namespace ) ]
|
ok_( not vimsupport.InsertNamespace.called )
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
|
||||||
self._server_state._OnCompleteDone_Csharp()
|
|
||||||
vimsupport.InsertNamespace.assert_called_once_with( namespace )
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
def PostCompleteCsharp_ValueDoesInsertNamespace_test( ycm, *args ):
|
||||||
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
namespace = 'A_NAMESPACE'
|
||||||
@patch( 'ycm.vimsupport.PresentDialog', return_value = 1 )
|
completions = [ BuildCompletion( namespace ) ]
|
||||||
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( self, *args ):
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
namespace = 'A_NAMESPACE'
|
ycm._OnCompleteDone_Csharp()
|
||||||
namespace2 = 'ANOTHER_NAMESPACE'
|
vimsupport.InsertNamespace.assert_called_once_with( namespace )
|
||||||
completions = [
|
|
||||||
BuildCompletion( namespace ),
|
|
||||||
BuildCompletion( namespace2 ),
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
||||||
]
|
@patch( 'ycm.vimsupport.PresentDialog', return_value = 1 )
|
||||||
with self._SetupForCsharpCompletionDone( completions ):
|
@YouCompleteMeInstance()
|
||||||
self._server_state._OnCompleteDone_Csharp()
|
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( ycm, *args ):
|
||||||
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
|
namespace = 'A_NAMESPACE'
|
||||||
|
namespace2 = 'ANOTHER_NAMESPACE'
|
||||||
|
completions = [
|
||||||
|
BuildCompletion( namespace ),
|
||||||
|
BuildCompletion( namespace2 ),
|
||||||
|
]
|
||||||
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
||||||
|
ycm._OnCompleteDone_Csharp()
|
||||||
|
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
|
||||||
|
@ -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()
|
|
@ -29,10 +29,9 @@ MockVimModule()
|
|||||||
import sys
|
import sys
|
||||||
from hamcrest import assert_that, is_in, is_not
|
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 ):
|
@YouCompleteMeInstance()
|
||||||
|
def YouCompleteMe_YcmCoreNotImported_test( ycm ):
|
||||||
def YcmCoreNotImported_test( self ):
|
assert_that( 'ycm_core', is_not( is_in( sys.modules ) ) )
|
||||||
assert_that( 'ycm_core', is_not( is_in( sys.modules ) ) )
|
|
||||||
|
Loading…
Reference in New Issue
Block a user