def test_Subcommands_StopServer_Timeout(self, app): StartJavaScriptCompleterServerInDirectory(app, PathToTestFile()) app.post_json( '/run_completer_command', BuildRequest(filetype='javascript', command_arguments=['StopServer'])) request_data = BuildRequest(filetype='javascript') assert_that( app.post_json('/debug_info', request_data).json, has_entry( 'completer', has_entry('servers', contains_exactly(has_entry('is_running', False)))))
def Subcommands_FixIt_Single_test( app ): fixit_test = PathToTestFile( 'testy', 'FixItTestCase.cs' ) with WrapOmniSharpServer( app, fixit_test ): contents = ReadFile( fixit_test ) request = BuildRequest( completer_target = 'filetype_default', command_arguments = [ 'FixIt' ], line_num = 4, column_num = 23, contents = contents, filetype = 'cs', filepath = fixit_test ) response = app.post_json( '/run_completer_command', request ).json LOGGER.debug( 'r = %s', response ) assert_that( response, has_entries( { 'fixits': contains_exactly( has_entries( { 'location': LocationMatcher( fixit_test, 4, 23 ), 'chunks': contains_exactly( has_entries( { 'replacement_text': '\n {\n NewMethod();\n }\n\n' ' private static void NewMethod()\n {\r\n', 'range': RangeMatcher( fixit_test, ( 3, 31 ), ( 4, 1 ) ) } ) ) } ) ) } ) )
def Subcommands_FixIt_Basic_test( app ): filepath = PathToTestFile( 'common', 'src', 'main.rs' ) RunTest( app, { 'description': 'Simple FixIt test', 'request': { 'command': 'FixIt', 'line_num': 17, 'column_num': 13, 'filepath': filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( ChunkMatcher( 'pub(crate) ', LocationMatcher( filepath, 17, 1 ), LocationMatcher( filepath, 17, 1 ) ) ) } ) ) } ) }, } )
def test_that_username_and_email_are_mutually_exclusive(self): query_string = {'email': '*****@*****.**', 'username': '******'} assert_that( calling(self.password_query_parameters_schema.load).with_args(query_string), raises( ValidationError, has_property( "messages", has_entries( _schema=contains_exactly('"username" or "email" should be used') ), ), ), )
def FixIt_Check_cpp11_DelAdd( results ): assert_that( results, has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( has_entries( { 'replacement_text': equal_to( '' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 48, 'column_num': 3 } ), 'end' : has_entries( { 'line_num': 48, 'column_num': 4 } ), } ), } ), has_entries( { 'replacement_text': equal_to( '~' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 48, 'column_num': 9 } ), 'end' : has_entries( { 'line_num': 48, 'column_num': 9 } ), } ), } ), ), 'location': has_entries( { 'line_num': 48, 'column_num': 3 } ) } ), has_entries( { 'chunks': contains_exactly( has_entries( { 'replacement_text': equal_to( '= default;' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 48, 'column_num': 15 } ), 'end' : has_entries( { 'line_num': 48, 'column_num': 17 } ), } ), } ), ), 'location': has_entries( { 'line_num': 48, 'column_num': 3 } ) } ), ) } ) )
def CppBindings_IdentifierCompleter_test(): identifier_completer = ycm_core.IdentifierCompleter() identifiers = ycm_core.StringVector() identifiers.append('foo') identifiers.append('bar') identifiers.append('baz') identifier_completer.ClearForFileAndAddIdentifiersToDatabase( identifiers, 'foo', 'file') del identifiers query_fo_10 = identifier_completer.CandidatesForQueryAndType( 'fo', 'foo', 10) query_fo = identifier_completer.CandidatesForQueryAndType('fo', 'foo') query_a = identifier_completer.CandidatesForQueryAndType('a', 'foo') assert_that(query_fo_10, contains_exactly('foo')) assert_that(query_fo, contains_exactly('foo')) assert_that(query_a, contains_exactly('bar', 'baz')) identifiers = ycm_core.StringVector() identifiers.append('oof') identifiers.append('rab') identifiers.append('zab') identifier_completer.ClearForFileAndAddIdentifiersToDatabase( identifiers, 'foo', 'file') query_a_10 = identifier_completer.CandidatesForQueryAndType('a', 'foo') assert_that(query_a_10, contains_exactly('rab', 'zab'))
def test_that_valid_configs_are_returned_when_one_fails(self): dirname = _new_tmp_dir() f1 = tempfile.NamedTemporaryFile('w+t', suffix='.yml') f1.writelines('test: one') f1.seek(0) f2 = tempfile.NamedTemporaryFile('w+t', suffix='.yml') f2.writelines('test: [:one :two]') f2.seek(0) res = self.parser.parse_config_dir(dirname) assert_that(res, contains_exactly({'test': 'one'})) self.error_handler.on_parse_config_dir_parse_exception.assert_called_once_with( os.path.basename(f2.name), ANY)
def MiscHandlers_SignatureHelp_ComputeSignatureThrows_test( compute_sig, app ): with PatchCompleter( DummyCompleter, filetype = 'dummy_filetype' ): request_data = BuildRequest( filetype = 'dummy_filetype' ) response = app.post_json( '/signature_help', request_data ).json print( response ) assert_that( response, has_entries( { 'signature_help': has_entries( { 'activeSignature': 0, 'activeParameter': 0, 'signatures': empty() } ), 'errors': contains_exactly( ErrorMatcher( RuntimeError, '' ) ) } ) )
def GenericLSPCompleter_GetCompletions_NotACompletionProvider_test( app ): completer = handlers._server_state.GetFiletypeCompleter( [ 'foo' ] ) with patch.object( completer, '_is_completion_provider', False ): request = BuildRequest( filepath = TEST_FILE, filetype = 'foo', line_num = 1, column_num = 3, contents = 'Java', event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', request ) WaitUntilCompleterServerReady( app, 'foo' ) request.pop( 'event_name' ) response = app.post_json( '/completions', BuildRequest( **request ) ) assert_that( response.json, has_entries( { 'completions': contains_exactly( CompletionEntryMatcher( 'Java', '[ID]' ) ) } ) )
def Subcommands_FixIt_ApplySuggestion_test(app): # Similarly to textDocument/formatting, if a file has errors # RLS won't respond with `rls.applySuggestions` command. project_dir = PathToTestFile('formatting') StartRustCompleterServerInDirectory(app, project_dir) filepath = os.path.join(project_dir, 'src', 'main.rs') RunTest( app, { 'description': 'Simple FixIt test', 'request': { 'command': 'FixIt', 'line_num': 8, 'column_num': 13, 'filepath': filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_exactly( ChunkMatcher('_x', LocationMatcher(filepath, 8, 13), LocationMatcher(filepath, 8, 14))) })) }) }, 'run_resolve_fixit_test': True })
def test_DebugInfo_ExtraConf_Global( self, app ): request_data = BuildRequest( filepath = PathToTestFile( 'foo.cpp' ), contents = '', filetype = 'cpp' ) test = { 'request': request_data } request_data[ 'contents' ] = '' RunAfterInitialized( app, test ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': contains_exactly( has_entries( { 'name': 'Clangd', 'is_running': True, 'extras': contains_exactly( has_entries( { 'key': 'Server State', 'value': 'Initialized', } ), has_entries( { 'key': 'Project Directory', 'value': PathToTestFile(), } ), has_entries( { 'key': 'Settings', 'value': '{}', } ), has_entries( { 'key': 'Compilation Command', 'value': has_items( '-I', 'test' ), } ), ), } ) ), 'items': empty() } ) ) )
def test_EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache( self, ycm, *args): current_buffer = VimBuffer(name='current_buffer', filetype='some_filetype') with patch('ycm.client.event_notification.EventNotification.' 'PostDataToHandlerAsync') as post_data_to_handler_async: with MockVimBuffers([current_buffer], [current_buffer]): ycm.OnFileReadyToParse() assert_that( # Positional arguments passed to PostDataToHandlerAsync. post_data_to_handler_async.call_args[0], contains_exactly( has_entry('syntax_keywords', has_items('foo', 'bar')), 'event_notification')) # Do not send again syntax keywords in subsequent requests. ycm.OnFileReadyToParse() assert_that( # Positional arguments passed to PostDataToHandlerAsync. post_data_to_handler_async.call_args[0], contains_exactly(is_not(has_key('syntax_keywords')), 'event_notification'))
def Subcommands_StopServer_NoErrorIfNotStarted_test(app): filepath = PathToTestFile('testy', 'GotoTestCase.cs') app.post_json( '/run_completer_command', BuildRequest(filetype='cs', filepath=filepath, command_arguments=['StopServer'])) request_data = BuildRequest(filetype='cs', filepath=filepath) assert_that( app.post_json('/debug_info', request_data).json, has_entry( 'completer', has_entry('servers', contains_exactly(has_entry('is_running', False)))))
def _Check_FileReadyToParse_Diagnostic_Warning(ycm): # Tests Vim sign placement/unplacement and error/warning count python API # 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() assert_that(ycm.FileParseRequestReady()) ycm.HandleFileParseRequest() assert_that( test_utils.VIM_SIGNS, contains_exactly( VimSign(SIGN_BUFFER_ID_INITIAL_VALUE + 2, 2, 'YcmWarning', 1))) assert_that(ycm.GetErrorCount(), equal_to(0)) assert_that(ycm.GetWarningCount(), equal_to(1)) # Consequent calls to HandleFileParseRequest shouldn't mess with # existing diagnostics, when there is no new parse request. ycm.HandleFileParseRequest() assert_that( test_utils.VIM_SIGNS, contains_exactly( VimSign(SIGN_BUFFER_ID_INITIAL_VALUE + 2, 2, 'YcmWarning', 1))) assert_that(ycm.GetErrorCount(), equal_to(0)) assert_that(ycm.GetWarningCount(), equal_to(1)) assert_that(not ycm.ShouldResendFileParseRequest())
def Subcommands_FixIt_Simple_test(app): filepath = PathToTestFile('goto.go') fixit = has_entries({ 'fixits': contains_exactly( has_entries({ 'text': "Organize Imports", 'chunks': contains_exactly( ChunkMatcher('', LocationMatcher(filepath, 8, 1), LocationMatcher(filepath, 9, 1)), ChunkMatcher('\tdummy() //GoTo\n', LocationMatcher(filepath, 9, 1), LocationMatcher(filepath, 9, 1)), ChunkMatcher('', LocationMatcher(filepath, 12, 1), LocationMatcher(filepath, 13, 1)), ChunkMatcher('\tdiagnostics_test\n', LocationMatcher(filepath, 13, 1), LocationMatcher(filepath, 13, 1)), ), }), ) }) RunFixItTest(app, 'Only one fixit returned', filepath, 1, 1, fixit)
def Subcommands_RefactorRename_test(app): filepath = PathToTestFile('unicode', 'unicode.go') RunTest( app, { 'description': 'RefactorRename on a function renames all its occurences', 'request': { 'command': 'RefactorRename', 'arguments': ['xxx'], 'line_num': 10, 'column_num': 17, 'filepath': filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'text': '', 'chunks': contains_exactly( ChunkMatcher('xxx', LocationMatcher(filepath, 3, 6), LocationMatcher(filepath, 3, 10)), ChunkMatcher( 'xxx', LocationMatcher(filepath, 10, 16), LocationMatcher(filepath, 10, 20)), ) })) }) } })
def bus_received_msg(): assert_that( msg_accumulator.accumulate(with_headers=True), contains_exactly( has_entries( message=has_entries( data={ 'uuid': session_uuid, 'user_uuid': user['uuid'], 'tenant_uuid': user['tenant_uuid'], 'mobile': True, }), headers=has_entry('tenant_uuid', user['tenant_uuid']), )), )
def FixIt_Check_cpp11_InsMultiLine( results ): # Similar to FixIt_Check_cpp11_1 but inserts split across lines # assert_that( results, has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( has_entries( { 'replacement_text': equal_to( 'static_cast<int>(' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 26, 'column_num': 7 } ), 'end' : has_entries( { 'line_num': 26, 'column_num': 7 } ), } ), } ), has_entries( { 'replacement_text': equal_to( ')' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 28, 'column_num': 2 } ), 'end' : has_entries( { 'line_num': 28, 'column_num': 2 } ), } ), } ) ), 'location': has_entries( { 'line_num': 25, 'column_num': 14 } ) } ) ) } ) )
def Diagnostics_SimpleLocationExtent_test(app): contents = """ void foo() { baz = 5; } // Padding to 5 lines // Padding to 5 lines """ filepath = PathToTestFile('foo.cc') request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'} test = {'request': request, 'route': '/receive_messages'} results = RunAfterInitialized(app, test) assert_that( results, contains_exactly( has_entries({ 'diagnostics': contains_exactly( has_entries({ 'location_extent': RangeMatcher(filepath, (3, 3), (3, 6)) })) })))
def ServerManagement_StopServerTwice_test(app): StartJavaCompleterServerInDirectory( app, PathToTestFile('simple_eclipse_project')) app.post_json( '/run_completer_command', BuildRequest( filetype='java', command_arguments=['StopServer'], ), ) request_data = BuildRequest(filetype='java') assert_that( app.post_json('/debug_info', request_data).json, has_entry( 'completer', has_entry('servers', contains_exactly(has_entry('is_running', False))))) # Stopping a stopped server is a no-op app.post_json( '/run_completer_command', BuildRequest( filetype='java', command_arguments=['StopServer'], ), ) request_data = BuildRequest(filetype='java') assert_that( app.post_json('/debug_info', request_data).json, has_entry( 'completer', has_entry('servers', contains_exactly(has_entry('is_running', False)))))
def test_ServerManagement_CloseServer_Unclean(self, app, *args): StartRustCompleterServerInDirectory(app, PathToTestFile('common', 'src')) app.post_json( '/run_completer_command', BuildRequest(filetype='rust', command_arguments=['StopServer'])) request_data = BuildRequest(filetype='rust') assert_that( app.post_json('/debug_info', request_data).json, has_entry( 'completer', has_entry('servers', contains_exactly(has_entry('is_running', False)))))
def test_email_confirmation_get(self, user): email_uuid = user['emails'][0]['uuid'] url = 'http://{}:{}/0.1/emails/{}/confirm'.format( self.auth_host, self.auth_port, email_uuid) token = self.client._token_id response = requests.get(url, params={'token': token}) assert_that(response.status_code, equal_to(200)) updated_user = self.client.users.get(user['uuid']) assert_that( updated_user, has_entries(emails=contains_exactly( has_entries(address='*****@*****.**', confirmed=True))), )
def bus_received_msg(): assert_that( msg_accumulator.accumulate(with_headers=True), contains_exactly( has_entries( message=has_entries( data={ 'user_uuid': user['uuid'], 'external_auth_name': 'foo', } ), headers=has_key('tenant_uuid'), ) ), )
def FixIt_Check_cpp11_Ins( results ): # First fixit # switch(A()) { // expected-error{{explicit conversion to}} assert_that( results, has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( has_entries( { 'replacement_text': equal_to( 'static_cast<int>(' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 16, 'column_num': 10 } ), 'end' : has_entries( { 'line_num': 16, 'column_num': 10 } ), } ), } ), has_entries( { 'replacement_text': equal_to( ')' ), 'range': has_entries( { 'start': has_entries( { 'line_num': 16, 'column_num': 13 } ), 'end' : has_entries( { 'line_num': 16, 'column_num': 13 } ), } ), } ) ), 'location': has_entries( { 'line_num': 16, 'column_num': 0 } ) } ) ) } ) )
def test_Signature_Help_Trigger(self, app): RunTest( app, { 'description': 'trigger after (', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('general_fallback', 'make_drink.cc'), 'line_num': 7, 'column_num': 14, 'signature_help_state': 'INACTIVE', }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'errors': empty(), 'signature_help': has_entries({ 'activeSignature': 0, 'activeParameter': 0, 'signatures': contains_exactly( SignatureMatcher( 'make_drink(TypeOfDrink type, ' 'Temperature temp, ' 'int sugargs) -> Drink &', [ ParameterMatcher(11, 27), ParameterMatcher(29, 45), ParameterMatcher(47, 58), ]), SignatureMatcher( 'make_drink(TypeOfDrink type, ' 'double fizziness, ' 'Flavour Flavour) -> Drink &', [ ParameterMatcher(11, 27), ParameterMatcher(29, 45), ParameterMatcher(47, 62), ]), ) }), }) }, })
def SendCompletionRequest_ResponseContainingError_test( post_vim_message, ycm ): current_buffer = VimBuffer( 'buffer' ) def ServerResponse( *args ): return { 'completions': [ { 'insertion_text': 'insertion_text', 'menu_text': 'menu_text', 'extra_menu_info': 'extra_menu_info', 'detailed_info': 'detailed_info', 'kind': 'kind', 'extra_data': { 'doc_string': 'doc_string' } } ], 'completion_start_column': 3, 'errors': [ { 'exception': { 'TYPE': 'Exception' }, 'message': 'message', 'traceback': 'traceback' } ] } with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockCompletionRequest( ServerResponse ): ycm.SendCompletionRequest() assert_that( ycm.CompletionRequestReady() ) response = ycm.GetCompletionResponse() post_vim_message.assert_has_exact_calls( [ call( 'Exception: message', truncate = True ) ] ) assert_that( response, has_entries( { 'completions': contains_exactly( has_entries( { 'word': 'insertion_text', 'abbr': 'menu_text', 'menu': 'extra_menu_info', 'info': 'detailed_info\ndoc_string', 'kind': 'k', 'dup': 1, 'empty': 1 } ) ), 'completion_start_column': 3 } ) )
def test_GetCompletions_Import_Classes(self, app): filepath = ProjectPath('TestLauncher.java') RunTest( app, { 'description': 'completion works for imports with multiple classes', 'request': { 'filetype': 'java', 'filepath': filepath, 'line_num': 4, 'column_num': 52, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 52, 'completions': contains_exactly( CompletionEntryMatcher( 'A;', None, { 'menu_text': 'A - com.test.wobble', 'kind': 'Class', }), CompletionEntryMatcher( 'A_Very_Long_Class_Here;', None, { 'menu_text': 'A_Very_Long_Class_Here - com.test.wobble', 'kind': 'Class', }), CompletionEntryMatcher( 'Waggle;', None, { 'menu_text': 'Waggle - com.test.wobble', 'kind': 'Interface', }), CompletionEntryMatcher( 'Wibble;', None, { 'menu_text': 'Wibble - com.test.wobble', 'kind': 'Enum', }), ), 'errors': empty(), }) }, })
def ServerManagement_WipeWorkspace_WithConfig_test( isolated_app ): with TemporaryTestDir() as tmp_dir: with isolated_app( { 'java_jdtls_use_clean_workspace': 0, 'java_jdtls_workspace_root_path': tmp_dir } ) as app: StartJavaCompleterServerInDirectory( app, PathToTestFile( 'simple_eclipse_project', 'src' ) ) project = PathToTestFile( 'simple_eclipse_project' ) filepath = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'youcompleteme', 'Test.java' ) app.post_json( '/run_completer_command', BuildRequest( filepath = filepath, filetype = 'java', command_arguments = [ 'WipeWorkspace', '--with-config' ], ), ) WaitUntilCompleterServerReady( app, 'java' ) assert_that( app.post_json( '/debug_info', BuildRequest( filetype = 'java', filepath = filepath ) ).json, CompleterProjectDirectoryMatcher( project ) ) assert_that( app.post_json( '/debug_info', BuildRequest( filetype = 'java', filepath = filepath ) ).json, has_entry( 'completer', has_entry( 'servers', contains_exactly( has_entry( 'extras', has_item( has_entries( { 'key': 'Workspace Path', 'value': starts_with( tmp_dir ), } ) ) ) ) ) ) )
def CppBindings_RangeVector_test(): flags = ycm_core.StringVector() flags.append('-xc++') clang_completer = ycm_core.ClangCompleter() translation_unit = PathToTestFile('foo.c') filename = PathToTestFile('foo.c') fixits = (clang_completer.GetFixItsForLocationInFile( translation_unit, filename, 3, 5, ycm_core.UnsavedFileVector(), flags, True)) fixit_range = fixits[0].chunks[0].range ranges = ycm_core.RangeVector() ranges.append(fixit_range) EmplaceBack(ranges, fixit_range) del flags del translation_unit del filename del clang_completer del fixits del fixit_range assert_that( ranges, contains_exactly( has_properties({ 'start_': has_properties({ 'line_number_': 3, 'column_number_': 16, }), 'end_': has_properties({ 'line_number_': 3, 'column_number_': 16, }), }), has_properties({ 'start_': has_properties({ 'line_number_': 3, 'column_number_': 16, }), 'end_': has_properties({ 'line_number_': 3, 'column_number_': 16, }), }), ))
def RunGoToTest_all( app, folder, command, test ): req = test[ 'req' ] filepath = PathToTestFile( folder, req[ 0 ] ) request = { 'completer_target' : 'filetype_default', 'filepath' : filepath, 'contents' : ReadFile( filepath ), 'filetype' : 'cpp', 'line_num' : req[ 1 ], 'column_num' : req[ 2 ], 'command_arguments': [ command ] + ( [] if len( req ) < 4 else req[ 3 ] ), } response = test[ 'res' ] if isinstance( response, list ): expect = { 'response': requests.codes.ok, 'data': contains_exactly( *[ LocationMatcher( PathToTestFile( folder, os.path.normpath( location[ 0 ] ) ), location[ 1 ], location[ 2 ], **( {} if len( location ) < 4 else location[ 3 ] ) ) for location in response ] ) } elif isinstance( response, tuple ): expect = { 'response': requests.codes.ok, 'data': LocationMatcher( PathToTestFile( folder, os.path.normpath( response[ 0 ] ) ), response[ 1 ], response[ 2 ], **( {} if len( response ) < 4 else response[ 3 ] ) ) } else: expect = { 'response': requests.codes.internal_server_error, 'data': ErrorMatcher( RuntimeError, test[ 'res' ] ) } RunAfterInitialized( app, { 'request': request, 'route' : '/run_completer_command', 'expect' : expect } )