def test_schema_translation_thread(): from _pydevd_bundle._debug_adapter.pydevd_schema import ThreadsRequest pydevd_base_schema.BaseSchema.initialize_ids_translation() threads = [ pydevd_schema.Thread(id=2**45, name='foo').to_dict(), pydevd_schema.Thread(id=2**46, name='bar').to_dict(), ] body = pydevd_schema.ThreadsResponseBody(threads) threads_request = ThreadsRequest() threads_response = pydevd_base_schema.build_response( threads_request, kwargs=dict(body=body)) as_dict = threads_response.to_dict(update_ids_to_dap=True) assert as_dict == { 'type': 'response', 'request_seq': -1, 'success': True, 'command': 'threads', 'body': { 'threads': [ { 'id': 1, 'name': 'foo' }, { 'id': 2, 'name': 'bar' }, ] }, 'seq': -1 } reconstructed = pydevd_base_schema.from_dict(as_dict, update_ids_from_dap=True) assert reconstructed.to_dict() == { 'type': 'response', 'request_seq': -1, 'success': True, 'command': 'threads', 'body': { 'threads': [{ 'id': 2**45, 'name': 'foo' }, { 'id': 2**46, 'name': 'bar' }] }, 'seq': -1 }
def make_list_threads_message(self, seq): threads = [] for thread in get_non_pydevd_threads(): if is_thread_alive(thread): thread_schema = pydevd_schema.Thread(id=get_thread_id(thread), name=thread.getName()) threads.append(thread_schema.to_dict()) body = pydevd_schema.ThreadsResponseBody(threads) response = pydevd_schema.ThreadsResponse( request_seq=seq, success=True, command='threads', body=body) return NetCommand(CMD_RETURN, 0, response.to_dict(), is_json=True)
def make_list_threads_message(self, py_db, seq): threads = [] for thread in get_non_pydevd_threads(): if is_thread_alive(thread): thread_id = get_thread_id(thread) # Notify that it's created (no-op if we already notified before). py_db.notify_thread_created(thread_id, thread) thread_schema = pydevd_schema.Thread(id=thread_id, name=thread.getName()) threads.append(thread_schema.to_dict()) body = pydevd_schema.ThreadsResponseBody(threads) response = pydevd_schema.ThreadsResponse( request_seq=seq, success=True, command='threads', body=body) return NetCommand(CMD_RETURN, 0, response, is_json=True)