forked from cms-sw/cms-sw.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-unitTestSummary-logs
executable file
·36 lines (33 loc) · 1.1 KB
/
process-unitTestSummary-logs
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
#!/usr/bin/env python
from argparse import ArgumentParser
from os.path import exists
from sys import exit
from json import dumps
import re
from operator import itemgetter
BEGIN_TEST = "^ ([^/]*/[^ ]*) :[ ]*$"
TEST_OK = '^.* OK:(\d+)\s+fail:(\d+)\s*$'
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("input")
args = parser.parse_args()
if not exists(args.input):
print "Please specify an input file"
exit(1)
buf = open(args.input).read()
results = {}
currentPackage = None
for l in buf.split("\n"):
isBegin = re.match(BEGIN_TEST, l)
if isBegin:
currentPackage = isBegin.group(1)
results[currentPackage] = {"name": currentPackage, "errors": 0, "ok": 0}
continue
if (not currentPackage) or (not currentPackage in l): continue
m = re.match(TEST_OK, l)
if m:
results[currentPackage]["ok"]=int(m.group(1))
results[currentPackage]["errors"]=int(m.group(2))
results = results.values()
results.sort(key=lambda x : (x["errors"], x["name"]), reverse=True)
print dumps(results, sort_keys=True, indent=2, separators=(',', ': '))