def ModuleForSourceFile_GlobalExtraConf_test(self): filename = PathToTestFile('extra_conf', 'some_file') extra_conf_file = PathToTestFile('extra_conf', 'global_extra_conf.py') with UserOption('global_ycm_extra_conf', extra_conf_file): module = extra_conf_store.ModuleForSourceFile(filename) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(extra_conf_file))
def StopServer_KeepLogFiles( app, keeping_log_files ): with UserOption( 'server_keep_logfiles', keeping_log_files ): filepath = PathToTestFile( 'testy', 'GotoTestCase.cs' ) contents = ReadFile( filepath ) event_data = BuildRequest( filepath = filepath, filetype = 'cs', contents = contents, event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) WaitUntilCompleterServerReady( app, 'cs' ) event_data = BuildRequest( filetype = 'cs', filepath = filepath ) response = app.post_json( '/debug_info', event_data ).json logfiles = [] for server in response[ 'completer' ][ 'servers' ]: logfiles.extend( server[ 'logfiles' ] ) try: for logfile in logfiles: ok_( os.path.exists( logfile ), 'Logfile should exist at {0}'.format( logfile ) ) finally: StopCompleterServer( app, 'cs', filepath ) if keeping_log_files: for logfile in logfiles: ok_( os.path.exists( logfile ), 'Logfile should still exist at {0}'.format( logfile ) ) else: for logfile in logfiles: ok_( not os.path.exists( logfile ), 'Logfile should no longer exist at {0}'.format( logfile ) )
def GetCompletions_NoCompletionsWhenAutoTriggerOff_test( app ): with UserOption( 'auto_trigger', False ): app.post_json( '/ignore_extra_conf_file', { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } ) contents = """ struct Foo { int x; int y; char c; }; int main() { Foo foo; foo. } """ completion_data = BuildRequest( filepath = '/foo.cpp', filetype = 'cpp', contents = contents, line_num = 11, column_num = 7, compilation_flags = ['-x', 'c++'] ) results = app.post_json( '/completions', completion_data ).json[ 'completions' ] assert_that( results, empty() )
def CallGlobalExtraConfMethod_NoMethodInGlobalExtraConf_test(self, logger): with UserOption('global_ycm_extra_conf', PathToTestFile('extra_conf', 'global_extra_conf.py')): extra_conf_store._CallGlobalExtraConfMethod('MissingMethod') assert_that(logger.method_calls, has_length(1)) logger.debug.assert_called_with('Global extra conf not loaded or ' 'no function MissingMethod')
def GetCompletions_NonExistingRustSrcPathFromUserOption_test(app): with UserOption('rust_src_path', '/non/existing/rust/src/path'): response = app.get('/ready', { 'subserver': 'rust' }, expect_errors=True).json assert_that( response, ErrorMatcher(RuntimeError, NON_EXISTING_RUST_SOURCES_PATH_MESSAGE))
def CallGlobalExtraConfMethod_NoGlobalExtraConf_test(self, logger): with UserOption('global_ycm_extra_conf', PathToTestFile('extra_conf', 'no_extra_conf.py')): extra_conf_store._CallGlobalExtraConfMethod('SomeMethod') assert_that(logger.method_calls, has_length(1)) logger.debug.assert_called_with( 'No global extra conf, not calling method ' 'SomeMethod')
def ModuleForSourceFile_Whitelisted_test(self): filename = PathToTestFile('extra_conf', 'project', 'some_file') extra_conf_file = PathToTestFile('extra_conf', 'project', '.ycm_extra_conf.py') with UserOption('extra_conf_globlist', [extra_conf_file]): module = extra_conf_store.ModuleForSourceFile(filename) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(extra_conf_file))
def ModuleForSourceFile_NoConfirmation_test(self): filename = PathToTestFile('extra_conf', 'project', 'some_file') extra_conf_file = PathToTestFile('extra_conf', 'project', '.ycm_extra_conf.py') with UserOption('confirm_extra_conf', 0): module = extra_conf_store.ModuleForSourceFile(filename) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(extra_conf_file))
def CallGlobalExtraConfMethod_NoExceptionFromMethod_test(self, logger): extra_conf_file = PathToTestFile('extra_conf', 'global_extra_conf.py') with UserOption('global_ycm_extra_conf', extra_conf_file): extra_conf_store._CallGlobalExtraConfMethod('NoException') assert_that(logger.method_calls, has_length(1)) logger.info.assert_called_with('Calling global extra conf method ' 'NoException on conf file ' '{0}'.format(extra_conf_file))
def DebugInfo_ServerIsNotRunning_LogfilesDoNotExist_test( app ): with UserOption( 'server_keep_logfiles', False ): StopCompleterServer( app, 'javascript' ) request_data = BuildRequest( filetype = 'javascript' ) assert_that( app.post_json( '/debug_info', request_data ).json, matches_regexp( 'JavaScript completer debug information:\n' ' Tern is not running\n' ' Tern executable: .+' ) )
def WorkingDir_UseFilePath_test(): ok_(GetCurrentDirectory() != DATA_DIR, ('Please run this test from a ' 'different directory')) with UserOption('filepath_completion_use_working_dir', 0) as options: completer = FilenameCompleter(options) data = sorted(_CompletionResultsForLine(completer, 'ls ./include/')) eq_([('Qt', '[Dir]'), ('QtGui', '[Dir]')], data)
def DebugInfo_ServerIsNotRunning_LogfilesDoNotExist_test(app): with UserOption('server_keep_logfiles', False): StopGoCodeServer(app) subcommands_data = BuildRequest(completer_target='go') assert_that( app.post_json('/debug_info', subcommands_data).json, matches_regexp('Go completer debug information:\n' ' Gocode is not running\n' ' Gocode binary: .+\n' ' Godef binary: .+'))
def DebugInfo_ServerIsNotRunning_LogfilesDoNotExist_test(app): with UserOption('server_keep_logfiles', False): StopCompleterServer(app, 'python') request_data = BuildRequest(filetype='python') assert_that( app.post_json('/debug_info', request_data).json, matches_regexp('Python completer debug information:\n' ' JediHTTP is not running\n' ' JediHTTP executable: .+\n' ' Python interpreter: .+'))
def CallGlobalExtraConfMethod_CatchExceptionFromExtraConf_test( self, logger): extra_conf_file = PathToTestFile('extra_conf', 'erroneous_extra_conf.py') with UserOption('global_ycm_extra_conf', extra_conf_file): extra_conf_store._CallGlobalExtraConfMethod('NoException') assert_that(logger.method_calls, has_length(1)) logger.exception.assert_called_with('Error occurred while ' 'loading global extra conf ' '{0}'.format(extra_conf_file))
def DebugInfo_ServerIsNotRunning_LogfilesExist_test(app): with UserOption('server_keep_logfiles', True): StopCompleterServer(app, filetype='typescript') request_data = BuildRequest(filetype='typescript') assert_that( app.post_json('/debug_info', request_data).json, matches_regexp('TypeScript completer debug information:\n' ' TSServer no longer running\n' ' TSServer executable: .+\n' ' TSServer logfile: .+'))
def CallGlobalExtraConfMethod_CatchExceptionFromMethod_test(self, logger): extra_conf_file = PathToTestFile('extra_conf', 'global_extra_conf.py') with UserOption('global_ycm_extra_conf', extra_conf_file): extra_conf_store._CallGlobalExtraConfMethod('RaiseException') assert_that(logger.method_calls, has_length(2)) logger.info.assert_called_with('Calling global extra conf method ' 'RaiseException on conf file ' '{0}'.format(extra_conf_file)) logger.exception.assert_called_with( 'Error occurred while calling global extra conf method RaiseException ' 'on conf file {0}'.format(extra_conf_file))
def UserDefinedPython_WhenNonExistentPythonIsGiven_ReturnAnError_test( app, *args ): python = '/non/existing/path/python' with UserOption( 'python_binary_path', python ): response = app.get( '/ready', { 'subserver': 'python' }, expect_errors = True ).json msg = BINARY_NOT_FOUND_MESSAGE.format( python ) assert_that( response, ErrorMatcher( RuntimeError, msg ) ) utils.SafePopen.assert_not_called()
def GetCompletions_SemanticCompleter_WorksWhenTriggerIsIdentifier_test( app, *args): with UserOption('semantic_triggers', {'dummy_filetype': ['_']}): with PatchCompleter(DummyCompleter, 'dummy_filetype'): completion_data = BuildRequest(filetype='dummy_filetype', contents='some_can', column_num=9) results = app.post_json('/completions', completion_data).json['completions'] assert_that(results, has_items(CompletionEntryMatcher('some_candidate')))
def DebugInfo_ServerIsNotRunning_LogfilesExist_test(app): with UserOption('server_keep_logfiles', True): StopCompleterServer(app, 'rust') request_data = BuildRequest(filetype='rust') assert_that( app.post_json('/debug_info', request_data).json, matches_regexp('Rust completer debug information:\n' ' Racerd no longer running\n' ' Racerd executable: .+\n' ' Racerd logfiles:\n' ' .+\n' ' .+\n' ' Rust sources: .+'))
def GetCompletions_IdentifierCompleter_FilterShortCandidates_test( app ): with UserOption( 'min_num_identifier_candidate_chars', 4 ): event_data = BuildRequest( contents = 'foo foogoo gooo', event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) completion_data = BuildRequest( contents = 'oo', column_num = 3 ) response = app.post_json( '/completions', completion_data ).json[ 'completions' ] assert_that( response, contains_inanyorder( CompletionEntryMatcher( 'foogoo' ), CompletionEntryMatcher( 'gooo' ) ) )
def WorkingDir_UseServerWorkingDirectory_Unicode_test(): test_dir = os.path.join(TEST_DIR, 'testdata', 'filename_completer', '∂†∫') with CurrentWorkingDirectory(test_dir) as old_current_dir: ok_(old_current_dir != test_dir, ('Please run this test from a different ' 'directory')) with UserOption('filepath_completion_use_working_dir', 1) as options: completer = FilenameCompleter(options) # We don't supply working_dir in the request, so the current working # directory is used. data = sorted(_CompletionResultsForLine(completer, 'ls ./')) eq_([('†es†.txt', '[File]')], data)
def WorkingDir_UseClientWorkingDirectory_test(): test_dir = os.path.join(DATA_DIR, 'include') ok_(GetCurrentDirectory() != test_dir, ('Please run this test from a ' 'different directory')) with UserOption('filepath_completion_use_working_dir', 1) as options: completer = FilenameCompleter(options) # We supply working_dir in the request, so we expect results to be # relative to the supplied path. data = sorted( _CompletionResultsForLine(completer, 'ls ./', {'working_dir': test_dir})) eq_([('Qt', '[Dir]'), ('QtGui', '[Dir]')], data)
def GetCompletions_UltiSnipsCompleter_UnusedWhenOffWithOption_test( app ): with UserOption( 'use_ultisnips_completer', False ): event_data = BuildRequest( event_name = 'BufferVisit', ultisnips_snippets = [ {'trigger': 'foo', 'description': 'bar'}, {'trigger': 'zoo', 'description': 'goo'}, ] ) app.post_json( '/event_notification', event_data ) completion_data = BuildRequest( contents = 'oo ', column_num = 3 ) eq_( [], app.post_json( '/completions', completion_data ).json[ 'completions' ] )
def StopServer_KeepLogFiles(app, keeping_log_files): with UserOption('server_keep_logfiles', keeping_log_files): filepath = PathToTestFile('testy', 'GotoTestCase.cs') contents = ReadFile(filepath) event_data = BuildRequest(filepath=filepath, filetype='cs', contents=contents, event_name='FileReadyToParse') app.post_json('/event_notification', event_data) WaitUntilOmniSharpServerReady(app, filepath) event_data = BuildRequest(filetype='cs', filepath=filepath) debuginfo = app.post_json('/debug_info', event_data).json log_files_match = re.search("^OmniSharp logfiles:\n(.*)\n(.*)", debuginfo, re.MULTILINE) stdout_logfiles_location = log_files_match.group(1) stderr_logfiles_location = log_files_match.group(2) try: ok_(os.path.exists(stdout_logfiles_location), "Logfile should exist at {0}".format(stdout_logfiles_location)) ok_(os.path.exists(stderr_logfiles_location), "Logfile should exist at {0}".format(stderr_logfiles_location)) finally: StopOmniSharpServer(app, filepath) if keeping_log_files: ok_( os.path.exists(stdout_logfiles_location), "Logfile should still exist at " "{0}".format(stdout_logfiles_location)) ok_( os.path.exists(stderr_logfiles_location), "Logfile should still exist at " "{0}".format(stderr_logfiles_location)) else: ok_( not os.path.exists(stdout_logfiles_location), "Logfile should no longer exist at " "{0}".format(stdout_logfiles_location)) ok_( not os.path.exists(stderr_logfiles_location), "Logfile should no longer exist at " "{0}".format(stderr_logfiles_location))
def DebugInfo_ServerIsNotRunning_LogfilesDoNotExist_test(app): with UserOption('server_keep_logfiles', False): filepath = PathToTestFile('testy', 'Program.cs') contents = ReadFile(filepath) event_data = BuildRequest(filepath=filepath, filetype='cs', contents=contents, event_name='FileReadyToParse') app.post_json('/event_notification', event_data) WaitUntilCompleterServerReady(app, 'cs') StopCompleterServer(app, 'cs', filepath) request_data = BuildRequest(filepath=filepath, filetype='cs') assert_that( app.post_json('/debug_info', request_data).json, matches_regexp('C# completer debug information:\n' ' OmniSharp is not running\n' ' OmniSharp executable: .+\n' ' OmniSharp solution: .+'))
def UserDefinedPython_WhenExistingPythonIsGiven_ThatIsUsed_test(app, *args): python = '/existing/python' with UserOption('python_binary_path', python): app.get('/ready', {'subserver': 'python'}).json assert_that(utils.SafePopen, was_called_with_python(python))
def ModuleForSourceFile_Blacklisted_test(self): filename = PathToTestFile('extra_conf', 'project', 'some_file') extra_conf_file = PathToTestFile('extra_conf', 'project', '.ycm_extra_conf.py') with UserOption('extra_conf_globlist', ['!' + extra_conf_file]): assert_that(extra_conf_store.ModuleForSourceFile(filename), none())