forked from microsoft/debugpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_path_mapping.py
More file actions
146 lines (112 loc) · 4.68 KB
/
Copy pathtest_path_mapping.py
File metadata and controls
146 lines (112 loc) · 4.68 KB
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
136
137
138
139
140
141
142
143
144
145
146
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
import pytest
import tests
from tests import debug, test_data
from tests.debug import targets
from tests.patterns import some
if not tests.full:
@pytest.fixture(params=targets.all_named)
def target(request):
return request.param
def test_with_dot_remote_root(pyfile, long_tmpdir, target, run):
@pyfile
def code_to_debug():
import os
import debuggee
from debuggee import backchannel
debuggee.setup()
backchannel.send(os.path.abspath(__file__))
print("done") # @bp
dir_local = long_tmpdir.mkdir("local")
dir_remote = long_tmpdir.mkdir("remote")
path_local = dir_local / "code_to_debug.py"
path_remote = dir_remote / "code_to_debug.py"
code_to_debug.copy(path_local)
code_to_debug.copy(path_remote)
with debug.Session() as session:
session.config["pathMappings"] = [{"localRoot": dir_local, "remoteRoot": "."}]
backchannel = session.open_backchannel()
with run(session, target(path_remote), cwd=dir_remote):
# Set breakpoints using local path. This tests that local paths are
# mapped to remote paths.
session.set_breakpoints(path_local, all)
actual_path_remote = backchannel.receive()
assert some.path(actual_path_remote) == path_remote
session.wait_for_stop(
"breakpoint",
expected_frames=[some.dap.frame(some.dap.source(path_local), line="bp")],
)
session.request_continue()
def test_with_path_mappings(pyfile, long_tmpdir, target, run):
@pyfile
def code_to_debug():
import debuggee
import os
import sys
from debuggee import backchannel
debuggee.setup()
backchannel.send(os.path.abspath(__file__))
call_me_back_dir = backchannel.receive()
sys.path.insert(0, call_me_back_dir)
import call_me_back
def call_func():
print("break here") # @bp
call_me_back.call_me_back(call_func) # @call_me_back
print("done")
dir_local = long_tmpdir.mkdir("local")
dir_remote = long_tmpdir.mkdir("remote")
path_local = dir_local / "code_to_debug.py"
path_remote = dir_remote / "code_to_debug.py"
code_to_debug.copy(path_local)
code_to_debug.copy(path_remote)
call_me_back_dir = test_data / "call_me_back"
call_me_back_py = call_me_back_dir / "call_me_back.py"
with debug.Session() as session:
session.config["pathMappings"] = [
{"localRoot": dir_local, "remoteRoot": dir_remote}
]
backchannel = session.open_backchannel()
with run(session, target(path_remote)):
# Set breakpoints using local path. This tests that local paths are
# mapped to remote paths.
session.set_breakpoints(path_local, ["bp"])
actual_path_remote = backchannel.receive()
assert some.path(actual_path_remote) == path_remote
backchannel.send(call_me_back_dir)
stop = session.wait_for_stop(
"breakpoint",
expected_frames=[
some.dap.frame(
# Mapped files should not have a sourceReference, so that the IDE
# doesn't try to fetch them instead of opening the local file.
some.dap.source(path_local, sourceReference=0),
line="bp",
),
some.dap.frame(
# Unmapped files should have a sourceReference, since there's no
# local file for the IDE to open.
some.dap.source(
call_me_back_py, sourceReference=some.int.not_equal_to(0)
),
line="callback",
),
some.dap.frame(
# Mapped files should not have a sourceReference, so that the IDE
# doesn't try to fetch them instead of opening the local file.
some.dap.source(path_local, sourceReference=0),
line="call_me_back",
),
],
)
srcref = stop.frames[1]["source"]["sourceReference"]
try:
session.request("source", {"sourceReference": 0})
except Exception as exc:
assert "Source unavailable" in str(exc)
else:
pytest.fail("sourceReference=0 should not be valid")
source = session.request("source", {"sourceReference": srcref})
assert "def call_me_back(callback):" in source["content"]
session.request_continue()