Clean up YCM object in PostComplete tests

Move PostComplete tests inside a class that defines setUp and tearDown
methods. Clean YCM object in tearDown method. This fixes the error
"OSError: [WinError 6] The handle is invalid" on Windows with
Python 3.5.
This commit is contained in:
micbou 2016-02-29 05:04:12 +01:00
parent eb8a24f23d
commit b78c403cfe

View File

@ -26,13 +26,14 @@ from builtins import * # noqa
from ycm.test_utils import MockVimModule from ycm.test_utils import MockVimModule
MockVimModule() MockVimModule()
from mock import ( MagicMock, DEFAULT, patch ) import contextlib
from nose.tools import eq_
from hamcrest import assert_that, empty from hamcrest import assert_that, empty
from mock import MagicMock, DEFAULT, patch
from nose.tools import eq_, ok_
from ycm import vimsupport from ycm import vimsupport
from ycm.youcompleteme import YouCompleteMe from ycm.youcompleteme import YouCompleteMe
import contextlib
def GetVariableValue_CompleteItemIs( word, abbr = None, menu = None, def GetVariableValue_CompleteItemIs( word, abbr = None, menu = None,
info = None, kind = None ): info = None, kind = None ):
@ -45,28 +46,15 @@ def GetVariableValue_CompleteItemIs( word, abbr = None, menu = None,
'info': info, 'info': info,
'kind': kind, 'kind': kind,
} }
else: return DEFAULT
return DEFAULT
return MagicMock( side_effect = Result ) return MagicMock( side_effect = Result )
@contextlib.contextmanager def BuildCompletion( namespace = None, insertion_text = 'Test',
def _SetupForCsharpCompletionDone( completions ): menu_text = None, extra_menu_info = None,
with patch( 'ycm.vimsupport.InsertNamespace' ): detailed_info = None, kind = None ):
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
request = MagicMock();
request.Done = MagicMock( return_value = True )
request.RawResponse = MagicMock( return_value = completions )
ycm_state._latest_completion_request = request
yield ycm_state
def _BuildCompletion( namespace = None, insertion_text = 'Test',
menu_text = None, extra_menu_info = None,
detailed_info = None, kind = None ):
return { return {
'extra_data': { 'required_namespace_import' : namespace }, 'extra_data': { 'required_namespace_import': namespace },
'insertion_text': insertion_text, 'insertion_text': insertion_text,
'menu_text': menu_text, 'menu_text': menu_text,
'extra_menu_info': extra_menu_info, 'extra_menu_info': extra_menu_info,
@ -75,348 +63,363 @@ def _BuildCompletion( namespace = None, insertion_text = 'Test',
} }
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "cs" ] ) class PostComplete_test():
def GetCompleteDoneHooks_ResultOnCsharp_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
result = ycm_state.GetCompleteDoneHooks()
eq_( 1, len( list( result ) ) )
def setUp( self ):
self.ycm = YouCompleteMe( MagicMock( spec_set = dict ) )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
result = ycm_state.GetCompleteDoneHooks()
eq_( 0, len( list( result ) ) )
def tearDown( self ):
self.ycm.OnVimLeave()
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
def OnCompleteDone_WithActionCallsIt_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
action = MagicMock()
ycm_state._complete_done_hooks[ "txt" ] = action
ycm_state.OnCompleteDone()
assert action.called @contextlib.contextmanager
def _SetupForCsharpCompletionDone( self, completions ):
with patch( 'ycm.vimsupport.InsertNamespace' ):
with patch( 'ycm.vimsupport.TextBeforeCursor',
return_value = ' Test' ):
request = MagicMock()
request.Done = MagicMock( return_value = True )
request.RawResponse = MagicMock( return_value = completions )
self.ycm._latest_completion_request = request
yield
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] ) @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "cs" ] )
def OnCompleteDone_NoActionNoError_test( *args ): def GetCompleteDoneHooks_ResultOnCsharp_test( self, *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) ) result = self.ycm.GetCompleteDoneHooks()
eq_( 1, len( list( result ) ) )
ycm_state.OnCompleteDone()
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( self, *args ):
result = self.ycm.GetCompleteDoneHooks()
eq_( 0, len( list( result ) ) )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._FilterToMatchingCompletions( completions, False ) @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
def OnCompleteDone_WithActionCallsIt_test( self, *args ):
action = MagicMock()
self.ycm._complete_done_hooks[ "txt" ] = action
self.ycm.OnCompleteDone()
eq_( list( result ), completions ) ok_( action.called )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
@patch( 'ycm.vimsupport.GetVariableValue', def OnCompleteDone_NoActionNoError_test( self, *args ):
GetVariableValue_CompleteItemIs( 'A' ) ) self.ycm.OnCompleteDone()
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "AAA" ) ]
ycm_state._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( self, *args ):
completions = [ BuildCompletion( "Test" ) ]
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) result = self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._FilterToMatchingCompletions( completions, False ) eq_( list( result ), completions )
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 ):
completions = [ BuildCompletion( "AAA" ) ]
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( ' Quote' ) )
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "A" ) ]
result = ycm_state._FilterToMatchingCompletions( completions, False )
assert_that( list( result ), empty() ) @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Test' ) )
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( self,
*args ):
completions = [ BuildCompletion( "Test" ) ]
result = self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) eq_( list( result ), completions )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Test" )
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._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 ):
completions = [ BuildCompletion( "A" ) ]
result = self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) assert_that( list( result ), empty() )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "AAA" ) ]
ycm_state._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Test" )
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( self, *args ):
completions = [ BuildCompletion( "Test" ) ]
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) result = self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._FilterToMatchingCompletions( completions, False ) eq_( list( result ), completions )
eq_( list( result ), completions )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( self,
*args ):
completions = [ BuildCompletion( "AAA" ) ]
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "A" ) ]
result = ycm_state._FilterToMatchingCompletions( completions, False )
assert_that( list( result ), empty() ) @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( self,
*args ):
completions = [ BuildCompletion( "Test" ) ]
result = self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) eq_( list( result ), completions )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Te" )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test(
*args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, True ) @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( self,
*args ):
completions = [ BuildCompletion( "A" ) ]
result = self.ycm._FilterToMatchingCompletions( completions, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) assert_that( list( result ), empty() )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( *args ) :
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "AAA" ) ]
ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( 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 = " Te" )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( *args ): def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test(
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) ) self, *args ):
completions = [ _BuildCompletion( "Test" ) ] completions = [ BuildCompletion( "Test" ) ]
result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False ) eq_( result, True )
@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 = "X" )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( *args ): def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test(
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) ) self, *args ):
completions = [ _BuildCompletion( "A" ) ] completions = [ BuildCompletion( "AAA" ) ]
result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test(
self, *args ):
completions = [ BuildCompletion( "Test" ) ]
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( "Te") )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test(
*args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) eq_( result, False )
eq_( result, True )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test(
self, *args ):
completions = [ BuildCompletion( "A" ) ]
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( "X") )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
completions = [ _BuildCompletion( "AAA" ) ]
ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) 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( "Test" ) ) GetVariableValue_CompleteItemIs( "Te") )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test(
*args ): self, *args ):
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) ) completions = [ BuildCompletion( "Test" ) ]
completions = [ _BuildCompletion( "Test" ) ]
result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False ) 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( " Quote" ) ) GetVariableValue_CompleteItemIs( "X") )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( *args ): def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test(
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) ) self, *args ):
completions = [ _BuildCompletion( "A" ) ] completions = [ BuildCompletion( "AAA" ) ]
result = ycm_state._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
eq_( result, False )
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
@patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( "Test" ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test(
self, *args ):
completions = [ BuildCompletion( "Test" ) ]
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test(): result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
eq_( None, ycm_state._GetRequiredNamespaceImport( {} ) ) eq_( result, False )
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test(): @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
namespace = "A_NAMESPACE" @patch( 'ycm.vimsupport.GetVariableValue',
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) ) GetVariableValue_CompleteItemIs( " Quote" ) )
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test(
self, *args ):
completions = [ BuildCompletion( "A" ) ]
eq_( namespace, ycm_state._GetRequiredNamespaceImport( result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
_BuildCompletion( namespace )
))
eq_( result, False )
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test():
with _SetupForCsharpCompletionDone( [] ) as ycm_state:
ycm_state._latest_completion_request.Done = MagicMock( return_value = False )
eq_( [], ycm_state.GetCompletionsUserMayHaveCompleted() ) def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( self ):
eq_( None, self.ycm._GetRequiredNamespaceImport( {} ) )
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test(): def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( self ):
completions = [ _BuildCompletion( None ) ] namespace = "A_NAMESPACE"
with _SetupForCsharpCompletionDone( completions ) as ycm_state:
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Te' ) ):
eq_( [], ycm_state.GetCompletionsUserMayHaveCompleted() )
eq_( namespace, self.ycm._GetRequiredNamespaceImport(
BuildCompletion( namespace )
) )
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test(
*args ):
completions = [ _BuildCompletion( None ) ]
with _SetupForCsharpCompletionDone( completions ) as ycm_state:
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( 'Te' ) ):
eq_( [], ycm_state.GetCompletionsUserMayHaveCompleted() )
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( self ):
with self._SetupForCsharpCompletionDone( [] ):
self.ycm._latest_completion_request.Done = MagicMock(
return_value = False )
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test( eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
*args ):
info = [ "NS","Test", "Abbr", "Menu", "Info", "Kind" ]
completions = [ _BuildCompletion( *info ) ]
with _SetupForCsharpCompletionDone( completions ) as ycm_state:
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( completions, ycm_state.GetCompletionsUserMayHaveCompleted() )
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( *args ): def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test(
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ] self ):
completions = [ _BuildCompletion( *info ), completions = [ BuildCompletion( None ) ]
_BuildCompletion( insertion_text = "TestTest" ) ] with self._SetupForCsharpCompletionDone( completions ):
with _SetupForCsharpCompletionDone( completions ) as ycm_state: with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ): with patch( 'ycm.vimsupport.GetVariableValue',
with patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Te' ) ):
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ): eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
eq_( [ completions[ 0 ] ],
ycm_state.GetCompletionsUserMayHaveCompleted() )
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test(): def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test(
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ] self, *args ):
completions = [ _BuildCompletion( insertion_text = info[ 0 ] ), completions = [ BuildCompletion( None ) ]
_BuildCompletion( insertion_text = "TestTest" ) ] with self._SetupForCsharpCompletionDone( completions ):
with _SetupForCsharpCompletionDone( completions ) as ycm_state: with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ): with patch( 'ycm.vimsupport.GetVariableValue',
with patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Te' ) ):
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ): eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
eq_( [], ycm_state.GetCompletionsUserMayHaveCompleted() )
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test( *args ): def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test(
completions = [ _BuildCompletion( None ) ] self, *args ):
with _SetupForCsharpCompletionDone( completions ) as ycm_state: info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ): completions = [ BuildCompletion( *info ) ]
with patch( 'ycm.vimsupport.GetVariableValue', with self._SetupForCsharpCompletionDone( completions ):
GetVariableValue_CompleteItemIs( "Test" ) ): with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
eq_( completions, ycm_state.GetCompletionsUserMayHaveCompleted() ) with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test( *args ): def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test(
completions = [ _BuildCompletion( None ) ] self, *args ):
ycm_state = _SetupForCsharpCompletionDone( completions ) info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
with _SetupForCsharpCompletionDone( completions ) as ycm_state: completions = [ BuildCompletion( *info ),
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ): BuildCompletion( insertion_text = "TestTest" ) ]
eq_( completions, ycm_state.GetCompletionsUserMayHaveCompleted() ) with self._SetupForCsharpCompletionDone( completions ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( [ completions[ 0 ] ],
self.ycm.GetCompletionsUserMayHaveCompleted() )
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( *args ): def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test(
with _SetupForCsharpCompletionDone( [] ) as ycm_state: self ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ): info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
ycm_state._OnCompleteDone_Csharp() completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
BuildCompletion( insertion_text = "TestTest" ) ]
with self._SetupForCsharpCompletionDone( completions ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
assert not vimsupport.InsertNamespace.called def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test(
self, *args ):
completions = [ BuildCompletion( None ) ]
with self._SetupForCsharpCompletionDone( completions ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
with patch( 'ycm.vimsupport.GetVariableValue',
GetVariableValue_CompleteItemIs( "Test" ) ):
eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test( *args def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test(
): self, *args ):
completions = [ _BuildCompletion( None ) ] completions = [ BuildCompletion( None ) ]
with _SetupForCsharpCompletionDone( completions ) as ycm_state: with self._SetupForCsharpCompletionDone( completions ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ): with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
ycm_state._OnCompleteDone_Csharp() eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )
assert not vimsupport.InsertNamespace.called
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( self, *args ):
with self._SetupForCsharpCompletionDone( [] ):
def PostCompleteCsharp_ValueDoesInsertNamespace_test( *args ): with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
namespace = "A_NAMESPACE" self.ycm._OnCompleteDone_Csharp()
completions = [ _BuildCompletion( namespace ) ]
with _SetupForCsharpCompletionDone( completions ) as ycm_state: ok_( not vimsupport.InsertNamespace.called )
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
ycm_state._OnCompleteDone_Csharp()
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
vimsupport.InsertNamespace.assert_called_once_with( namespace ) self, *args ):
completions = [ BuildCompletion( None ) ]
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( *args ): with self._SetupForCsharpCompletionDone( completions ):
namespace = "A_NAMESPACE" with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
namespace2 = "ANOTHER_NAMESPACE" self.ycm._OnCompleteDone_Csharp()
completions = [
_BuildCompletion( namespace ), ok_( not vimsupport.InsertNamespace.called )
_BuildCompletion( namespace2 ),
]
with _SetupForCsharpCompletionDone( completions ) as ycm_state: def PostCompleteCsharp_ValueDoesInsertNamespace_test( self, *args ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ): namespace = "A_NAMESPACE"
with patch( 'ycm.vimsupport.PresentDialog', return_value = 1 ): completions = [ BuildCompletion( namespace ) ]
ycm_state._OnCompleteDone_Csharp() with self._SetupForCsharpCompletionDone( completions ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
vimsupport.InsertNamespace.assert_called_once_with( namespace2 ) self.ycm._OnCompleteDone_Csharp()
vimsupport.InsertNamespace.assert_called_once_with( namespace )
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( self, *args ):
namespace = "A_NAMESPACE"
namespace2 = "ANOTHER_NAMESPACE"
completions = [
BuildCompletion( namespace ),
BuildCompletion( namespace2 ),
]
with self._SetupForCsharpCompletionDone( completions ):
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
with patch( 'ycm.vimsupport.PresentDialog', return_value = 1 ):
self.ycm._OnCompleteDone_Csharp()
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )