1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
from _pydevd_bundle._debug_adapter.pydevd_schema import InitializeRequest, InitializeRequestArguments, InitializeResponse, Capabilities
from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema
from _pydevd_bundle._debug_adapter.pydevd_schema import ThreadsResponse
def test_schema():
json_msg = """
{
"arguments": {
"adapterID": "pydevd",
"clientID": "vscode",
"clientName": "Visual Studio Code",
"columnsStartAt1": true,
"linesStartAt1": true,
"locale": "en-us",
"pathFormat": "path",
"supportsRunInTerminalRequest": true,
"supportsVariablePaging": true,
"supportsVariableType": true
},
"command": "initialize",
"seq": 1,
"type": "request"
}"""
initialize_request = pydevd_base_schema.from_json(json_msg)
assert initialize_request.__class__ == InitializeRequest
assert initialize_request.arguments.__class__ == InitializeRequestArguments
assert initialize_request.arguments.adapterID == "pydevd"
assert initialize_request.command == "initialize"
assert initialize_request.type == "request"
assert initialize_request.seq == 1
response = pydevd_base_schema.build_response(initialize_request)
assert response.__class__ == InitializeResponse
assert response.seq == -1 # Must be set before sending
assert response.command == "initialize"
assert response.type == "response"
assert response.body.__class__ == Capabilities
assert response.to_dict() == {"seq": -1, "type": "response", "request_seq": 1, "success": True, "command": "initialize", "body": {}}
capabilities = response.body # : :type capabilities: Capabilities
capabilities.supportsCompletionsRequest = True
assert response.to_dict() == {
"seq": -1,
"type": "response",
"request_seq": 1,
"success": True,
"command": "initialize",
"body": {"supportsCompletionsRequest": True},
}
initialize_event = pydevd_schema.InitializedEvent()
assert initialize_event.to_dict() == {"seq": -1, "type": "event", "event": "initialized"}
def test_schema_translation_frame():
pydevd_base_schema.BaseSchema.initialize_ids_translation()
stack_trace_arguments = pydevd_schema.StackTraceArguments(threadId=1)
stack_trace_request = pydevd_schema.StackTraceRequest(stack_trace_arguments)
stackFrames = [
pydevd_schema.StackFrame(id=2**45, name="foo", line=1, column=1).to_dict(),
pydevd_schema.StackFrame(id=2**46, name="bar", line=1, column=1).to_dict(),
]
body = pydevd_schema.StackTraceResponseBody(stackFrames)
stack_trace_response = pydevd_base_schema.build_response(stack_trace_request, kwargs=dict(body=body))
as_dict = stack_trace_response.to_dict(update_ids_to_dap=True)
assert as_dict == {
"type": "response",
"request_seq": -1,
"success": True,
"command": "stackTrace",
"body": {
"stackFrames": [
{"id": 1, "name": "foo", "line": 1, "column": 1, "source": {}},
{"id": 2, "name": "bar", "line": 1, "column": 1, "source": {}},
]
},
"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": "stackTrace",
"body": {
"stackFrames": [
{"id": 2**45, "name": "foo", "line": 1, "column": 1, "source": {}},
{"id": 2**46, "name": "bar", "line": 1, "column": 1, "source": {}},
]
},
"seq": -1,
}
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,
}
|