All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ScriptTest_V6 Namespace Reference

Functions

def XMLwriter
 
def cleanXml
 
def main
 

Function Documentation

def ScriptTest_V6.cleanXml (   xmlFileName)
Removes xml illegal characters from a file.
@param xmlFileName: The name of the xml file.

Definition at line 85 of file ScriptTest_V6.py.

85 
86 def cleanXml(xmlFileName):
87  """
88  Removes xml illegal characters from a file.
89  @param xmlFileName: The name of the xml file.
90  """
91  _illegal_xml_chars_Re = re.compile(u'[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]')
92  xmlFile = open(xmlFileName,'r')
93  data = xmlFile.read()
94  xmlFile.close()
95  xmlFile = open(xmlFileName,'w')
96  xmlFile.write(_illegal_xml_chars_Re.sub("", data))
97  xmlFile.close()
98 
99 #-------------------------------------------------------------------------#
def ScriptTest_V6.main (   fileList)

Definition at line 100 of file ScriptTest_V6.py.

101 def main(fileList):
102  if not os.path.exists("./results"):
103  os.makedirs("./results")
104  DOB = time.localtime()
105  dateOfBegining = str(DOB[1])+"-"+str(DOB[2])+"-"+str(DOB[0])+"_"+str(DOB[3])+":"+str(DOB[4])
106  # Preparing the result file
107  nameResult = "./results/results_"+dateOfBegining+"_"+str(len(fileList))+".xml"
108  file = open(nameResult,"w+")
109  file.close()
110  Doc = ET.Element('Doc')
111  tree = ET.ElementTree(Doc)
112  tree.write(nameResult)
113 
114 
115 
116  #fileList=["/afs/cern.ch/user/v/valentin/workspace/Gaudi/GaudiExamples/tests/qmtest/gaudiexamples.qms/event_timeout_abort.qmt"]
117 
118  #fileList = ['./gaudiexamples.qms/root_io.qms/read.qmt']
119 
120  # Testing the file begining with "Test" or if it is a qmt file and doing the test
121  for file in fileList :
122  if file.endswith('_test.py') :
123  indexFilePart= file.rfind("/")
124  fileToImport = file[indexFilePart+1:]
125  sys.path.append(GT.RationalizePath(file)[:-len(fileToImport)-1])
126  imp = __import__(fileToImport[:-3])
127  fileToExec = imp.Test()
128  XMLwriter(fileToExec.runTest(),nameResult)
129  if file.endswith(".qmt"):
130  fileToTest = QT.QMTTest()
131  fileToTest.XMLParser(file)
132  XMLwriter(fileToTest.runTest(),nameResult)
133  cleanXml(nameResult)
134 
135 main(sys.argv)
def ScriptTest_V6.XMLwriter (   resultDic,
  fileName 
)

Definition at line 20 of file ScriptTest_V6.py.

20 
21 def XMLwriter(resultDic, fileName):
22  if resultDic is not None:
23 
24  #Creating the xml tree
25  try :
26  tree = ET.parse(fileName)
27  except :
28  cleanXml(fileName)
29  tree = ET.parse(fileName)
30  root = tree.getroot()
31 
32  #Test is the root
33  Test = ET.Element('Test')
34  Test.set('Status',resultDic['Status'])
35  del resultDic['Status']
36  Name = ET.SubElement(Test,'Name')
37  Name.text= XSS.escape(resultDic['Name'][:-4])
38  del resultDic['Name']
39 
40  # Branch containing all the measurments
41  Results = ET.SubElement(Test,'Results')
42 
43  NamedMeasurement = dict()
44  Value = dict()
45 
46  # Storing the measurments in dictionnaries, if not a String type, add an "if" condition
47  for key in resultDic :
48  if resultDic[key] !='' and key!='Measurement':
49  NamedMeasurement[key] = ET.SubElement(Results,'NamedMeasurement')
50  NamedMeasurement[key].set('name',key)
51 
52  # Setting type
53  if key=="Execution Time" : NamedMeasurement[key].set('type',"numeric/float")
54  if key=="exit_code" : NamedMeasurement[key].set('type',"numeric/integer")
55  else : NamedMeasurement[key].set('type',"String")
56 
57  # Setting value
58  Value[key] = ET.SubElement(NamedMeasurement[key],'Value')
59  if key=='Environment' :
60  env = resultDic[key]
61  Value[key].text = XSS.escape('\n'.join('{0}={1}'.format(k, env[k]) for k in sorted(env)))
62  elif key=='Causes':
63  Value[key].text = XSS.escape('\n'.join(resultDic[key]))
64  elif key=='Validator results':
65  valres= resultDic[key]
66  Value[key].text = XSS.escape('\n'.join('{0}={1}'.format(k, valres[k]) for k in valres)).encode("ascii", "xmlcharrefreplace")
67  elif key=='Unsupported platforms':
68  Value[key].text = XSS.escape('\n'.join(resultDic[key]))
69  else :
70  Value[key].text = XSS.escape(str(resultDic[key]))
71 
72 
73 
74  Measurement = ET.SubElement(Results,'Measurement')
75  Value['Measurement'] = ET.SubElement(Measurement,'Value')
76  Value['Measurement'].text = XSS.escape(resultDic['Measurement'])
77 
78 
79 
80  root.append(Test)
81  tree.write(fileName,encoding='utf-8')
82 
83 
84 #----------------------------------------------------------------------------------------#
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133