def GetCompletions_NoCompletionsWhenAutoTriggerOff_test( app ): RunTest( app, { 'description': 'no completions on . when auto trigger is off', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile( 'foo.cc' ), 'contents': """ struct Foo { int x; int y; char c; }; int main() { Foo foo; foo. } """, 'line_num': 11, 'column_num': 7 }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': empty(), 'errors': empty() } ) }, } )
def GetCompletions_IgoreNonJSFiles_test(app): trivial1 = {"filetypes": ["python"], "contents": ReadFile(PathToTestFile("trivial.js"))} trivial2 = {"filetypes": ["javascript"], "contents": ReadFile(PathToTestFile("trivial2.js"))} request = { "line_num": 1, "column_num": 3, "file_data": {PathToTestFile("trivial.js"): trivial1, PathToTestFile("trivial2.js"): trivial2}, } app.post_json( "/event_notification", _Merge(request, {"filepath": PathToTestFile("trivial2.js"), "event_name": "FileReadyToParse"}), ) response = app.post_json("/completions", _Merge(request, {"filepath": PathToTestFile("trivial2.js")})).json print("completer response: {0}".format(pformat(response, indent=2))) assert_that( response, has_entries( { "completion_start_column": 3, # Note: we do *not* see X.y and X.z because tern is not told about # the trivial.js file because we pretended it was Python "completions": empty(), "errors": empty(), } ), )
def Diagnostics_NoLimitToNumberOfDiagnostics_test( app ): filepath = PathToTestFile( 'max_diagnostics.cc' ) contents = ReadFile( filepath ) event_data = BuildRequest( contents = contents, event_name = 'FileReadyToParse', filetype = 'cpp', filepath = filepath, compilation_flags = [ '-x', 'c++' ] ) response = app.post_json( '/event_notification', event_data ).json pprint( response ) assert_that( response, contains( has_entries( { 'kind': equal_to( 'ERROR' ), 'location': LocationMatcher( filepath, 3, 9 ), 'location_extent': RangeMatcher( filepath, ( 3, 9 ), ( 3, 13 ) ), 'ranges': empty(), 'text': equal_to( "redefinition of 'test'" ), 'fixit_available': False } ), has_entries( { 'kind': equal_to( 'ERROR' ), 'location': LocationMatcher( filepath, 4, 9 ), 'location_extent': RangeMatcher( filepath, ( 4, 9 ), ( 4, 13 ) ), 'ranges': empty(), 'text': equal_to( "redefinition of 'test'" ), 'fixit_available': False } ) ) )
def GetCompletions_ForceSemantic_NoSemanticCompleter_test( app, *args ): event_data = BuildRequest( event_name = 'FileReadyToParse', filetype = 'dummy_filetype', contents = 'complete_this_word\ncom' ) app.post_json( '/event_notification', event_data ) completion_data = BuildRequest( filetype = 'dummy_filetype', force_semantic = True, contents = 'complete_this_word\ncom', line_number = 2, column_num = 4 ) results = app.post_json( '/completions', completion_data ).json assert_that( results, has_entries( { 'completions': empty(), 'errors': empty(), } ) ) # For proof, show that non-forced completion would return identifiers completion_data = BuildRequest( filetype = 'dummy_filetype', contents = 'complete_this_word\ncom', line_number = 2, column_num = 4 ) results = app.post_json( '/completions', completion_data ).json assert_that( results, has_entries( { 'completions': contains( CompletionEntryMatcher( 'com' ), CompletionEntryMatcher( 'complete_this_word' ) ), 'errors': empty(), } ) )
def GetCompletions_ForceSemantic_NoYcmdCache_test( app ): RunTest( app, { 'description': 'no completions are returned when using Clangd filtering', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile( 'foo.cc' ), 'contents': """ int main() { int foobar; int floozar; int gooboo; int bleble; fooar } """, 'line_num': 9, 'column_num': 8, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': empty(), 'errors': empty() } ) }, } )
def Subcommands_ServerNotReady_test( app ): filepath = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'test', 'AbstractTestWidget.java' ) completer = handlers._server_state.GetFiletypeCompleter( [ 'java' ] ) with patch.object( completer, 'ServerIsReady', return_value = False ): RunTest( app, { 'description': 'Completion works for unicode identifier', 'request': { 'filetype' : 'java', 'filepath' : filepath, 'line_num' : 16, 'column_num' : 35, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'errors': empty(), 'completions': empty(), 'completion_start_column': 6 } ), } } )
def test_creates_an_empty_vlan(self): self.client.add_vlan(1000) vlan = self.get_vlan_from_list(1000) assert_that(vlan.number, is_(1000)) assert_that(vlan.name, is_(none())) assert_that(vlan.access_groups[IN], is_(none())) assert_that(vlan.access_groups[OUT], is_(none())) assert_that(vlan.vrf_forwarding, is_(none())) assert_that(vlan.ips, is_(empty())) assert_that(vlan.vrrp_groups, is_(empty())) assert_that(vlan.dhcp_relay_servers, is_(empty()))
def test_should_remove_trigger_from_db(self): shutil.copyfile(self.test_db_file, self.temp_file.name) store = LightsSqliteStore(self.temp_file.name) store.remove_trigger(self.trigger.job_id) conn = sqlite3.connect(self.temp_file.name) cursor = conn.cursor() rows = cursor.execute("SELECT * FROM triggers").fetchall() assert_that(rows, is_(empty())) triggers = store.read_triggers() assert_that(triggers, is_(empty()))
def GetCompletions_Require_NoQuery_test(app): RunTest( app, { "description": "semantic completion works for simple object no query", "request": { "filetype": "javascript", "filepath": PathToTestFile("requirejs_test.js"), "line_num": 2, "column_num": 15, }, "expect": { "response": http.client.OK, "data": has_entries( { "completions": contains_inanyorder( CompletionEntryMatcher("mine_bitcoin", "fn(how_much: ?) -> number"), CompletionEntryMatcher("get_number", "number"), CompletionEntryMatcher("get_string", "string"), CompletionEntryMatcher("get_thing", "fn(a: ?) -> number|string"), CompletionEntryMatcher("toString", "fn() -> string"), CompletionEntryMatcher("toLocaleString", "fn() -> string"), CompletionEntryMatcher("valueOf", "fn() -> number"), CompletionEntryMatcher("hasOwnProperty", "fn(prop: string) -> bool"), CompletionEntryMatcher("isPrototypeOf", "fn(obj: ?) -> bool"), CompletionEntryMatcher("propertyIsEnumerable", "fn(prop: string) -> bool"), ), "errors": empty(), } ), }, }, )
def GetCompletions_FilteredNoResults_Fallback_test( app ): # no errors because the semantic completer returned results, but they # were filtered out by the query, so this is considered working OK # (whereas no completions from the semantic engine is considered an # error) # TESTCASE5 (general_fallback/lang_cpp.cc) RunTest( app, { 'description': '. on struct returns IDs after query=do_', 'request': { 'filetype': 'c', 'filepath': PathToTestFile( 'general_fallback', 'lang_c.c' ), 'line_num': 71, 'column_num': 18, 'extra_conf_data': { '&filetype': 'c' }, 'force_semantic': False, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains_inanyorder( # do_ is an identifier because it is already in the file when we # load it CompletionEntryMatcher( 'do_', '[ID]' ), CompletionEntryMatcher( 'do_something', '[ID]' ), CompletionEntryMatcher( 'do_another_thing', '[ID]' ), ), 'errors': empty() } ) }, } )
def GetCompletions_NoSuggestions_Fallback_test( app ): # Python completer doesn't raise NO_COMPLETIONS_MESSAGE, so this is a # different code path to the Clang completer cases # TESTCASE2 (general_fallback/lang_python.py) RunTest( app, { 'description': 'param jedi does not know about (id). query="a_p"', 'request': { 'filetype' : 'python', 'filepath' : PathToTestFile( 'general_fallback', 'lang_python.py' ), 'line_num' : 28, 'column_num': 20, 'force_semantic': False, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains( CompletionEntryMatcher( 'a_parameter', '[ID]' ), CompletionEntryMatcher( 'another_parameter', '[ID]' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_Unicode_InFile_test(app): RunTest( app, { "description": "completions work with unicode chars in the file", "request": { "filetype": "javascript", "filepath": PathToTestFile("unicode.js"), "line_num": 3, "column_num": 16, }, "expect": { "response": http.client.OK, "data": has_entries( { "completions": contains_inanyorder( CompletionEntryMatcher("charAt", "fn(i: number) -> string"), CompletionEntryMatcher("charCodeAt", "fn(i: number) -> number"), ), "completion_start_column": 13, "errors": empty(), } ), }, }, )
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( self, *args ): completions = [ BuildCompletion( "A" ) ] result = self.ycm._FilterToMatchingCompletions( completions, False ) assert_that( list( result ), empty() )
def test_download_datapackage(self, helpers, config, test_datapackages_path, api_client, dataset_key): datapackage_zip = path.join(test_datapackages_path, 'the-simpsons-by-the-data.zip') with responses.RequestsMock() as rsps, open(datapackage_zip, 'rb') as file: @helpers.validate_request_headers() def datapackage_endpoint(_): return 200, {}, file.read() rsps.add_callback( rsps.GET, 'https://download.data.world/datapackage/agentid/datasetid', datapackage_endpoint) datapackage = api_client.download_datapackage(dataset_key, config.cache_dir) assert_that(datapackage, equal_to( path.join(config.cache_dir, 'datapackage.json'))) assert_that(path.isfile(datapackage), described_as('%0 is a file', is_(True), datapackage)) data_subdirectory = path.join(config.cache_dir, 'data') assert_that(path.isdir(data_subdirectory), described_as('%0 is a directory', is_(True), data_subdirectory)) assert_that(os.listdir(config.tmp_dir), described_as('%0 is empty', empty(), config.tmp_dir))
def GetCompletions_ClangCompleter_NoCompletionsWhenAutoTriggerOff_test(): ChangeSpecificOptions( { 'auto_trigger': False } ) app = TestApp( handlers.app ) contents = """ struct Foo { int x; int y; char c; }; int main() { Foo foo; foo. } """ # 0-based line and column! completion_data = BuildRequest( filepath = '/foo.cpp', filetype = 'cpp', contents = contents, line_num = 11, column_num = 7, start_column = 7, compilation_flags = ['-x', 'c++'] ) results = app.post_json( '/completions', completion_data ).json assert_that( results, empty() )
def test_starts_actions_and_adds_back_to_queue(self): # given start_time = 0 deadline = 10 action_to_start = Action(start_time, deadline+1) action_to_start.agent = Mock(name="agent") action_to_start.is_applicable = Mock(return_val=True) action_to_start.apply = Mock(name="apply") model = Mock(name="model") execution_queue = PriorityQueue() execution_queue.put(ActionState(action_to_start, start_time, ExecutionState.pre_start)) # when actual, _stalled = simulator.execute_action_queue(model, execution_queue, break_on_new_knowledge=False, deadline=deadline) # then assert_that(execution_queue.queue, has_length(1)) time, state, action = execution_queue.queue[0] assert_that(time, equal_to(action_to_start.end_time)) assert_that(state, equal_to(ExecutionState.executing)) assert_that(action, equal_to(action_to_start)) assert_that(actual.executed, is_(empty())) assert_that(is_not(action_to_start.apply.called)) assert_that(actual.simulation_time, equal_to(start_time))
def DebugInfo_ServerIsRunning_test( app ): 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' ) request_data = BuildRequest( filepath = filepath, filetype = 'cs' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C#', 'servers': contains( has_entries( { 'name': 'OmniSharp', 'is_running': True, 'executable': instance_of( str ), 'pid': instance_of( int ), 'address': instance_of( str ), 'port': instance_of( int ), 'logfiles': contains( instance_of( str ), instance_of( str ) ), 'extras': contains( has_entries( { 'key': 'solution', 'value': instance_of( str ) } ) ) } ) ), 'items': empty() } ) ) )
def GetCompletions_Require_NoQuery_test( app ): RunTest( app, { 'description': 'semantic completion works for simple object no query', 'request': { 'filetype' : 'javascript', 'filepath' : PathToTestFile( 'requirejs_test.js' ), 'line_num' : 2, 'column_num': 15, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains_inanyorder( CompletionEntryMatcher( 'mine_bitcoin', 'fn(how_much: ?) -> number' ), CompletionEntryMatcher( 'get_number', 'number' ), CompletionEntryMatcher( 'get_string', 'string' ), CompletionEntryMatcher( 'get_thing', 'fn(a: ?) -> number|string' ), CompletionEntryMatcher( 'toString', 'fn() -> string' ), CompletionEntryMatcher( 'toLocaleString', 'fn() -> string' ), CompletionEntryMatcher( 'valueOf', 'fn() -> number' ), CompletionEntryMatcher( 'hasOwnProperty', 'fn(prop: string) -> bool' ), CompletionEntryMatcher( 'isPrototypeOf', 'fn(obj: ?) -> bool' ), CompletionEntryMatcher( 'propertyIsEnumerable', 'fn(prop: string) -> bool' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_ReturnsDocsInCompletions_test( app ): # This tests that we supply docs for completions RunTest( app, { 'description': 'completions supply docs', 'request': { 'filetype' : 'javascript', 'filepath' : PathToTestFile( 'requirejs_test.js' ), 'line_num' : 8, 'column_num': 15, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains_inanyorder( CompletionEntryMatcher( 'a_function', 'fn(bar: ?) -> {a_value: string}', { 'detailed_info': ( 'fn(bar: ?) -> {a_value: string}\n' 'This is a short documentation string' ), } ), CompletionEntryMatcher( 'options', 'options' ), CompletionEntryMatcher( 'toString', 'fn() -> string' ), CompletionEntryMatcher( 'toLocaleString', 'fn() -> string' ), CompletionEntryMatcher( 'valueOf', 'fn() -> number' ), CompletionEntryMatcher( 'hasOwnProperty', 'fn(prop: string) -> bool' ), CompletionEntryMatcher( 'isPrototypeOf', 'fn(obj: ?) -> bool' ), CompletionEntryMatcher( 'propertyIsEnumerable', 'fn(prop: string) -> bool' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_Require_Query_LCS_test(app): RunTest( app, { "description": ("completion works for require object " "with query not prefix"), "request": { "filetype": "javascript", "filepath": PathToTestFile("requirejs_test.js"), "line_num": 4, "column_num": 17, }, "expect": { "response": http.client.OK, "data": has_entries( { "completions": contains( CompletionEntryMatcher("get_number", "number"), CompletionEntryMatcher("get_thing", "fn(a: ?) -> number|string"), CompletionEntryMatcher("get_string", "string"), ), "errors": empty(), } ), }, }, )
def GetCompletions_NoQuery_test(app): RunTest( app, { "description": "semantic completion works for simple object no query", "request": { "filetype": "javascript", "filepath": PathToTestFile("simple_test.js"), "line_num": 13, "column_num": 43, }, "expect": { "response": http.client.OK, "data": has_entries( { "completions": contains_inanyorder( CompletionEntryMatcher("a_simple_function", "fn(param: ?) -> string"), CompletionEntryMatcher("basic_type", "number"), CompletionEntryMatcher("object", "object"), CompletionEntryMatcher("toString", "fn() -> string"), CompletionEntryMatcher("toLocaleString", "fn() -> string"), CompletionEntryMatcher("valueOf", "fn() -> number"), CompletionEntryMatcher("hasOwnProperty", "fn(prop: string) -> bool"), CompletionEntryMatcher("isPrototypeOf", "fn(obj: ?) -> bool"), CompletionEntryMatcher("propertyIsEnumerable", "fn(prop: string) -> bool"), ), "errors": empty(), } ), }, }, )
def GetCompletions_CsCompleter_NonForcedReturnsNoResults_test(): app = TestApp( handlers.app ) app.post_json( '/ignore_extra_conf_file', { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } ) filepath = PathToTestFile( 'testy/ContinuousTest.cs' ) contents = open( filepath ).read() event_data = BuildRequest( filepath = filepath, filetype = 'cs', contents = contents, event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) WaitUntilOmniSharpServerReady( app, filepath ) completion_data = BuildRequest( filepath = filepath, filetype = 'cs', contents = contents, line_num = 9, column_num = 21, force_semantic = False, query = 'Date' ) results = app.post_json( '/completions', completion_data ).json[ 'completions' ] assert_that( results, empty() ) StopOmniSharpServer( app, filepath )
def GetCompletions_NoQuery_test( app ): RunTest( app, { 'description': 'semantic completion works for simple object no query', 'request': { 'filetype' : 'javascript', 'filepath' : PathToTestFile( 'simple_test.js' ), 'line_num' : 13, 'column_num': 43, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains_inanyorder( CompletionEntryMatcher( 'a_simple_function', 'fn(param: ?) -> string' ), CompletionEntryMatcher( 'basic_type', 'number' ), CompletionEntryMatcher( 'object', 'object' ), CompletionEntryMatcher( 'toString', 'fn() -> string' ), CompletionEntryMatcher( 'toLocaleString', 'fn() -> string' ), CompletionEntryMatcher( 'valueOf', 'fn() -> number' ), CompletionEntryMatcher( 'hasOwnProperty', 'fn(prop: string) -> bool' ), CompletionEntryMatcher( 'isPrototypeOf', 'fn(obj: ?) -> bool' ), CompletionEntryMatcher( 'propertyIsEnumerable', 'fn(prop: string) -> bool' ), ), 'errors': empty(), } ) }, } )
def DebugInfo_FlagsWhenNoExtraConfAndInvalidCompilationDatabase_test( app ): with TemporaryTestDir() as tmp_dir: compile_commands = 'garbage' with TemporaryClangProject( tmp_dir, compile_commands ): request_data = BuildRequest( filepath = os.path.join( tmp_dir, 'test.cc' ), filetype = 'cpp' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': empty(), 'items': contains( has_entries( { 'key': 'compilation database path', 'value': 'None' } ), has_entries( { 'key': 'flags', 'value': '[]' } ) ) } ) ) )
def GetCompletions_ClangCompleter_NoCompletionsWhenAutoTriggerOff_test(): ChangeSpecificOptions( { 'auto_trigger': False } ) app = TestApp( handlers.app ) 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 GetCompletions_NonForcedReturnsNoResults_test( app ): filepath = PathToTestFile( 'testy', 'ContinuousTest.cs' ) with WrapOmniSharpServer( app, filepath ): contents = ReadFile( filepath ) event_data = BuildRequest( filepath = filepath, filetype = 'cs', contents = contents, event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) completion_data = BuildRequest( filepath = filepath, filetype = 'cs', contents = contents, line_num = 9, column_num = 21, force_semantic = False, query = 'Date' ) results = app.post_json( '/completions', completion_data ).json # There are no semantic completions. However, we fall back to identifier # completer in this case. assert_that( results, has_entries( { 'completions': has_item( has_entries( { 'insertion_text' : 'String', 'extra_menu_info': '[ID]', } ) ), 'errors': empty(), } ) )
def DebugInfo_FlagsWhenNoExtraConfAndCompilationDatabaseLoaded_test( app ): with TemporaryTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -I. -I/absolute/path -Wall', 'file': os.path.join( tmp_dir, 'test.cc' ), }, ] with TemporaryClangProject( tmp_dir, compile_commands ): request_data = BuildRequest( filepath = os.path.join( tmp_dir, 'test.cc' ), filetype = 'cpp' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': empty(), 'items': contains( has_entries( { 'key': 'compilation database path', 'value': instance_of( str ) } ), has_entries( { 'key': 'flags', 'value': matches_regexp( "\['clang\+\+', '-x', 'c\+\+', .*, '-Wall', .*\]" ) } ) ) } ) ) )
def FileReadyToParse_ServerNotReady_test( app ): filepath = TestFactory contents = ReadFile( filepath ) StartJavaCompleterServerInDirectory( app, ProjectPath() ) completer = handlers._server_state.GetFiletypeCompleter( [ 'java' ] ) # It can take a while for the diagnostics to be ready for tries in range( 0, 60 ): event_data = BuildRequest( event_name = 'FileReadyToParse', contents = contents, filepath = filepath, filetype = 'java' ) results = app.post_json( '/event_notification', event_data ).json if results: break time.sleep( 0.5 ) # To make the test fair, we make sure there are some results prior to the # 'server not running' call assert results # Call the FileReadyToParse handler but pretend that the server isn't running with patch.object( completer, 'ServerIsHealthy', return_value = False ): event_data = BuildRequest( event_name = 'FileReadyToParse', contents = contents, filepath = filepath, filetype = 'java' ) results = app.post_json( '/event_notification', event_data ).json assert_that( results, empty() )
def GetCompletions_Query_test(app): RunTest( app, { "description": "semantic completion works for simple object with query", "request": { "filetype": "javascript", "filepath": PathToTestFile("simple_test.js"), "line_num": 14, "column_num": 45, }, "expect": { "response": http.client.OK, "data": has_entries( { "completions": contains( CompletionEntryMatcher("basic_type", "number"), CompletionEntryMatcher("isPrototypeOf", "fn(obj: ?) -> bool"), ), "errors": empty(), } ), }, }, )
def GetCompletions_UnicodeInLine_test( app ): RunTest( app, { 'description': 'member completion with a unicode identifier', 'extra_conf': [ '.ycm_extra_conf.py' ], 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'unicode.cc' ), 'line_num' : 9, 'column_num': 8, 'extra_conf_data': { '&filetype': 'cpp' }, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 8, 'completions': contains_inanyorder( CompletionEntryMatcher( 'member_with_å_unicøde', 'int' ), CompletionEntryMatcher( '~MyStruct', 'void' ), CompletionEntryMatcher( 'operator=', 'MyStruct &' ), CompletionEntryMatcher( 'MyStruct::', '' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_WithFixIt_test( app ): filepath = ProjectPath( 'TestFactory.java' ) RunTest( app, { 'description': 'semantic completion with when additional textEdit', 'request': { 'filetype' : 'java', 'filepath' : filepath, 'line_num' : 19, 'column_num': 25, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 22, 'completions': contains_inanyorder( CompletionEntryMatcher( 'CUTHBERT', 'com.test.wobble.Wibble', { 'kind': 'EnumMember', 'extra_data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains( ChunkMatcher( 'Wibble', LocationMatcher( filepath, 19, 15 ), LocationMatcher( filepath, 19, 21 ) ), # OK, so it inserts the import ChunkMatcher( '\n\nimport com.test.wobble.Wibble;\n\n', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 3, 1 ) ), ), } ) ), } ), } ), ), 'errors': empty(), } ) }, } )
def GetCompletions_Import_ModuleAndClass_test(app): filepath = ProjectPath('TestLauncher.java') RunTest( app, { 'description': 'completion works for imports of classes and modules', 'request': { 'filetype': 'java', 'filepath': filepath, 'line_num': 3, 'column_num': 26, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 26, 'completions': contains( CompletionEntryMatcher( 'testing.*;', None, { 'menu_text': 'com.youcompleteme.testing', 'kind': 'Module', }), CompletionEntryMatcher( 'Test;', None, { 'menu_text': 'Test - com.youcompleteme', 'kind': 'Class', }), ), 'errors': empty(), }) }, })
def GetCompletions_UnicodeIdentifier_test(app): filepath = PathToTestFile(DEFAULT_PROJECT_DIR, 'src', 'com', 'youcompleteme', 'Test.java') RunTest( app, { 'description': 'Completion works for unicode identifier', 'request': { 'filetype': 'java', 'filepath': filepath, 'line_num': 16, 'column_num': 35, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 35, 'completions': contains_inanyorder(*WithObjectMethods( CompletionEntryMatcher( 'a_test', 'Test.TéstClass', { 'kind': 'Field', 'detailed_info': 'a_test : int\n\n', }), CompletionEntryMatcher('testywesty', 'Test.TéstClass', { 'kind': 'Field', }), )), 'errors': empty(), }) }, })
def GetCompletions_ClangCompleter_Filtered_No_Results_Fallback_test(): # no errors because the semantic completer returned results, but they # were filtered out by the query, so this is considered working OK # (whereas no completions from the semantic engine is considered an # error) # TESTCASE5 (general_fallback/lang_cpp.cc) GetCompletions_RunTest({ 'description': '. on struct returns IDs after query=do_', 'request': { 'filetype': 'c', 'filepath': PathToTestFile('general_fallback', 'lang_c.c'), 'line_num': 71, 'column_num': 18, 'extra_conf_data': { '&filetype': 'c' }, 'force_semantic': False, }, 'expect': { 'response': httplib.OK, 'data': has_entries({ 'completions': contains_inanyorder( # do_ is an identifier because it is already in the file when we # load it CompletionEntryMatcher('do_', '[ID]'), CompletionEntryMatcher('do_something', '[ID]'), CompletionEntryMatcher('do_another_thing', '[ID]'), ), 'errors': empty() }) }, })
def DebugInfo_FlagsWhenGlobalExtraConfAndCompilationDatabaseLoaded_test( app ): with TemporaryTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -I. -I/absolute/path -Wall', 'file': os.path.join( tmp_dir, 'test.cc' ), }, ] with TemporaryClangProject( tmp_dir, compile_commands ): request_data = BuildRequest( filepath = os.path.join( tmp_dir, 'test.cc' ), filetype = 'cpp' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': empty(), 'items': contains( has_entries( { 'key': 'compilation database path', 'value': instance_of( str ) } ), has_entries( { 'key': 'flags', 'value': matches_regexp( "\\[u?'clang\\+\\+', u?'-x', u?'c\\+\\+', .*, u?'-Wall', .*\\]" ) } ), has_entries( { 'key': 'translation unit', 'value': os.path.join( tmp_dir, 'test.cc' ), } ) ) } ) ) )
def get_flavors(self, check=True, **kwgs): """Step to find all items with attributes matching `**kwgs`. Args: check (bool): flag whether to check step or not **kwgs (dict, optional): could be: * name (str): Descriptive name of the flavor * ram (int): Memory in MB for the flavor * vcpus (int): Number of VCPUs for the flavor * disk (int): Size of local disk in GB * id (str): ID for the flavor (optional). You can use the reserved value ``"auto"`` to have Nova generate a UUID for the flavor in cases where you cannot simply pass ``None``. * OS-FLV-EXT-DATA (int): Ephemeral space in MB * swap (int): Swap space in MB * rxtx_factor (float): RX/TX factor * os-flavor-access (bool): flag whether flavor should be public or not * check (bool): flag whether to check step or not Returns: list: nova flavor object(s) """ flavors = self._client.findall(**kwgs) if check: err_msg = "No flavors were retrieved, which correspond " \ "requested parameters {!r}".format(kwgs) assert_that(flavors, is_not(empty()), err_msg) for flavor in flavors: err_msg = "Retrieved flavor with ID {!r} doesn't correspond " \ "requested parameters".format(flavor.id) assert_that(flavor.to_dict(), has_entries(kwgs), err_msg) return flavors
def GetCompletions_BracketInclude_MultipleIncludeFlags_test(app): RunTest( app, { 'description': 'completion of #include < with multiple -I flags', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('test-include', 'main.cpp'), 'line_num': 10, 'column_num': 11, 'compilation_flags': [ '-x', 'cpp', '-I', PathToTestFile('test-include', 'dir with spaces'), '-I', PathToTestFile('test-include', 'quote'), '-I', PathToTestFile('test-include', 'system') ] }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 11, 'completions': contains(CompletionEntryMatcher('a.hpp', '[File]'), CompletionEntryMatcher('b.hpp', '[File]'), CompletionEntryMatcher('c.hpp', '[File]'), CompletionEntryMatcher('d.hpp', '[File]')), 'errors': empty(), }) }, })
def GetCompletions_ClangCLDriverFlag_SimpleCompletion_test(app): RunTest( app, { 'description': 'basic completion with --driver-mode=cl', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('driver_mode_cl', 'flag', 'driver_mode_cl.cpp'), 'line_num': 8, 'column_num': 18, 'force_semantic': True, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 3, 'completions': contains_inanyorder( CompletionEntryMatcher( 'driver_mode_cl_include_func', 'void\n"driver_mode_cl_include.h"'), CompletionEntryMatcher( 'driver_mode_cl_include_int', 'int\n"driver_mode_cl_include.h"'), ), 'errors': empty(), }) } })
def test_GetCompletions_ProcMacro(self, app): StartRustCompleterServerInDirectory(app, PathToTestFile('macro')) filepath = PathToTestFile('macro', 'src', 'main.rs') contents = ReadFile(filepath) completion_data = BuildRequest(filepath=filepath, filetype='rust', contents=contents, line_num=33, column_num=14) results = [] expiration = time.time() + 60 while time.time() < expiration: results = app.post_json('/completions', completion_data).json['completions'] if len(results) > 0: break time.sleep(0.25) assert_that(results, has_item(CompletionEntryMatcher('checkpoint'))) # This completer does not require or support resolve assert_that(results[0], is_not(has_key('resolve'))) assert_that(results[0], is_not(has_key('item'))) # So (erroneously) resolving an item returns the item completion_data['resolve'] = 0 response = app.post_json('/resolve_completion', completion_data).json print(f"Resolve resolve: { pformat( response ) }") # We can't actually check the result because we don't know what completion # resolve ID 0 actually is (could be anything), so we just check that we # get 1 result, and that there are no errors. assert_that(response['completion'], is_not(None)) assert_that(response['errors'], empty())
def Signature_Help_Multiple_Signatures_test(app): RunTest( app, { 'description': 'Test overloaded methods', 'request': { 'filetype': 'typescript', 'filepath': PathToTestFile('signatures.ts'), 'line_num': 89, 'column_num': 18, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'errors': empty(), 'signature_help': has_entries({ 'activeSignature': 1, 'activeParameter': 1, 'signatures': contains_exactly( SignatureMatcher('øverløåd(a: number): string', [ParameterMatcher(12, 21, '')], ''), SignatureMatcher( 'øverløåd(a: string, b: number): string', [ ParameterMatcher(12, 21, ''), ParameterMatcher(23, 32, '') ], '')), }), }) } })
def GetCompletions_BracketInclude_FrameworkHeader_test( app ): RunTest( app, { 'description': 'completion of #include <OpenGL/', 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'test-include', 'main.cpp' ), 'line_num' : 15, 'column_num': 18, 'compilation_flags': [ '-x', 'cpp', '-nostdinc', '-nobuiltininc', '-iframework', PathToTestFile( 'test-include', 'Frameworks' ) ] }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 18, 'completions': contains( CompletionEntryMatcher( 'gl.h', '[File]' ) ), 'errors': empty() } ) }, } )
def test_push_to_pagure(config_file, key_file, pushdir, lookasidedir, capsys): rpm = 'grub2-2.02-0.64.el7.src.rpm' options = [ '-v', '-c', config_file, '--push', 'c7', os.path.join(RPMS_PATH, rpm) ] config_defaults['pagure_repo_init_api'] = 'https://pagure_git_url/api/0/new' config_defaults['pagure_api_key_file'] = key_file def side_eff(): # create dummy remote repo to succeed git calls cmd = ['git', 'init', '--bare', 'grub2.git'] check_call(cmd, cwd=pushdir) return '{"message": "Project \\"rpms/grub2\\" created"}' with patch.dict("tests.test_import.alt_src.config_defaults", config_defaults): with patch("tests.test_import.alt_src.urlopen") as mock_resp: mock_resp.return_value.read.side_effect = side_eff # call main to push assert_that(calling(main).with_args(options), exits(0)) mock_resp.assert_called_once() _, err = capsys.readouterr() assert_that(len(err), equal_to(0)) # lookaside dir should have content lookaside = '%s/%s/%s' % (lookasidedir, 'grub2', 'c7') files = os.listdir(lookaside) assert_that(files, not_(empty())) remove_handlers()
def test_remove_acl_template(self, policy): assert_http_error(404, self.client.policies.remove_acl_template, UNKNOWN_UUID, '#') with self.client_in_subtenant() as (client, _, __): assert_http_error(404, client.policies.remove_acl_template, policy['uuid'], '#') policy_in_subtenant = client.policies.new(name='in sub-tenant', acl_templates=['#']) self.client.policies.remove_acl_template( policy_in_subtenant['uuid'], '#') assert_that( client.policies.get(policy_in_subtenant['uuid']), has_entries(uuid=policy_in_subtenant['uuid'], acl_templates=empty()), ) self.client.policies.remove_acl_template(policy['uuid'], 'ctid-ng.#') response = self.client.policies.get(policy['uuid']) assert_that( response, has_entries(acl_templates=contains_inanyorder('dird.me.#')))
def Signature_Help_Trigger_Paren_test( app ): RunTest( app, { 'description': 'Trigger after (', 'request': { 'filetype' : 'typescript', 'filepath' : PathToTestFile( 'signatures.ts' ), 'line_num' : 27, 'column_num': 29, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'errors': empty(), 'signature_help': has_entries( { 'activeSignature': 0, 'activeParameter': 0, 'signatures': contains( SignatureMatcher( 'single_argument_with_return(a: string): string', [ ParameterMatcher( 28, 37 ) ] ) ), } ), } ) } } )
def GetCompletions_RejectMultiLineInsertion_test(app): filepath = ProjectPath('TestLauncher.java') RunTest( app, { 'description': 'completion item discarded when not valid', 'request': { 'filetype': 'java', 'filepath': filepath, 'line_num': 28, 'column_num': 16, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 16, 'completions': contains_exactly( CompletionEntryMatcher( 'TestLauncher', 'com.test.TestLauncher.TestLauncher(int test)', {'kind': 'Constructor'}) # Note: There would be a suggestion here for the _real_ thing we want, # which is a TestLauncher.Launchable, but this would generate the code # for an anonymous inner class via a completion TextEdit (not # AdditionalTextEdit) which we don't support. ), 'errors': empty(), }) }, })
def DebugInfo_test(app): request_data = BuildRequest(filetype='javascript') assert_that( app.post_json('/debug_info', request_data).json, has_entry( 'completer', has_entries({ 'name': 'JavaScript', 'servers': contains( has_entries({ 'name': 'Tern', 'is_running': instance_of(bool), 'executable': instance_of(str), 'pid': instance_of(int), 'address': instance_of(str), 'port': instance_of(int), 'logfiles': contains(instance_of(str), instance_of(str)), 'extras': contains( has_entries({ 'key': 'configuration file', 'value': instance_of(str) })) })), 'items': empty() })))
def GetCompletions_WithQuery_test( app ): RunTest( app, { 'description': 'semantic completion works for builtin types (with query)', 'request': { 'filetype' : 'java', 'filepath' : ProjectPath( 'TestFactory.java' ), 'line_num' : 27, 'column_num': 15, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains_inanyorder( CompletionEntryMatcher( 'test', 'TestFactory.Bar', { 'kind': 'Field' } ), CompletionEntryMatcher( 'testString', 'TestFactory.Bar', { 'kind': 'Field' } ) ), 'errors': empty(), } ) }, } )
def DebugInfo_FlagsWhenGlobalExtraConfAndNoCompilationDatabase_test( app ): request_data = BuildRequest( filepath = PathToTestFile( 'basic.cpp' ), filetype = 'cpp' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': empty(), 'items': contains( has_entries( { 'key': 'compilation database path', 'value': 'None' } ), has_entries( { 'key': 'flags', 'value': matches_regexp( "\\[u?'-x', u?'c\\+\\+', .*\\]" ) } ), has_entries( { 'key': 'translation unit', 'value': PathToTestFile( 'basic.cpp' ) } ) ) } ) ) )
def GetCompletions_UnityInclude_test( app ): RunTest( app, { 'description': 'Completion returns for includes in unity setup', 'extra_conf': [ '.ycm_extra_conf.py' ], 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'unitya.cc' ), 'line_num' : 1, 'column_num': 17, 'force_semantic': True, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 11, 'completions': has_items( CompletionEntryMatcher( 'unity.h', '[File]' ), CompletionEntryMatcher( 'unity.cc', '[File]' ), CompletionEntryMatcher( 'unitya.cc', '[File]' ), ), 'errors': empty(), } ) } } )
def GetCompletions_ClangCompleter_Fallback_NoSuggestions_test(): # TESTCASE1 (general_fallback/lang_c.c) GetCompletions_RunTest({ 'description': 'Triggered, fallback but no query so no completions', 'request': { 'filetype': 'c', 'filepath': PathToTestFile('general_fallback', 'lang_c.c'), 'line_num': 29, 'column_num': 21, 'extra_conf_data': { '&filetype': 'c' }, 'force_semantic': False, }, 'expect': { 'response': httplib.OK, 'data': has_entries({ 'completions': empty(), 'errors': has_item(NO_COMPLETIONS_ERROR), }) }, })
def test_uve_module_states(client_contrail_analytics, os_faults_steps, role, get_nodes_method_name, get_ops_method_name): """Verify UVE module states.""" expected_process_list = settings.CONTRAIL_ANALYTIC_PROCESSES[role] get_nodes = getattr(client_contrail_analytics, get_nodes_method_name) get_ops = getattr(client_contrail_analytics, get_ops_method_name) # Map nodes to fqdns nodes = [] fqdns = settings.CONTRAIL_ROLES_DISTRIBUTION[role] for node in get_nodes(): if os_faults_steps.get_fqdn_by_host_name(node) in fqdns: nodes.append(node) with asserts.AssertsCollector() as collector: for node in nodes: data = get_ops(node) process_list = jmespath.search( 'NodeStatus.process_info[].process_name', data) process_list = [x.split(':')[0] for x in process_list] collector.check(process_list, superset_of(expected_process_list), 'Processes are absent on {}'.format(node)) wrong_processes = analytic_steps.get_process_info_with_wrong_state( data) collector.check(wrong_processes, is_(empty()), 'Processes has wrong status on {}'.format(node))
def GetCompletions_QuotedInclude_AfterDirectorySeparator_test(app): RunTest( app, { 'description': 'completion of #include "quote/', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('test-include', 'main.cpp'), 'line_num': 9, 'column_num': 27, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 27, 'completions': contains_exactly(CompletionEntryMatcher('d.hpp"'), ), 'errors': empty(), }) }, })
def GetCompletions_ForceSemantic_YcmdCache_test(app): RunTest( app, { 'description': 'completions are returned when using ycmd filtering', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('foo.cc'), 'contents': """ int main() { int foobar; int floozar; int gooboo; int bleble; fooar } """, 'line_num': 9, 'column_num': 8, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': contains_exactly(CompletionEntryMatcher('foobar'), CompletionEntryMatcher('floozar')), 'errors': empty() }) }, })
def GetCompletions_Fallback_Suggestions_test(app): # TESTCASE1 (general_fallback/lang_c.c) RunTest( app, { 'description': '. after macro with some query text (.a_)', 'request': { 'filetype': 'c', 'filepath': PathToTestFile('general_fallback', 'lang_c.c'), 'line_num': 29, 'column_num': 23, 'force_semantic': False, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': has_item(CompletionEntryMatcher('a_parameter', '[ID]')), 'errors': empty(), }) }, })
def test_update_contact_fields_one_phone(self): self.source.load(self.DEPENDENCIES) mario = { 'name': 'Mario Bros', 'mobilePhone': None, 'businessPhones': [], 'homePhones': ['111'], } assert_that( self.source._update_contact_fields([mario]), has_item( has_entries({ 'numbers': has_item('111'), 'numbers_except_label': has_entries({ 'mobilePhone': contains_inanyorder('111'), 'businessPhones': contains_inanyorder('111'), 'homePhones': empty(), }), })), )
def GetCompletions_Import_Classes_test( app ): filepath = ProjectPath( 'TestLauncher.java' ) RunTest( app, { 'description': 'completion works for imports with multiple classes', 'request': { 'filetype' : 'java', 'filepath' : filepath, 'line_num' : 3, 'column_num': 52, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 52, 'completions': contains( 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': 'Class', } ), CompletionEntryMatcher( 'Wibble;', None, { 'menu_text': 'Wibble - com.test.wobble', 'kind': 'Class', } ), ), 'errors': empty(), } ) }, } )
def get_images(self, name_prefix=None, check=True, **kwargs): """Step to retrieve images from glance. Args: name_prefix (str): name prefix to filter images check (bool): flag whether to check step or not **kwargs: like: {'name': 'TestVM', 'status': 'active'} Returns: list: images list Raises: AssertionError: if check triggered an error """ images = list(self._client.images.list()) if name_prefix: images = [ image for image in images if (image.name or '').startswith(name_prefix) ] if kwargs: matched_images = [] for image in images: for key, value in kwargs.items(): if not (key in image and image[key] == value): break else: matched_images.append(image) images = matched_images if check: assert_that(images, is_not(empty())) return images
def SignatureHelp_TriggerComma_test( app ): filepath = PathToTestFile( 'testy', 'ContinuousTest.cs' ) contents = ReadFile( filepath ) request = BuildRequest( line_num = 17, column_num = 16, filetypes = [ 'cs' ], filepath = filepath, contents = contents ) with WrapOmniSharpServer( app, filepath ): response = app.post_json( '/signature_help', request ).json LOGGER.debug( 'response = %s', response ) assert_that( response, has_entries( { 'errors': empty(), 'signature_help': has_entries( { 'activeSignature': 0, 'activeParameter': 1, 'signatures': contains_exactly( SignatureMatcher( 'void ContinuousTest.MultiArg(int i, string s)', [ ParameterMatcher( 29, 34 ), ParameterMatcher( 36, 44 ) ] ) ) } ) } ) )
def SignatureHelp_Constructor_test( app ): RunTest( app, { 'description': 'Trigger after , within a call-within-a-call', 'request': { 'filetype' : 'python', 'filepath' : PathToTestFile( 'signature_help.py' ), 'line_num' : 14, 'column_num': 61, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'errors': empty(), 'signature_help': has_entries( { 'activeSignature': 0, 'activeParameter': 0, 'signatures': contains( SignatureMatcher( 'class Class( argument )', [ ParameterMatcher( 13, 21 ) ] ) ), } ), } ) } } )
def GetCompletions_QuotedInclude_AfterSpace_test(app): RunTest( app, { 'description': 'completion of #include "dir with ', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('test-include', 'main.cpp'), 'line_num': 9, 'column_num': 20, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 11, 'completions': contains(CompletionEntryMatcher('dir with spaces/'), ), 'errors': empty(), }) }, })