Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions common/testexecresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from .resultsview import RunCommandResultsView
from .testresult import TestResults

import matplotlib.pyplot as plt
import numpy as np
import re


class TestExecResults():
def __init__(self, test_results):
Expand All @@ -31,3 +35,33 @@ def get_ExecuteNotebookResult(self, notebook_path, test_results):
'N/A', None, test_results)

return ExecuteNotebookResult('N/A', 'N/A', notebook_result, 'N/A')

def plot_pie_chart(self, title=None, legend=False, size=5):
"""
Plot a pie chart representing the distribution of test cases between 'Passed' and 'Failed' categories.

Parameters:
- title (str, optional): Title for the pie chart.
- legend (bool, optional): Whether to display a legend.
- size (int, optional): Size of the pie chart.

This method accepts three parameters:
1. title (str, optional): Title for the pie chart.
2. legend (bool, optional): Set to True to display a legend; False to hide it.
3. size (int, optional): Size of the pie chart (both width and height).

Note: The pie chart is based on the test results in the 'self.test_results' attribute.
"""
pass_fail_count = self.test_results.get_counts()
total_testcases = sum(pass_fail_count)

plt.figure(figsize=(size, size))
plt.pie(np.array(pass_fail_count), labels=["Passed", "Failed"],
autopct=lambda p: '' if re.search(r'^0+$', string='{:.0f}'.format(p * total_testcases / 100)) else '{:.0f}'.format(p * total_testcases / 100),
shadow=True, colors=["#4CAF50", "red"])
if legend:
plt.legend(title="Test Result", bbox_to_anchor=(1.1, 0.5), bbox_transform=plt.gcf().transFigure,
loc="lower right")
if title is not None:
plt.title(title, fontweight='bold')
plt.show()
14 changes: 12 additions & 2 deletions common/testresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
def get_test_results():
return TestResults()


class TestResults(PickleSerializable):
def __init__(self):
self.results = []
Expand All @@ -27,7 +28,7 @@ def append(self, testresult):

self.results.append(testresult)
self.test_cases = self.test_cases + 1
if (not testresult.passed):
if not testresult.passed:
self.num_failures = self.num_failures + 1

total_execution_time = self.total_execution_time + testresult.execution_time
Expand Down Expand Up @@ -64,11 +65,20 @@ def __eq__(self, other):

def __item_in_list_equalto(self, expected_item):
for item in self.results:
if (item == expected_item):
if item == expected_item:
return True

return False

def get_counts(self):
"""
This method returns the tuple having frequency of passed and failed test cases.
"""
passed = sum(1 for item in self.results if item.passed)
failed = len(self.results) - passed
return passed, failed


class TestResult:
def __init__(self, test_name, passed,
execution_time, tags, exception=None, stack_trace=""):
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ requests
fire
junit_xml
py4j

numpy
matplotlib
regex