6
6
from robot import result , running
7
7
from robot .model import Message
8
8
9
+ from robotcode .core .utils .path import normalized_path
10
+
9
11
from .dap_types import Event , Model
10
12
from .debugger import Debugger
11
13
@@ -18,6 +20,14 @@ class RobotExecutionEventBody(Model):
18
20
failed_keywords : Optional [List [Dict [str , Any ]]] = None
19
21
20
22
23
+ def source_from_attributes (attributes : Dict [str , Any ]) -> str :
24
+ s = attributes .get ("source" , "" )
25
+ if s :
26
+ return str (normalized_path (Path (s )))
27
+
28
+ return s or ""
29
+
30
+
21
31
class ListenerV2 :
22
32
ROBOT_LISTENER_API_VERSION = "2"
23
33
@@ -32,7 +42,7 @@ def start_suite(self, name: str, attributes: Dict[str, Any]) -> None:
32
42
event = "robotStarted" ,
33
43
body = RobotExecutionEventBody (
34
44
type = "suite" ,
35
- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} " ,
45
+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} " ,
36
46
attributes = dict (attributes ),
37
47
),
38
48
),
@@ -54,7 +64,7 @@ def end_suite(self, name: str, attributes: Dict[str, Any]) -> None:
54
64
body = RobotExecutionEventBody (
55
65
type = "suite" ,
56
66
attributes = dict (attributes ),
57
- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} " ,
67
+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} " ,
58
68
failed_keywords = self .failed_keywords ,
59
69
),
60
70
),
@@ -71,7 +81,7 @@ def start_test(self, name: str, attributes: Dict[str, Any]) -> None:
71
81
event = "robotStarted" ,
72
82
body = RobotExecutionEventBody (
73
83
type = "test" ,
74
- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} ;"
84
+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} ;"
75
85
f"{ attributes .get ('lineno' , 0 )} " ,
76
86
attributes = dict (attributes ),
77
87
),
@@ -93,7 +103,7 @@ def end_test(self, name: str, attributes: Dict[str, Any]) -> None:
93
103
event = "robotEnded" ,
94
104
body = RobotExecutionEventBody (
95
105
type = "test" ,
96
- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} ;"
106
+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} ;"
97
107
f"{ attributes .get ('lineno' , 0 )} " ,
98
108
attributes = dict (attributes ),
99
109
failed_keywords = self .failed_keywords ,
@@ -142,9 +152,9 @@ def log_message(self, message: Dict[str, Any]) -> None:
142
152
item_id = next (
143
153
(
144
154
(
145
- f"{ Path (item .source ). resolve ( ) if item .source is not None else '' } ;{ item .longname } "
155
+ f"{ normalized_path ( Path (item .source )) if item .source is not None else '' } ;{ item .longname } "
146
156
if item .type == "SUITE"
147
- else f"{ Path (item .source ). resolve ( ) if item .source is not None else '' } ;"
157
+ else f"{ normalized_path ( Path (item .source )) if item .source is not None else '' } ;"
148
158
f"{ item .longname } ;{ item .line } "
149
159
)
150
160
for item in Debugger .instance ().full_stack_frames
@@ -189,9 +199,9 @@ def message(self, message: Dict[str, Any]) -> None:
189
199
item_id = next (
190
200
(
191
201
(
192
- f"{ Path (item .source ). resolve ( ) if item .source is not None else '' } ;{ item .longname } "
202
+ f"{ normalized_path ( Path (item .source )) if item .source is not None else '' } ;{ item .longname } "
193
203
if item .type == "SUITE"
194
- else f"{ Path (item .source ). resolve ( ) if item .source is not None else '' } ;"
204
+ else f"{ normalized_path ( Path (item .source )) if item .source is not None else '' } ;"
195
205
f"{ item .longname } ;{ item .line } "
196
206
)
197
207
for item in Debugger .instance ().full_stack_frames
@@ -266,15 +276,15 @@ def enqueue(
266
276
item : Union [running .TestSuite , running .TestCase ],
267
277
) -> Iterator [str ]:
268
278
if isinstance (item , running .TestSuite ):
269
- yield f"{ Path (item .source ). resolve ( ) if item .source is not None else '' } ;{ item .longname } "
279
+ yield f"{ normalized_path (item .source ) if item .source is not None else '' } ;{ item .longname } "
270
280
271
281
for s in item .suites :
272
282
yield from enqueue (s )
273
283
for s in item .tests :
274
284
yield from enqueue (s )
275
285
return
276
286
277
- yield f"{ Path (item .source ). resolve () if item .source is not None else '' } ;{ item .longname } ;{ item .lineno } "
287
+ yield ( f"{ normalized_path (item .source ) if item .source is not None else '' } ;{ item .longname } ;{ item .lineno } " )
278
288
279
289
if self ._event_sended :
280
290
return
0 commit comments