Debian Codegraph @

testrunner/junitmerge.py

raw symbols SCIP
1 """
2 simple scrpt for junitxml file merging
3 """
4
5 from lxml.etree import parse, Element, tostring
6 from collections import defaultdict
7 import argparse
8
9 parser = argparse.ArgumentParser()
10 parser.add_argument('--out')
11 parser.add_argument('path', nargs='...')
12
13 opts = parser.parse_args()
14
15 files = []
16
17 for path in opts.path:
18 files.append(parse(path))
19
20
21 accum = defaultdict(int)
22 children = []
23
24 for item in files:
25 root = item.getroot()
26 for key, value in root.attrib.items():
27 if not value:
28 continue
29 value = float(value) if '.' in value else int(value)
30 accum[key] += value
31 children.extend(root)
32
33
34
35
36 assert len(children) == sum(accum[x] for x in 'tests errors skips'.split())
37
38 children.sort(key=lambda x:(x.attrib['classname'], x.attrib['name']))
39
40
41
42 new = Element('testsuite', dict((k, str(v)) for k, v in accum.items()))
43 new.extend(children)
44
45 data = tostring(new)
46
47 with open(opts.out, 'w') as fp:
48 fp.write(data)
49