1010
1111from .dap_types import Event , Model
1212from .debugger import Debugger
13+ from .mixins import SyncedEventBody
1314
1415
1516@dataclass
16- class RobotExecutionEventBody (Model ):
17+ class RobotExecutionEventBody (Model , SyncedEventBody ):
1718 type : str
1819 id : str
1920 name : str
2021 parent_id : Optional [str ] = None
2122 attributes : Optional [Dict [str , Any ]] = None
2223 failed_keywords : Optional [List [Dict [str , Any ]]] = None
24+ source : Optional [str ] = None
25+ lineno : Optional [int ] = None
26+ synced : bool = True
27+
28+
29+ @dataclass
30+ class RobotEnqueuedEventBody (Model , SyncedEventBody ):
31+ items : List [str ]
32+ synced : bool = True
33+
34+
35+ @dataclass
36+ class RobotLogMessageEventBody (Model , SyncedEventBody ):
37+ item_id : Optional [str ]
38+
39+ message : Optional [str ]
40+ level : Optional [str ]
41+ timestamp : Optional [str ]
42+ html : Optional [str ]
43+
44+ source : Optional [str ] = None
45+ lineno : Optional [int ] = None
46+ column : Optional [int ] = None
47+
48+ synced : bool = True
2349
2450
2551def source_from_attributes (attributes : Dict [str , Any ]) -> str :
@@ -40,6 +66,7 @@ def __init__(self) -> None:
4066
4167 def start_suite (self , name : str , attributes : Dict [str , Any ]) -> None :
4268 id = f"{ source_from_attributes (attributes )} ;{ attributes .get ('longname' , '' )} "
69+
4370 Debugger .instance ().send_event (
4471 self ,
4572 Event (
@@ -50,6 +77,8 @@ def start_suite(self, name: str, attributes: Dict[str, Any]) -> None:
5077 id = id ,
5178 parent_id = self .suite_id_stack [- 1 ] if self .suite_id_stack else None ,
5279 attributes = dict (attributes ),
80+ source = source_from_attributes (attributes ) or None ,
81+ lineno = attributes .get ("lineno" , None ),
5382 ),
5483 ),
5584 )
@@ -76,6 +105,8 @@ def end_suite(self, name: str, attributes: Dict[str, Any]) -> None:
76105 id = id ,
77106 parent_id = self .suite_id_stack [- 1 ] if self .suite_id_stack else None ,
78107 failed_keywords = self .failed_keywords ,
108+ source = source_from_attributes (attributes ) or None ,
109+ lineno = attributes .get ("lineno" , None ),
79110 ),
80111 ),
81112 )
@@ -96,6 +127,8 @@ def start_test(self, name: str, attributes: Dict[str, Any]) -> None:
96127 f"{ attributes .get ('lineno' , 0 )} " ,
97128 parent_id = self .suite_id_stack [- 1 ] if self .suite_id_stack else None ,
98129 attributes = dict (attributes ),
130+ source = source_from_attributes (attributes ) or None ,
131+ lineno = attributes .get ("lineno" , None ),
99132 ),
100133 ),
101134 )
@@ -121,6 +154,8 @@ def end_test(self, name: str, attributes: Dict[str, Any]) -> None:
121154 parent_id = self .suite_id_stack [- 1 ] if self .suite_id_stack else None ,
122155 attributes = dict (attributes ),
123156 failed_keywords = self .failed_keywords ,
157+ source = source_from_attributes (attributes ) or None ,
158+ lineno = attributes .get ("lineno" , None ),
124159 ),
125160 ),
126161 )
@@ -135,11 +170,45 @@ def start_keyword(self, name: str, attributes: Dict[str, Any]) -> None:
135170 attributes .get ("type" ),
136171 )
137172
173+ # if Debugger.instance().state != State.CallKeyword:
174+ # Debugger.instance().send_event(
175+ # self,
176+ # Event(
177+ # event="robotStarted",
178+ # body=RobotExecutionEventBody(
179+ # type="keyword",
180+ # name=name,
181+ # id=f"{source_from_attributes(attributes)};{name};{attributes.get('lineno', 0)}",
182+ # parent_id=self.suite_id_stack[-1] if self.suite_id_stack else None,
183+ # attributes=dict(attributes),
184+ # source=source_from_attributes(attributes) or None,
185+ # lineno=attributes.get("lineno", None),
186+ # ),
187+ # ),
188+ # )
189+
138190 Debugger .instance ().start_keyword (name , attributes )
139191
140192 def end_keyword (self , name : str , attributes : Dict [str , Any ]) -> None :
141193 Debugger .instance ().end_keyword (name , attributes )
142194
195+ # if Debugger.instance().state != State.CallKeyword:
196+ # Debugger.instance().send_event(
197+ # self,
198+ # Event(
199+ # event="robotEnded",
200+ # body=RobotExecutionEventBody(
201+ # type="keyword",
202+ # name=name,
203+ # id=f"{source_from_attributes(attributes)};{name};{attributes.get('lineno', 0)}",
204+ # parent_id=self.suite_id_stack[-1] if self.suite_id_stack else None,
205+ # attributes=dict(attributes),
206+ # source=source_from_attributes(attributes) or None,
207+ # lineno=attributes.get("lineno", None),
208+ # ),
209+ # ),
210+ # )
211+
143212 if attributes ["type" ] in ["KEYWORD" , "SETUP" , "TEARDOWN" ]:
144213 Debugger .instance ().end_output_group (name , attributes , attributes .get ("type" ))
145214
@@ -189,14 +258,16 @@ def log_message(self, message: Dict[str, Any]) -> None:
189258 self ,
190259 Event (
191260 event = "robotLog" ,
192- body = {
193- "itemId" : item_id ,
194- "source" : source ,
195- "lineno" : line ,
196- "column" : column ,
197- ** dict (message ),
198- ** ({"message" : msg } if msg else {}),
199- },
261+ body = RobotLogMessageEventBody (
262+ item_id = item_id ,
263+ message = msg if msg else message .get ("message" , None ),
264+ level = message .get ("level" , None ),
265+ timestamp = message .get ("timestamp" , None ),
266+ html = message .get ("html" , None ),
267+ source = source ,
268+ lineno = line ,
269+ column = column ,
270+ ),
200271 ),
201272 )
202273
@@ -236,14 +307,16 @@ def message(self, message: Dict[str, Any]) -> None:
236307 self ,
237308 Event (
238309 event = "robotMessage" ,
239- body = {
240- "itemId" : item_id ,
241- "source" : source ,
242- "lineno" : line ,
243- "column" : column ,
244- ** dict (message ),
245- ** ({"message" : msg } if msg else {}),
246- },
310+ body = RobotLogMessageEventBody (
311+ item_id = item_id ,
312+ message = msg if msg else message .get ("message" , None ),
313+ level = message .get ("level" , None ),
314+ timestamp = message .get ("timestamp" , None ),
315+ html = message .get ("html" , None ),
316+ source = source ,
317+ lineno = line ,
318+ column = column ,
319+ ),
247320 ),
248321 )
249322
@@ -305,7 +378,7 @@ def enqueue(
305378
306379 items = list (reversed (list (enqueue (cast (running .model .TestSuite , data )))))
307380
308- Debugger .instance ().send_event (self , Event (event = "robotEnqueued" , body = { " items" : items } ))
381+ Debugger .instance ().send_event (self , Event (event = "robotEnqueued" , body = RobotEnqueuedEventBody ( items ) ))
309382
310383 self ._event_sended = True
311384
@@ -337,6 +410,8 @@ def report_status(
337410 if isinstance (result_item , result .TestCase )
338411 else ""
339412 ),
413+ source = str (normalized_path (Path (result_item .source ))) if result_item .source else None ,
414+ lineno = data_item .lineno if data_item else None ,
340415 ),
341416 ),
342417 )
0 commit comments