Skip to content

Commit

Permalink
Added the summary stats in results (gluster#425)
Browse files Browse the repository at this point in the history
* Added the summary stats in results

Added the summary stats in result_handler component.

Fixes: gluster#417

Signed-off-by: Ayush Ujjwal <[email protected]>

* pushed the table to top

Signed-off-by: Ayush Ujjwal <[email protected]>

* reformatted the output

Signed-off-by: Ayush Ujjwal <[email protected]>
  • Loading branch information
aujjwal-redhat authored May 24, 2021
1 parent d26333b commit ede4fb8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
93 changes: 87 additions & 6 deletions core/result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def _get_output(cls, test_results: dict, colorify: bool,
"""
cls.result = "Table:\n"
dcount = 0
ndcount = 0
dpass = 0
ndpass = 0
dtest = 0
ndtest = 0

for item in test_results:
if colorify:
Expand All @@ -40,13 +46,41 @@ def _get_output(cls, test_results: dict, colorify: bool,

table = PrettyTable(
['Volume Type', 'Test Result', 'Time taken (sec)'])

if test_results[item][0]['tcNature'] == 'disruptive':
dtest += 1
elif test_results[item][0]['tcNature'] == 'nonDisruptive':
ndtest += 1
for each_vol_test in test_results[item]:

table.add_row(
[each_vol_test['volType'], each_vol_test['testResult'],
each_vol_test['timeTaken']])

cls.result = (f"{cls.result}{str(table)}\n")
if each_vol_test['tcNature'] == 'disruptive':
dcount += 1
if each_vol_test['testResult'] == 'PASS':
dpass += 1
elif each_vol_test['tcNature'] == 'nonDisruptive':
ndcount += 1
if each_vol_test['testResult'] == 'PASS':
ndpass += 1

cls.result = (f"{cls.result}{str(table)}\n\n")

table = PrettyTable(['Category',
'Cases',
'Pass Percent'])

table.add_row(['nonDisruptive', ndtest,
0 if ndcount == 0 else (ndpass/ndcount)*100])
table.add_row(['Disruptive', dtest,
0 if dcount == 0 else (dpass/dcount)*100])
table.add_row(['Total', ndtest+dtest,
(0 if (ndcount + dcount == 0)
else ((ndpass + dpass)/(ndcount + dcount))*100)])

cls.result = (f"Summary:\n{str(table)}\n{cls.result}\n")

cls.result = (f"{cls.result}\nFramework runtime : {total_time}\n")

Expand Down Expand Up @@ -99,17 +133,64 @@ def store_results_in_excelsheet(cls, excel_sheet: str, test_results: dict,

result_sheet = wb.add_sheet('Result Sheet')

dcount = 0
ndcount = 0
dpass = 0
ndpass = 0
dtest = 0
ndtest = 0

for item in test_results:
if test_results[item][0]['tcNature'] == 'disruptive':
dtest += 1
elif test_results[item][0]['tcNature'] == 'nonDisruptive':
ndtest += 1

for each_vol_test in test_results[item]:

if each_vol_test['tcNature'] == 'disruptive':
dcount += 1
if each_vol_test['testResult'] == 'PASS':
dpass += 1
elif each_vol_test['tcNature'] == 'nonDisruptive':
ndcount += 1
if each_vol_test['testResult'] == 'PASS':
ndpass += 1

row = 0
style = xlwt.easyxf('font: bold 1')

result_sheet.write(row, 0, 'Total time taken (s)', style)
result_sheet.write(row, 1, total_time)
result_sheet.write(row, 0, 'Category', style)
result_sheet.write(row, 1, 'Cases', style)
result_sheet.write(row, 2, 'Pass Percent', style)

row += 1
result_sheet.write(row, 0, 'nonDisruptive')
result_sheet.write(row, 1, ndtest)
result_sheet.write(row, 2,
0 if ndcount == 0
else (ndpass/ndcount)*100)

row += 1
result_sheet.write(row, 0, 'Disruptive')
result_sheet.write(row, 1, dtest)
result_sheet.write(row, 2,
0 if dcount == 0
else (dpass/dcount)*100)

test_case_count = len(test_results)
result_sheet.write(row, 0, 'Total number of TCs', style)
result_sheet.write(row, 1, test_case_count)
row += 1
result_sheet.write(row, 0, 'Total')
result_sheet.write(row, 1, ndtest + dtest)
result_sheet.write(row, 2,
(0 if (ndcount + dcount == 0)
else
((ndpass + dpass)/(ndcount + dcount))*100))

row += 2

result_sheet.write(row, 0, 'Total time taken (s)', style)
result_sheet.write(row, 1, total_time)
row += 2

for item in test_results:
result_sheet.write(row, 0, item, style)
Expand Down
1 change: 1 addition & 0 deletions core/test_list_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def create_test_dict(cls, path: str, excluded_tests: list,
test_dict["componentName"] = test_case_path.split("/")[-2]
test_dict["testClass"] = cls._get_test_class(test_case_path)
test_dict["testType"] = test_case_path.split("/")[-3]
test_dict["tcNature"] = test_flags["tcNature"]
if test_flags["tcNature"] == "disruptive":
for vol_type in test_flags["volType"]:
if vol_type not in valid_vol_types:
Expand Down
1 change: 1 addition & 0 deletions core/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def _run_test(cls, test_dict: dict):
test_stats = runner_thread_obj.run_thread()

test_stats['timeTaken'] = time.time() - start
test_stats['tcNature'] = test_dict['tcNature']
result_text = f"{test_dict['moduleName'][:-3]}-{test_dict['volType']}"
if test_stats['testResult']:
test_stats['testResult'] = "PASS"
Expand Down

0 comments on commit ede4fb8

Please sign in to comment.