def RunTest(app, test): """ Method to run a simple completion test and verify the result test is a dictionary containing: 'request': kwargs for BuildRequest 'expect': { 'response': server response code (e.g. httplib.OK) 'data': matcher for the server response json } """ ClearCompletionsCache() contents = ReadFile(test['request']['filepath']) app.post_json('/event_notification', CombineRequest(test['request'], { 'event_name': 'FileReadyToParse', 'contents': contents, }), expect_errors=True) # We ignore errors here and we check the response code ourself. # This is to allow testing of requests returning errors. request = CombineRequest(test['request'], {'contents': contents}) response = app.post_json('/completions', request, expect_errors=True) print(f'completer response: { pformat( response.json ) }') assert_that(response.status_code, equal_to(test['expect']['response'])) assert_that(response.json, test['expect']['data']) return request, response.json
def app( request ): which = request.param[ 0 ] assert which == 'isolated' or which == 'shared' if which == 'isolated': with IsolatedApp( request.param[ 1 ] ) as app: yield app else: global shared_app ClearCompletionsCache() yield shared_app
def app( request ): which = request.param[ 0 ] assert which == 'isolated' or which == 'shared' if which == 'isolated': with IsolatedApp( {} ) as app: yield app StopCompleterServer( app, 'javascript' ) else: global shared_app ClearCompletionsCache() yield shared_app
def app(request): which = request.param[0] assert which == 'isolated' or which == 'shared' if which == 'isolated': with IsolatedApp({}) as app: yield app StopCompleterServer(app, 'rust') else: global shared_app ClearCompletionsCache() with IgnoreExtraConfOutsideTestsFolder(): yield shared_app
def app(request): which = request.param[0] assert which == 'isolated' or which == 'shared' if which == 'isolated': custom_options = request.param[1] with IsolatedApp(custom_options) as app: yield app else: global shared_app ClearCompletionsCache() with IgnoreExtraConfOutsideTestsFolder(): yield shared_app
def app(request): which = request.param[0] assert which == 'isolated' or which == 'shared' if which == 'isolated': custom_options = request.param[1] custom_options.update({'use_clangd': 0}) with IsolatedApp(custom_options) as app: yield app else: global shared_app ClearCompletionsCache() yield shared_app
def app(request): which = request.param[0] assert which == 'isolated' or which == 'shared' if which == 'isolated': with IsolatedApp(request.param[1]) as app: try: yield app finally: StopCompleterServer(app, 'go') else: global shared_app ClearCompletionsCache() yield shared_app
def app(request): which = request.param[0] assert which == 'isolated' or which == 'shared' if which == 'isolated': with IsolatedApp(request.param[1]) as app: clangd_completer.CLANGD_COMMAND = clangd_completer.NOT_CACHED yield app StopCompleterServer(app, 'cpp') else: global shared_app ClearCompletionsCache() with IgnoreExtraConfOutsideTestsFolder(): yield shared_app
def GetCompletions_FewerThan10_Resolved_test(app): ClearCompletionsCache() nl = os.linesep request, response = RunTest( app, { 'description': "More than 10 candiates after filtering, don't resolve", 'request': { 'filetype': 'java', 'filepath': ProjectPath('TestWithDocumentation.java'), 'line_num': 6, 'column_num': 10, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': has_item( CompletionEntryMatcher( 'useAString', 'MethodsWithDocumentation.useAString(String s) : void', { 'kind': 'Method', # This is the resolved info (no documentation) 'detailed_info': 'useAString(String s) : void\n' '\n' f'Multiple lines of description here.{ nl }' f'{ nl }' f' * **Parameters:**{ nl }' f' { nl }' f' * **s** a string' }), ), 'completion_start_column': 7, 'errors': empty(), }) }, }) # All items are resolved assert_that(response['completions'][0], is_not(has_key('resolve'))) assert_that(response['completions'][0], is_not(has_key('item'))) assert_that(response['completions'][-1], is_not(has_key('resolve'))) assert_that(response['completions'][-1], is_not(has_key('item')))
def app( request ): which = request.param[ 0 ] print( which ) assert which == 'isolated' or which == 'shared' if which == 'isolated': with patch( 'ycmd.completers.javascript.hook.' 'ShouldEnableTernCompleter', return_value = False ): with IsolatedApp( request.param[ 1 ] ) as app: try: yield app finally: StopCompleterServer( app, 'go' ) else: global shared_app ClearCompletionsCache() yield shared_app
def app(request): which = request.param[0] assert which == 'isolated' or which == 'shared' if which == 'isolated': custom_options = request.param[1] with IsolatedApp(custom_options) as app: yield app # Shutdown the isolated app for filepath in shared_filepaths.get(app, []): StopCompleterServer(app, 'cs', filepath) else: global shared_app ClearCompletionsCache() with IgnoreExtraConfOutsideTestsFolder(): yield shared_app
def app(request): which = request.param[0] print(which) assert which == 'isolated' or which == 'shared' if which == 'isolated': with patch( 'ycmd.completers.javascript.hook.' 'ShouldEnableTernCompleter', return_value=False): with IsolatedApp(request.param[1]) as app: yield app StopCompleterServer(app, 'javascript') else: global shared_app ClearCompletionsCache() with IgnoreExtraConfOutsideTestsFolder(): yield shared_app
def test_GetCompletions_MoreThan10ForceSemantic(self, app): ClearCompletionsCache() RunTest( app, { 'description': 'When forcing we pass the query, which reduces candidates', 'request': { 'filetype': 'java', 'filepath': ProjectPath('TestLauncher.java'), 'line_num': 4, 'column_num': 15, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': contains_exactly( CompletionEntryMatcher( 'com.youcompleteme.*;', None, { 'kind': 'Module', 'detailed_info': 'com.youcompleteme\n\n', }), CompletionEntryMatcher( 'com.youcompleteme.testing.*;', None, { 'kind': 'Module', 'detailed_info': 'com.youcompleteme.testing\n\n', }), ), 'completion_start_column': 8, 'errors': empty(), }) }, })
def Wrapper(test_case_instance, *args, **kwargs): ClearCompletionsCache() with IgnoreExtraConfOutsideTestsFolder(): return test(test_case_instance, shared_app, *args, **kwargs)
def Wrapper(*args, **kwargs): ClearCompletionsCache() return test(shared_app, *args, **kwargs)
def Wrapper( test_case_instance, *args, **kwargs ): ClearCompletionsCache() return test( test_case_instance, shared_app, *args, **kwargs )
def Wrapper(*args, **kwargs): WriteBasicExampleCompilationDatabase() ClearCompletionsCache() return test(shared_app, *args, **kwargs)
def EventNotification_OnBufferUnload_CloseFile_test( app ): # Open main.ts file in a buffer. main_filepath = PathToTestFile( 'buffer_unload', 'main.ts' ) main_contents = ReadFile( main_filepath ) event_data = BuildRequest( filepath = main_filepath, filetype = 'typescript', contents = main_contents, event_name = 'BufferVisit' ) app.post_json( '/event_notification', event_data ) # Complete in main.ts buffer an object defined in imported.ts. completion_data = BuildRequest( filepath = main_filepath, filetype = 'typescript', contents = main_contents, line_num = 3, column_num = 10 ) response = app.post_json( '/completions', completion_data ) assert_that( response.json, has_entries( { 'completions': contains( CompletionEntryMatcher( 'method' ) ) } ) ) # FIXME: we should not have to clear the cache. ClearCompletionsCache() # Open imported.ts file in another buffer. imported_filepath = PathToTestFile( 'buffer_unload', 'imported.ts' ) imported_contents = ReadFile( imported_filepath ) event_data = BuildRequest( filepath = imported_filepath, filetype = 'typescript', contents = imported_contents, event_name = 'BufferVisit' ) app.post_json( '/event_notification', event_data ) # Modify imported.ts buffer without writing the changes to disk. modified_imported_contents = imported_contents.replace( 'method', 'modified_method' ) # FIXME: TypeScript completer should not rely on the FileReadyToParse events # to synchronize the contents of dirty buffers but use instead the file_data # field of the request. event_data = BuildRequest( filepath = imported_filepath, filetype = 'typescript', contents = modified_imported_contents, event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) # Complete at same location in main.ts buffer. imported_data = { imported_filepath: { 'filetypes': [ 'typescript' ], 'contents': modified_imported_contents } } completion_data = BuildRequest( filepath = main_filepath, filetype = 'typescript', contents = main_contents, line_num = 3, column_num = 10, file_data = imported_data ) response = app.post_json( '/completions', completion_data ) assert_that( response.json, has_entries( { 'completions': contains( CompletionEntryMatcher( 'modified_method' ) ) } ) ) # FIXME: we should not have to clear the cache. ClearCompletionsCache() # Unload imported.ts buffer. event_data = BuildRequest( filepath = imported_filepath, filetype = 'typescript', contents = imported_contents, event_name = 'BufferUnload' ) app.post_json( '/event_notification', event_data ) # Complete at same location in main.ts buffer. completion_data = BuildRequest( filepath = main_filepath, filetype = 'typescript', contents = main_contents, line_num = 3, column_num = 10 ) response = app.post_json( '/completions', completion_data ) assert_that( response.json, has_entries( { 'completions': contains( CompletionEntryMatcher( 'method' ) ) } ) )
def GetCompletions_MoreThan10_NoResolve_ThenResolveCacheBad_test(app): ClearCompletionsCache() request, response = RunTest( app, { 'description': "More than 10 candiates after filtering, don't resolve", 'request': { 'filetype': 'java', 'filepath': ProjectPath('TestWithDocumentation.java'), 'line_num': 6, 'column_num': 7, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': has_item( CompletionEntryMatcher( 'useAString', 'MethodsWithDocumentation.useAString(String s) : void', { 'kind': 'Method', # This is the un-resolved info (no documentation) 'detailed_info': 'useAString(String s) : void\n\n', 'extra_data': has_entries({'resolve': instance_of(int)}) }), ), 'completion_start_column': 7, 'errors': empty(), }) }, }) # We know the item we want is there, pull out the resolve ID resolve = None for item in response['completions']: if item['insertion_text'] == 'useAString': resolve = item['extra_data']['resolve'] break assert resolve is not None request['resolve'] = resolve # Use a different position - should mean the cache is not valid for request request['column_num'] = 20 response = app.post_json('/resolve_completion', request).json print(f"Resolve response: { pformat( response ) }") assert_that( response, has_entries({ 'completion': None, 'errors': contains_exactly(ErrorMatcher(CompletionsChanged)) }))
def GetCompletions_MoreThan10_NoResolve_ThenResolve_test(app): ClearCompletionsCache() request, response = RunTest( app, { 'description': "More than 10 candiates after filtering, don't resolve", 'request': { 'filetype': 'java', 'filepath': ProjectPath('TestWithDocumentation.java'), 'line_num': 6, 'column_num': 7, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': has_item( CompletionEntryMatcher( 'useAString', 'MethodsWithDocumentation.useAString(String s) : void', { 'kind': 'Method', # This is the un-resolved info (no documentation) 'detailed_info': 'useAString(String s) : void\n\n', 'extra_data': has_entries({'resolve': instance_of(int)}) }), ), 'completion_start_column': 7, 'errors': empty(), }) }, }) # We know the item we want is there, pull out the resolve ID resolve = None for item in response['completions']: if item['insertion_text'] == 'useAString': resolve = item['extra_data']['resolve'] break assert resolve is not None request['resolve'] = resolve # Do this twice to prove that the request is idempotent for i in range(2): response = app.post_json('/resolve_completion', request).json print(f"Resolve response: { pformat( response ) }") nl = os.linesep assert_that( response, has_entries({ 'completion': CompletionEntryMatcher( 'useAString', 'MethodsWithDocumentation.useAString(String s) : void', { 'kind': 'Method', # This is the resolved info (no documentation) 'detailed_info': 'useAString(String s) : void\n' '\n' f'Multiple lines of description here.{ nl }' f'{ nl }' f' * **Parameters:**{ nl }' f' { nl }' f' * **s** a string' }), 'errors': empty(), })) # The item is resoled assert_that(response['completion'], is_not(has_key('resolve'))) assert_that(response['completion'], is_not(has_key('item')))