Refactoring the server tests to use a helper func

This makes the tests smaller, less repetitive and easier to maintain.
This commit is contained in:
Strahinja Val Markovic 2013-09-24 10:04:22 -07:00
parent 3b9b9ed036
commit c01bc0481a
2 changed files with 29 additions and 44 deletions

View File

@ -133,6 +133,7 @@ class IdentifierCompleter( GeneralCompleter ):
ToUtf8IfNeeded( filetypes[ 0 ] ),
ToUtf8IfNeeded( filepath ) )
def OnFileReadyToParse( self, request_data ):
self.AddBufferIdentifiers( request_data )
if 'tag_files' in request_data:

View File

@ -25,39 +25,38 @@ import bottle
bottle.debug( True )
# 'contents' should be just one line of text
def RequestDataForFileWithContents( filename, contents ):
return {
'filetypes': ['foo'],
'filepath': filename,
'line_value': contents,
'file_data': {
filename: {
'contents': contents,
'filetypes': ['foo']
}
}
}
def GetCompletions_IdentifierCompleterWorks_test():
app = TestApp( server.app )
event_data = {
event_data = RequestDataForFileWithContents( '/foo/bar', 'foo foogoo ba' )
event_data.update( {
'event_name': 'FileReadyToParse',
'filetypes': ['foo'],
'filepath': '/foo/bar',
'file_data': {
'/foo/bar': {
'contents': 'foo foogoo ba',
'filetypes': ['foo']
}
}
}
} )
app.post_json( '/event_notification', event_data )
line_value = 'oo foo foogoo ba'
completion_data = {
completion_data = RequestDataForFileWithContents( '/foo/bar',
'oo foo foogoo ba' )
completion_data.update( {
'query': 'oo',
'filetypes': ['foo'],
'filepath': '/foo/bar',
'line_num': 0,
'column_num': 2,
'start_column': 0,
'line_value': line_value,
'file_data': {
'/foo/bar': {
'contents': line_value,
'filetypes': ['foo']
}
}
}
} )
eq_( [ BuildCompletionData( 'foo' ),
BuildCompletionData( 'foogoo' ) ],
@ -66,37 +65,22 @@ def GetCompletions_IdentifierCompleterWorks_test():
def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
app = TestApp( server.app )
event_data = {
event_data = RequestDataForFileWithContents( '/foo/bar', '' )
event_data.update( {
'event_name': 'FileReadyToParse',
'filetypes': ['foo'],
'filepath': '/foo/bar',
'file_data': {
'/foo/bar': {
'contents': '',
'filetypes': ['foo']
}
},
'syntax_keywords': ['foo', 'bar', 'zoo']
}
} )
app.post_json( '/event_notification', event_data )
line_value = 'oo '
completion_data = {
completion_data = RequestDataForFileWithContents( '/foo/bar',
'oo ' )
completion_data.update( {
'query': 'oo',
'filetypes': ['foo'],
'filepath': '/foo/bar',
'line_num': 0,
'column_num': 2,
'start_column': 0,
'line_value': line_value,
'file_data': {
'/foo/bar': {
'contents': line_value,
'filetypes': ['foo']
}
}
}
} )
eq_( [ BuildCompletionData( 'foo' ),
BuildCompletionData( 'zoo' ) ],