5 import xml.etree.ElementTree
as ET
7 import xml.sax.saxutils
as XSS
21 if resultDic
is not None:
25 tree = ET.parse(fileName)
28 tree = ET.parse(fileName)
32 Test = ET.Element(
'Test')
33 Test.set(
'Status',resultDic[
'Status'])
34 del resultDic[
'Status']
35 Name = ET.SubElement(Test,
'Name')
36 Name.text= XSS.escape(resultDic[
'Name'][:-4])
40 Results = ET.SubElement(Test,
'Results')
42 NamedMeasurement = dict()
46 for key
in resultDic :
47 if resultDic[key] !=
'' and key!=
'Measurement':
48 NamedMeasurement[key] = ET.SubElement(Results,
'NamedMeasurement')
49 NamedMeasurement[key].set(
'name',key)
52 if key==
"Execution Time" : NamedMeasurement[key].set(
'type',
"numeric/float")
53 if key==
"exit_code" : NamedMeasurement[key].set(
'type',
"numeric/integer")
54 else : NamedMeasurement[key].set(
'type',
"String")
57 Value[key] = ET.SubElement(NamedMeasurement[key],
'Value')
58 if key==
'Environment' :
60 Value[key].text = XSS.escape(
'\n'.join(
'{0}={1}'.
format(k, env[k])
for k
in sorted(env)))
62 Value[key].text = XSS.escape(
'\n'.join(resultDic[key]))
63 elif key==
'Validator results':
64 valres= resultDic[key]
65 Value[key].text = XSS.escape(
'\n'.join(
'{0}={1}'.
format(k, valres[k])
for k
in valres)).encode(
"ascii",
"xmlcharrefreplace")
66 elif key==
'Unsupported platforms':
67 Value[key].text = XSS.escape(
'\n'.join(resultDic[key]))
69 Value[key].text = XSS.escape(str(resultDic[key]))
73 Measurement = ET.SubElement(Results,
'Measurement')
74 Value[
'Measurement'] = ET.SubElement(Measurement,
'Value')
75 Value[
'Measurement'].text = XSS.escape(resultDic[
'Measurement'])
80 tree.write(fileName,encoding=
'utf-8')
87 Removes xml illegal characters from a file.
88 @param xmlFileName: The name of the xml file.
90 _illegal_xml_chars_Re = re.compile(
u'[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]')
91 xmlFile = open(xmlFileName,
'r')
94 xmlFile = open(xmlFileName,'w')
95 xmlFile.write(_illegal_xml_chars_Re.sub(
"", data))
101 if not os.path.exists(
"./results"):
102 os.makedirs(
"./results")
103 DOB = time.localtime()
104 dateOfBegining = str(DOB[1])+
"-"+str(DOB[2])+
"-"+str(DOB[0])+
"_"+str(DOB[3])+
":"+str(DOB[4])
106 nameResult =
"./results/results_"+dateOfBegining+
"_"+str(len(fileList))+
".xml"
107 file = open(nameResult,
"w+")
109 Doc = ET.Element(
'Doc')
110 tree = ET.ElementTree(Doc)
111 tree.write(nameResult)
120 for file
in fileList :
121 if file.endswith(
'_test.py') :
122 indexFilePart= file.rfind(
"/")
123 fileToImport = file[indexFilePart+1:]
124 sys.path.append(GT.RationalizePath(file)[:-len(fileToImport)-1])
125 imp = __import__(fileToImport[:-3])
126 fileToExec = imp.Test()
127 XMLwriter(fileToExec.runTest(),nameResult)
128 if file.endswith(
".qmt"):
129 fileToTest = QT.QMTTest()
130 fileToTest.XMLParser(file)
131 XMLwriter(fileToTest.runTest(),nameResult)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".