@@ -161,42 +161,45 @@ def json_to_discord_json(json_data, os_name, compiler, event, author, branch):
161
161
return discord_json
162
162
163
163
def parse_test_results_from_file (file_path ):
164
- # Read the XML data from the file
165
- with open (file_path , 'r' , encoding = 'utf-8' ) as file :
166
- xml_data = file .read ()
167
-
168
- # Parse the XML data
169
- root = ET .fromstring (xml_data )
170
-
171
- # Extract test suite information
172
- test_suite_name = root .attrib .get ('name' , 'Test Suite' )
173
- tests = root .attrib .get ('tests' , '0' )
174
- failures = root .attrib .get ('failures' , '0' )
175
- skipped = root .attrib .get ('skipped' , '0' )
176
-
177
- # Initialize the total time
178
- total_time = 0.0
164
+ tree = ET .parse (file_path )
165
+ root = tree .getroot ()
166
+ test_suite_name = root .attrib ['name' ]
167
+ tests = int (root .attrib ['tests' ])
168
+ failures = int (root .attrib ['failures' ])
169
+ skipped = int (root .attrib ['skipped' ])
170
+ total_time = float (root .attrib ['time' ])
179
171
180
- # Extract test case information
181
172
test_cases = []
173
+ failed_cases = []
182
174
for testcase in root .findall ('testcase' ):
183
- name = testcase .attrib . get ( 'name' )
184
- time = float (testcase .attrib . get ( 'time' , '0' ) )
185
- status = 'passed' if testcase . find ( 'failure' ) is None else 'failed'
186
- test_cases . append (( name , status , time ))
175
+ name = testcase .attrib [ 'name' ]
176
+ time = float (testcase .attrib [ 'time' ] )
177
+ status = 'passed'
178
+ error_message = None
187
179
188
- # Accumulate total time
189
- total_time += time
180
+ failure = testcase .find ('failure' )
181
+ if failure is not None :
182
+ status = 'failed'
183
+ error_message = failure .attrib .get ('message' , '' ) + ' ' + testcase .find ('system-out' ).text .strip ()
184
+ failed_cases .append ((name , error_message ))
190
185
191
- return test_suite_name , tests , failures , skipped , total_time , test_cases
186
+ test_cases . append (( name , status , time , error_message ))
192
187
188
+ return test_suite_name , tests , failures , skipped , total_time , test_cases , failed_cases
193
189
194
- def create_dark_theme_test_results_image (file_path , os , compiler ):
190
+ def create_horizontal_test_results_image (file_path , os , compiler , event , author , brach ):
195
191
# Parse the XML data from the file
196
- test_suite_name , tests , failures , skipped , total_time , test_cases = parse_test_results_from_file (file_path )
192
+ test_suite_name , tests , failures , skipped , total_time , test_cases , failed_cases = parse_test_results_from_file (file_path )
193
+
194
+ # Set height depending if there are failed tests
195
+ default_height = 0
196
+ if failures > 0 :
197
+ default_height = 250
198
+ else :
199
+ default_height = 150
197
200
198
201
# Set up image
199
- width , height = 500 , 350
202
+ width , height = 800 , default_height + ( 25 * len ( test_cases )) + ( 25 * len ( failed_cases )) # Adjust height based on number of test cases and failed cases
200
203
background_color = (45 , 47 , 49 ) # Dark gray
201
204
image = Image .new ('RGB' , (width , height ), color = background_color )
202
205
draw = ImageDraw .Draw (image )
@@ -227,11 +230,20 @@ def create_dark_theme_test_results_image(file_path, os, compiler):
227
230
# Draw title
228
231
draw .text ((20 , 20 ), "Test Results" , font = title_font , fill = white )
229
232
233
+ x = 200
234
+ # Add the trigger details
235
+ draw .text ((x , 30 ), f"Author: { author } " , font = body_font , fill = white )
236
+ x += 150
237
+ draw .text ((x , 30 ), f"Event: { event } " , font = body_font , fill = white )
238
+ x += 150
239
+ draw .text ((x , 30 ), f"Branch: { brach } " , font = body_font , fill = white )
230
240
# Hard set the suite name
231
241
test_suite_name = f"{ os } -{ compiler } "
232
242
233
243
# Draw test suite information
234
244
y = 60
245
+ draw .text ((20 , y ), f"Details" , font = header_font , fill = white )
246
+ y += 40
235
247
draw .text ((20 , y ), f"Test Suite: { test_suite_name } " , font = body_font , fill = white )
236
248
y += 25
237
249
draw .text ((20 , y ), f"Total Tests: { tests } " , font = body_font , fill = white )
@@ -241,16 +253,30 @@ def create_dark_theme_test_results_image(file_path, os, compiler):
241
253
draw .text ((20 , y ), f"Skipped: { skipped } " , font = body_font , fill = light_gray )
242
254
y += 25
243
255
draw .text ((20 , y ), f"Duration: { total_time :.6f} " , font = body_font , fill = light_gray )
244
- y += 40
256
+
257
+ if failures > 0 :
258
+ # Draw failed test summary header
259
+ y += 40
260
+ draw .text ((20 , y ), "Failed Test Summary" , font = header_font , fill = white )
261
+
262
+ # Draw failed test cases
263
+ y += 30
264
+ for name , error_message in failed_cases :
265
+ draw .text ((20 , y ), name , font = body_font , fill = white )
266
+ y += 25
267
+ draw .text ((20 , y ), error_message , font = body_font , fill = red )
268
+ y += 25
269
+
270
+ # Draw detailed test results header
271
+ draw .text ((400 , 60 ), "Detailed Test Results" , font = header_font , fill = white )
245
272
246
273
# Draw test cases
247
- draw .text ((20 , y ), "Detailed Test Results" , font = header_font , fill = white )
248
- y += 30
249
- for name , status , duration in test_cases :
250
- draw .text ((20 , y ), name , font = body_font , fill = white )
274
+ y = 100
275
+ for name , status , duration , error_message in test_cases :
276
+ draw .text ((400 , y ), name , font = body_font , fill = white )
251
277
status_color = green if status == 'passed' else red
252
- draw .text ((200 , y ), status , font = body_font , fill = status_color )
253
- draw .text ((280 , y ), f"{ duration :.6f} " , font = body_font , fill = light_gray ) # Corrected here
278
+ draw .text ((580 , y ), status , font = body_font , fill = status_color )
279
+ draw .text ((660 , y ), f"{ duration :.6f} " , font = body_font , fill = light_gray )
254
280
y += 25
255
281
256
282
return image
@@ -296,7 +322,7 @@ def create_dark_theme_test_results_image(file_path, os, compiler):
296
322
print (f"Discord JSON output has been written to { discord_json_output_file } " )
297
323
298
324
# Generate data
299
- image = create_dark_theme_test_results_image (args .xml_file , args .os , args .compiler )
325
+ image = create_horizontal_test_results_image (args .xml_file , args .os , args .compiler , args . event , args . author , args . branch )
300
326
301
327
# Create the image
302
328
os .makedirs (os .path .dirname (args .image_out ), exist_ok = True )
0 commit comments