33
33
34
34
from ..config import APP_REFS
35
35
36
+ from ..dialog import create_and_show_dialog
37
+
36
38
from ..pygamesetup import SERVICES_NS , SCREEN_RECT
37
39
38
40
from ..ourstdlibs .behaviour import empty_function
78
80
REPORT_BG = (235 , 235 , 250 )
79
81
REPORT_FG = (28 , 28 , 28 )
80
82
81
- RESULT_TO_COLOR = {
82
- 'passed' : (30 , 160 , 70 ),
83
- 'error' : (255 , 30 , 70 ),
84
- 'failed' : (255 , 255 , 70 ),
85
- }
86
-
87
83
TEXT_SETTINGS = {
88
84
"font_height" : ENC_SANS_BOLD_FONT_HEIGHT ,
89
85
"font_path" : ENC_SANS_BOLD_FONT_PATH ,
101
97
}
102
98
103
99
PIE_COLOR_MAP = {
104
- 'passed' : 'green' ,
105
- 'failed ' : 'yellow' ,
106
- 'error ' : 'red' ,
100
+ 'passed' : ( 30 , 160 , 70 ) ,
101
+ 'error ' : ( 255 , 30 , 70 ) ,
102
+ 'failed ' : ( 255 , 140 , 0 ) ,
107
103
}
108
104
105
+ RESULT_TO_COLOR = PIE_COLOR_MAP
106
+
109
107
RESULTS = []
110
108
RESULTS_COUNTER = Counter ()
111
109
@@ -205,9 +203,14 @@ def __init__(self):
205
203
### build widgets
206
204
self .create_general_widgets ()
207
205
208
- ### create placeholder attribute to hold next loop holder
206
+ ### create placeholder attributes
207
+
208
+ ## to hold next loop holder
209
209
self .loop_holder = None
210
210
211
+ ## to hold report data
212
+ self .report_data = None
213
+
211
214
### center form and also append centering method
212
215
### as a window resize setup
213
216
@@ -231,7 +234,7 @@ def create_general_widgets(self):
231
234
"""Build general widgets to use/reuse in reports."""
232
235
### define an initial topleft relative to the
233
236
### topleft corner of the form 'rect'
234
- topleft = self .rect .move (10 , 10 ).topleft
237
+ topleft = self .rect .move (20 , 20 ).topleft
235
238
236
239
### instantiate a caption for the form
237
240
@@ -270,21 +273,24 @@ def create_general_widgets(self):
270
273
271
274
midright = self .exit_button .rect .move (- 10 , 0 ).midleft
272
275
273
- self .save_button = Button .from_text (
274
- text = "Save as html " ,
275
- command = self .save_report ,
276
+ self .export_button = Button .from_text (
277
+ text = "Export as HTML " ,
278
+ command = self .export_report ,
276
279
coordinates_name = 'midright' ,
277
280
coordinates_value = midright ,
278
281
** BUTTON_SETTINGS ,
279
282
)
280
283
281
- draw_depth_finish (self .save_button .image )
284
+ draw_depth_finish (self .export_button .image )
282
285
283
286
## store them
284
- self .widgets .extend ((self .save_button , self .exit_button ))
287
+ self .widgets .extend ((self .export_button , self .exit_button ))
285
288
286
289
def prepare_report (self , report_data ):
287
290
"""Create visuals showing report results."""
291
+ ### store report data
292
+ self .report_data = report_data
293
+
288
294
### reference widgets locally
289
295
widgets = self .widgets
290
296
@@ -293,35 +299,11 @@ def prepare_report(self, report_data):
293
299
294
300
### reposition and store caption
295
301
296
- self .caption_label .rect .topleft = self .rect .move (10 , 10 ).topleft
302
+ self .caption_label .rect .topleft = self .rect .move (20 , 20 ).topleft
297
303
widgets .append (self .caption_label )
298
304
299
305
### create report-related visuals
300
306
301
- ## result label
302
-
303
- topleft = self .caption_label .rect .move (0 , 10 ).bottomleft
304
-
305
- overall_result = report_data ['overall_result' ]
306
- fg_color = RESULT_TO_COLOR [overall_result ]
307
-
308
- result_label = Object2D .from_surface (
309
- surface = (
310
- render_text (
311
- text = f'Overall result: { overall_result } ' ,
312
- ** {
313
- ** TEXT_SETTINGS ,
314
- 'font_height' : 40 ,
315
- 'foreground_color' : fg_color ,
316
- },
317
- )
318
- ),
319
- coordinates_name = "topleft" ,
320
- coordinates_value = topleft ,
321
- )
322
-
323
- widgets .append (result_label )
324
-
325
307
## create pie chart
326
308
327
309
# update results
@@ -359,7 +341,7 @@ def prepare_report(self, report_data):
359
341
(pie_surf , PIE_LEGEND ),
360
342
retrieve_pos_from = 'midright' ,
361
343
assign_pos_to = 'midleft' ,
362
- offset_pos_by = (10 , 0 ),
344
+ offset_pos_by = (20 , 0 ),
363
345
background_color = REPORT_BG ,
364
346
)
365
347
)
@@ -377,20 +359,150 @@ def prepare_report(self, report_data):
377
359
# append to widgets
378
360
widgets .append (pie )
379
361
380
- ## legend
362
+ overall_objects = self .get_overall_objects ()
363
+
364
+ overall_objects .rect .topleft = pie .rect .move (0 , 10 ).bottomleft
365
+
366
+ widgets .extend (overall_objects )
381
367
382
368
### position and store buttons
383
369
384
370
self .exit_button .rect .bottomright = (
385
371
self .rect .right - 10 ,
386
- widgets .rect .bottom + 20 ,
372
+ widgets .rect .bottom + 10 ,
387
373
)
388
374
389
- self .save_button .rect .midright = (
375
+ self .export_button .rect .midright = (
390
376
self .exit_button .rect .move (- 10 , 0 ).midleft
391
377
)
392
378
393
- widgets .extend ((self .save_button , self .exit_button ))
379
+ widgets .extend ((self .export_button , self .exit_button ))
380
+
381
+ def get_overall_objects (self ):
382
+
383
+ ###
384
+ rd = self .report_data
385
+
386
+ ###
387
+ overall_objs = List2D ()
388
+
389
+ ##
390
+
391
+ result_label = Object2D .from_surface (
392
+ surface = (
393
+ render_text (
394
+ text = 'Overall result:' ,
395
+ ** TEXT_SETTINGS ,
396
+ )
397
+ ),
398
+ coordinates_name = 'midright' ,
399
+ coordinates_value = (0 , 0 ),
400
+ )
401
+
402
+ ##
403
+ overall_result = rd ['overall_result' ]
404
+
405
+ extra_settings = {
406
+ 'foreground_color' : RESULT_TO_COLOR [overall_result ],
407
+ 'font_height' : 40 ,
408
+ }
409
+
410
+ result_text = Object2D .from_surface (
411
+ surface = (
412
+ render_text (
413
+ text = overall_result ,
414
+ ** {
415
+ ** TEXT_SETTINGS ,
416
+ ** extra_settings ,
417
+ },
418
+ )
419
+ ),
420
+ coordinates_name = 'midleft' ,
421
+ coordinates_value = (10 , 0 ),
422
+ )
423
+
424
+ overall_objs .extend ((result_label , result_text ))
425
+
426
+ ###
427
+
428
+ top = overall_objs .rect .bottom + 10
429
+
430
+ for key , title , source in (
431
+ ('session_start_time' , "Start time" , rd ,),
432
+ ('session_end_time' , "End time" , rd ,),
433
+ ('utc_offset' , "Timezone" , rd ,),
434
+ ('passed' , "Passed" , RESULTS_COUNTER ),
435
+ ('failed' , "Failed" , RESULTS_COUNTER ),
436
+ ('error' , "Error" , RESULTS_COUNTER ),
437
+ ):
438
+
439
+ ## keys to skip
440
+
441
+ if key in ('cases_requested' , 'overall_result' , 'test_cases_stats' ):
442
+ continue
443
+
444
+ ##
445
+
446
+ overall_objs .append (
447
+ Object2D .from_surface (
448
+ surface = (
449
+ render_text (
450
+ text = f'{ title } :' ,
451
+ ** TEXT_SETTINGS ,
452
+ )
453
+ ),
454
+ coordinates_name = 'topright' ,
455
+ coordinates_value = (0 , top ),
456
+ )
457
+ )
458
+
459
+ text = (
460
+ str (source [key ]) + '/' + str (source .total ())
461
+ if isinstance (source , Counter )
462
+ else source [key ]
463
+ )
464
+
465
+ overall_objs .append (
466
+ Object2D .from_surface (
467
+ surface = (
468
+ render_text (
469
+ text = text ,
470
+ ** TEXT_SETTINGS ,
471
+ )
472
+ ),
473
+ coordinates_name = 'topleft' ,
474
+ coordinates_value = (10 , top ),
475
+ )
476
+ )
477
+
478
+ top = overall_objs .rect .bottom
479
+
480
+ ###
481
+ return overall_objs
482
+
483
+ def view_last_report (self ):
484
+ """Show report if there are report data, otherwise notify user."""
485
+
486
+ ### if there are report data, show report
487
+
488
+ if self .report_data is not None :
489
+
490
+ ### set loop holder to None
491
+ self .loop_holder = None
492
+
493
+ ### set itself as the current loop holder by raising
494
+ ### the corresponding exception
495
+ raise SwitchLoopException (self )
496
+
497
+ ### otherwise, notify user via dialog
498
+
499
+ else :
500
+
501
+ create_and_show_dialog (
502
+ "System tests were not performed yet."
503
+ " Go to \" Playback > Perform system testing session\" "
504
+ " to set and start a system testing session."
505
+ )
394
506
395
507
def handle_input (self ):
396
508
"""Process events from event queue."""
@@ -512,8 +624,8 @@ def draw(self):
512
624
### update screen
513
625
SERVICES_NS .update_screen ()
514
626
515
- def save_report (self ):
516
- ...
627
+ def export_report (self ):
628
+ """Export report to HTML."""
517
629
518
630
def exit (self ):
519
631
"""Exit report viewer."""
0 commit comments