-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.py
executable file
·111 lines (83 loc) · 3.05 KB
/
entrypoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
from pathlib import Path
import xml.etree.ElementTree as ET
class ResultCount:
title = ""
total = 0
skipped = 0
failed = 0
errors = 0
statusEmoji = ":cross_mark:"
successRate = 0
def __init__(self, title: str) -> None:
self.title = title
def __repr__(self) -> str:
return f"{self.statusEmoji} {self.title} - {self.successRate}% #:pointing_right: total={self.total}, skipped={self.skipped}, failed={self.failed}, errors={self.errors}"
def calculateSuccessRate(self):
success = self.total - (self.failed + self.errors)
self.successRate = round(success * 100 / self.total, 2)
if self.successRate == 100.0:
self.statusEmoji = ":check_mark:"
class FailedTest:
errors = []
def __repr__(self) -> str:
if len(self.errors) == 0:
return ""
else:
title = ":smiling_tear: Failed Test Cases"
errorsStr = ''.join(self.errors)
return f"{title}#{errorsStr}"
def add(self, methodName: str, className: str):
self.errors.append(f":file: {methodName} in {className}#")
def parse(path, rc: ResultCount, failed: FailedTest):
tree = ET.parse(path)
root = tree.getroot()
attributes = root.attrib
countTotal = attributes["tests"]
countSkipped = attributes["skipped"]
countFailed = attributes["failures"]
countError = attributes["errors"]
rc.total += int(countTotal)
rc.skipped += int(countSkipped)
rc.failed += int(countFailed)
rc.errors += int(countError)
for element in root:
if element.tag == "testcase":
if element.find("failure") != None:
attrib = element.attrib
methodName = attrib["name"]
className = attrib["classname"].split(".")[-1]
failed.add(methodName, className)
def traverse(inte: ResultCount, repo: ResultCount, uc: ResultCount, other: ResultCount, failed: FailedTest):
pathlist = Path().rglob("TEST-*.xml")
for p in pathlist:
path = str(p)
if path.lower().endswith("integrationtest.xml"):
parse(path, inte, failed)
elif path.lower().endswith("repositorytest.xml"):
parse(path, repo, failed)
elif path.lower().endswith("usecasetest.xml"):
parse(path, uc, failed)
else:
parse(path, other, failed)
def main():
inte = ResultCount("Integration")
repo = ResultCount("Repository")
uc = ResultCount("Use Case")
other = ResultCount("Others")
failed = FailedTest()
traverse(inte, repo, uc, other, failed)
inte.calculateSuccessRate()
repo.calculateSuccessRate()
uc.calculateSuccessRate()
other.calculateSuccessRate()
result = ":memo: SDK Test Report#" + \
str(inte) + "##" + str(repo) + "##" + str(uc) + "##" + str(other) + "##" + str(failed)
print(result)
try:
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f'SDK_TEST_REPORT={result}', file=fh)
except:
pass
if __name__ == "__main__":
main()