66from robot import result , running
77from robot .model import Message
88
9+ from robotcode .core .utils .path import normalized_path
10+
911from .dap_types import Event , Model
1012from .debugger import Debugger
1113
@@ -18,6 +20,14 @@ class RobotExecutionEventBody(Model):
1820 failed_keywords : Optional [List [Dict [str , Any ]]] = None
1921
2022
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+
2131class ListenerV2 :
2232 ROBOT_LISTENER_API_VERSION = "2"
2333
@@ -32,7 +42,7 @@ def start_suite(self, name: str, attributes: Dict[str, Any]) -> None:
3242 event = "robotStarted" ,
3343 body = RobotExecutionEventBody (
3444 type = "suite" ,
35- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} " ,
45+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} " ,
3646 attributes = dict (attributes ),
3747 ),
3848 ),
@@ -54,7 +64,7 @@ def end_suite(self, name: str, attributes: Dict[str, Any]) -> None:
5464 body = RobotExecutionEventBody (
5565 type = "suite" ,
5666 attributes = dict (attributes ),
57- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} " ,
67+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} " ,
5868 failed_keywords = self .failed_keywords ,
5969 ),
6070 ),
@@ -71,7 +81,7 @@ def start_test(self, name: str, attributes: Dict[str, Any]) -> None:
7181 event = "robotStarted" ,
7282 body = RobotExecutionEventBody (
7383 type = "test" ,
74- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} ;"
84+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} ;"
7585 f"{ attributes .get ('lineno' , 0 )} " ,
7686 attributes = dict (attributes ),
7787 ),
@@ -93,7 +103,7 @@ def end_test(self, name: str, attributes: Dict[str, Any]) -> None:
93103 event = "robotEnded" ,
94104 body = RobotExecutionEventBody (
95105 type = "test" ,
96- id = f"{ attributes . get ( 'source' , '' )} ;{ attributes .get ('longname' , '' )} ;"
106+ id = f"{ source_from_attributes ( attributes )} ;{ attributes .get ('longname' , '' )} ;"
97107 f"{ attributes .get ('lineno' , 0 )} " ,
98108 attributes = dict (attributes ),
99109 failed_keywords = self .failed_keywords ,
@@ -142,9 +152,9 @@ def log_message(self, message: Dict[str, Any]) -> None:
142152 item_id = next (
143153 (
144154 (
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 } "
146156 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 '' } ;"
148158 f"{ item .longname } ;{ item .line } "
149159 )
150160 for item in Debugger .instance ().full_stack_frames
@@ -189,9 +199,9 @@ def message(self, message: Dict[str, Any]) -> None:
189199 item_id = next (
190200 (
191201 (
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 } "
193203 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 '' } ;"
195205 f"{ item .longname } ;{ item .line } "
196206 )
197207 for item in Debugger .instance ().full_stack_frames
@@ -266,15 +276,15 @@ def enqueue(
266276 item : Union [running .TestSuite , running .TestCase ],
267277 ) -> Iterator [str ]:
268278 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 } "
270280
271281 for s in item .suites :
272282 yield from enqueue (s )
273283 for s in item .tests :
274284 yield from enqueue (s )
275285 return
276286
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 } " )
278288
279289 if self ._event_sended :
280290 return
0 commit comments