Skip to content

Commit e78885c

Browse files
wip: system testing service
1 parent f67fded commit e78885c

File tree

3 files changed

+169
-49
lines changed

3 files changed

+169
-49
lines changed

nodezator/our3rdlibs/svgutils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_pie_chart_svg_text(
8383
place_items_clockwise=True,
8484
):
8585

86-
total_radius = fill_radius + inner_outline_width
86+
total_radius = fill_radius + outer_outline_width
8787
width = height = total_radius * 2
8888
cx, cy = width // 2, height // 2
8989

nodezator/systemtesting/reportviewer.py

+160-48
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
from ..config import APP_REFS
3535

36+
from ..dialog import create_and_show_dialog
37+
3638
from ..pygamesetup import SERVICES_NS, SCREEN_RECT
3739

3840
from ..ourstdlibs.behaviour import empty_function
@@ -78,12 +80,6 @@
7880
REPORT_BG = (235, 235, 250)
7981
REPORT_FG = (28, 28, 28)
8082

81-
RESULT_TO_COLOR = {
82-
'passed': (30, 160, 70),
83-
'error': (255, 30, 70),
84-
'failed': (255, 255, 70),
85-
}
86-
8783
TEXT_SETTINGS = {
8884
"font_height": ENC_SANS_BOLD_FONT_HEIGHT,
8985
"font_path": ENC_SANS_BOLD_FONT_PATH,
@@ -101,11 +97,13 @@
10197
}
10298

10399
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),
107103
}
108104

105+
RESULT_TO_COLOR = PIE_COLOR_MAP
106+
109107
RESULTS = []
110108
RESULTS_COUNTER = Counter()
111109

@@ -205,9 +203,14 @@ def __init__(self):
205203
### build widgets
206204
self.create_general_widgets()
207205

208-
### create placeholder attribute to hold next loop holder
206+
### create placeholder attributes
207+
208+
## to hold next loop holder
209209
self.loop_holder = None
210210

211+
## to hold report data
212+
self.report_data = None
213+
211214
### center form and also append centering method
212215
### as a window resize setup
213216

@@ -231,7 +234,7 @@ def create_general_widgets(self):
231234
"""Build general widgets to use/reuse in reports."""
232235
### define an initial topleft relative to the
233236
### topleft corner of the form 'rect'
234-
topleft = self.rect.move(10, 10).topleft
237+
topleft = self.rect.move(20, 20).topleft
235238

236239
### instantiate a caption for the form
237240

@@ -270,21 +273,24 @@ def create_general_widgets(self):
270273

271274
midright = self.exit_button.rect.move(-10, 0).midleft
272275

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,
276279
coordinates_name='midright',
277280
coordinates_value=midright,
278281
**BUTTON_SETTINGS,
279282
)
280283

281-
draw_depth_finish(self.save_button.image)
284+
draw_depth_finish(self.export_button.image)
282285

283286
## store them
284-
self.widgets.extend((self.save_button, self.exit_button))
287+
self.widgets.extend((self.export_button, self.exit_button))
285288

286289
def prepare_report(self, report_data):
287290
"""Create visuals showing report results."""
291+
### store report data
292+
self.report_data = report_data
293+
288294
### reference widgets locally
289295
widgets = self.widgets
290296

@@ -293,35 +299,11 @@ def prepare_report(self, report_data):
293299

294300
### reposition and store caption
295301

296-
self.caption_label.rect.topleft = self.rect.move(10, 10).topleft
302+
self.caption_label.rect.topleft = self.rect.move(20, 20).topleft
297303
widgets.append(self.caption_label)
298304

299305
### create report-related visuals
300306

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-
325307
## create pie chart
326308

327309
# update results
@@ -359,7 +341,7 @@ def prepare_report(self, report_data):
359341
(pie_surf, PIE_LEGEND),
360342
retrieve_pos_from='midright',
361343
assign_pos_to='midleft',
362-
offset_pos_by=(10, 0),
344+
offset_pos_by=(20, 0),
363345
background_color=REPORT_BG,
364346
)
365347
)
@@ -377,20 +359,150 @@ def prepare_report(self, report_data):
377359
# append to widgets
378360
widgets.append(pie)
379361

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)
381367

382368
### position and store buttons
383369

384370
self.exit_button.rect.bottomright = (
385371
self.rect.right - 10,
386-
widgets.rect.bottom + 20,
372+
widgets.rect.bottom + 10,
387373
)
388374

389-
self.save_button.rect.midright = (
375+
self.export_button.rect.midright = (
390376
self.exit_button.rect.move(-10, 0).midleft
391377
)
392378

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+
)
394506

395507
def handle_input(self):
396508
"""Process events from event queue."""
@@ -512,8 +624,8 @@ def draw(self):
512624
### update screen
513625
SERVICES_NS.update_screen()
514626

515-
def save_report(self):
516-
...
627+
def export_report(self):
628+
"""Export report to HTML."""
517629

518630
def exit(self):
519631
"""Exit report viewer."""

nodezator/winman/menu.py

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
THIRDLIB_CATEGORY_TO_SORTED_ITEMS,
5454
)
5555

56+
from ..systemtesting.reportviewer import report_viewer
57+
58+
59+
5660
### class definition
5761

5862

@@ -143,6 +147,10 @@ def create_menubar(self):
143147
),
144148
},
145149
{"label": "------"},
150+
{
151+
"label": "Show system testing report",
152+
"command": report_viewer.view_last_report,
153+
},
146154
{
147155
"label": "Show user log",
148156
"key_text": "Shift+Ctrl+J",

0 commit comments

Comments
 (0)