This repository was archived by the owner on Oct 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.py
63 lines (51 loc) · 1.64 KB
/
results.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
import xml.etree.ElementTree as ET
import os
def indent(elem, level=0):
i = "\n" + level*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
def save_results( board_name, board_number, results ):
fname = "results/%s_results.xml" % board_name
if not os.path.exists(fname):
tree = ET.ElementTree( ET.fromstring("<results_file></results_file>") )
else:
tree = ET.parse( fname )
root = tree.getroot()
board = None
# Find the board
for e in root:
if e.attrib.has_key("number") and int(e.attrib["number"]) == board_number:
board = e
break
if board == None:
"Need to add a new entry into the tree"
board = ET.Element("board")
root.append(board)
board.clear()
board.set( "number", str(board_number) )
# Add test results:
for x in range(0, len(results)):
result = results[x].passed
ent = ET.Element("test")
ent.set( "number", str(x) )
if results[x].name != "":
ent.set( "name", results[x].name )
if result == None:
continue
elif result:
ent.set( "result", "pass" )
elif result == False:
ent.set( "result", "fail" )
board.append(ent)
indent(root)
tree.write( fname )