-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongest-tests.py
More file actions
executable file
·76 lines (62 loc) · 2.16 KB
/
longest-tests.py
File metadata and controls
executable file
·76 lines (62 loc) · 2.16 KB
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
#!/usr/bin/python
import os
import glob
import re
import argparse
filePatternToTest="TEST-"
timeRegex="time=\"[0-9]*(\.[0-9]*)*\""
classNameRegex="classname=\"[A-Za-z0-9\.]*\""
nameRegex="name=\"[A-Za-z0-9_]*\""
testCases = []
baseDirectory = '.'
def main():
files = findFiles()
readFiles(files)
testCases = sortTestCases()
testCases.reverse()
print "Running test cases"
print "============================="
for item in testCases:
print item
#Find all surefire reports in the current directory
def findFiles():
tests = []
for path,dirName,fileNames in os.walk(baseDirectory):
for fileName in fileNames:
if fileName.startswith(filePatternToTest):
tests.append(os.path.join(path,fileName))
return tests
#Read each surefire report and pass the content to parseContent method
def readFiles(files):
for file in files:
with open(file, "rb") as openedFile:
content = openedFile.read()
openedFile.closed
parseContent(content)
#Find all test cases within the the content passed and add name, class and timings to the testCases array
def parseContent(content):
matches = re.findall("<testcase .*/>", content)
for testCase in matches:
value = getValues(testCase)
testCases.append(value)
#Parse a testCase and pull out the classname, time and name of each test
def getValues(testCase):
timeAttribute = re.search(timeRegex, testCase)
if timeAttribute != None:
timeAttribute = timeAttribute.group(0)
timeAttribute = float(timeAttribute[6:-1])
classnameAttribute = re.search(classNameRegex, testCase)
if classnameAttribute != None:
classnameAttribute = classnameAttribute.group(0)
nameAttribute = re.search(nameRegex, testCase)
if nameAttribute != None:
nameAttribute = nameAttribute.group(0)
return tuple([timeAttribute, classnameAttribute, nameAttribute])
def sortTestCases():
return sorted(testCases, key=lambda row: row[0])
#Parse arguments
parser = argparse.ArgumentParser(description="Find the longest running maven tests.")
parser.add_argument('-d', help='Base directory to find the unit tests', required=False, action='store', default='.', dest='baseDirectory')
arguments = parser.parse_args()
baseDirectory = arguments.baseDirectory
main()