From c01bc0481acd581a8c23ff2954c7e58a735974b1 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 24 Sep 2013 10:04:22 -0700 Subject: [PATCH] Refactoring the server tests to use a helper func This makes the tests smaller, less repetitive and easier to maintain. --- .../completers/all/identifier_completer.py | 1 + python/ycm/server/tests/basic_test.py | 72 ++++++++----------- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/python/ycm/completers/all/identifier_completer.py b/python/ycm/completers/all/identifier_completer.py index 5fb0b77a..b1f75db3 100644 --- a/python/ycm/completers/all/identifier_completer.py +++ b/python/ycm/completers/all/identifier_completer.py @@ -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: diff --git a/python/ycm/server/tests/basic_test.py b/python/ycm/server/tests/basic_test.py index 95fb7c03..e6ab628d 100644 --- a/python/ycm/server/tests/basic_test.py +++ b/python/ycm/server/tests/basic_test.py @@ -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' ) ],