Newer
Older
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
#!/usr/bin/env python3
import json
from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, IntAttr, FloatAttr
# Create the new element by subclassing Element or one of its child class,
## and add custom attributes to it.
#class MyTestCase(TestCase):
# foo = Attr()
# Add the custom attribute
#TestCase.id = IntAttr('id')
TestCase.efficiency = FloatAttr('efficiency')
#TestCase.custom = Attr('custom')
#case = TestCase()
#case.id = 123
#case.rate = 0.95
#case.custom = 'foobar'
# After looking at two different python libraries (junit-xml and junitparser)
# junitparser looks the most robust
# https://github.com/weiwei/junitparser
def merge_results():
results = None;
with open("results/dvcs/dvcs_tests.json","r") as f:
results = json.load(f)
# Create suite and add cases
suite = TestSuite('dvcs')
suite.add_property('energy', '10-on-100')
for tname,tres in results.items():
for ttype, tval in tres.items():
# Create cases
case1 = TestCase(tname)
case1.time = 1.0
case1.efficiency = tval
case1.classname = ttype
suite.add_testcase(case1)
xml = JUnitXml()
xml.add_testsuite(suite)
xml.write('results/dvcs/dvcs_report.xml',pretty=True)
#test code for junit-xml:
#from junit_xml import TestSuite, TestCase
# test_cases = []
# print(test_name)
# print(test_res)
# for test_type, test_val in test_res.items():
# test_cases.append(TestCase(test_name, "dvcs.dvcs_tests.{}".format(test_type), 10, str(test_val), 'I am stderr!'))
# ts = TestSuite("my test suite", test_cases)
# # pretty printing is on by default but can be disabled using prettyprint=False
# print(TestSuite.to_xml_string([ts]))
# # you can also write the XML to a file and not pretty print it
# with open('results/dvcs/dvcs_report.xml', 'w') as f:
# TestSuite.to_file(f, [ts], prettyprint=True)
if __name__ == "__main__":
# execute only if run as a script
merge_results()