GaudiTest.XMLResultStream Class Reference
Inheritance diagram for GaudiTest.XMLResultStream:
Collaboration diagram for GaudiTest.XMLResultStream:

Public Member Functions

def __init__ (self, arguments=None, args)
 
def WriteAnnotation (self, key, value)
 
def WriteResult (self, result)
 
def Summarize (self)
 

Static Public Attributes

list arguments
 

Private Attributes

 _xmlFile
 
 _startTime
 
 _endTime
 
 _tree
 
 _site
 
 _Testing
 
 _StartDateTime
 
 _StartTestTime
 
 _TestList
 
 _EndDateTime
 End time elements. More...
 
 _EndTestTime
 
 _ElapsedMinutes
 

Detailed Description

An 'XMLResultStream' writes its output to a Ctest XML file.

The argument 'dir' is used to select the destination file for the XML
report.
The destination directory may already contain the report from a previous run
(for example of a different package), in which case it will be overrided to
with the new data.

Definition at line 1949 of file GaudiTest.py.

Constructor & Destructor Documentation

def GaudiTest.XMLResultStream.__init__ (   self,
  arguments = None,
  args 
)
Prepare the destination directory.

Creates the destination directory and store in it some preliminary
annotations .

Definition at line 1976 of file GaudiTest.py.

1976  def __init__(self, arguments = None, **args):
1977  """Prepare the destination directory.
1978 
1979  Creates the destination directory and store in it some preliminary
1980  annotations .
1981  """
1982  ResultStream.__init__(self, arguments, **args)
1983 
1984  self._xmlFile = os.path.join(self.dir, self.prefix + 'Test.xml')
1985 
1986  # add some global variable
1987  self._startTime = None
1988  self._endTime = None
1989  # Format the XML file if it not exists
1990  if not os.path.isfile(self._xmlFile):
1991  # check that the container directory exists and create it if not
1992  if not os.path.exists(os.path.dirname(self._xmlFile)):
1993  os.makedirs(os.path.dirname(self._xmlFile))
1994 
1995  newdataset = ET.Element("newdataset")
1996  self._tree = ET.ElementTree(newdataset)
1997  self._tree.write(self._xmlFile)
1998  else :
1999  # Read the xml file
2000  self._tree = ET.parse(self._xmlFile)
2001  newdataset = self._tree.getroot()
2002 
2003  # Find the corresponding site, if do not exist, create it
2004 
2005  #site = newdataset.find('Site[@BuildStamp="'+result["qmtest.start_time"]+'"][@OSPlatform="'+os.getenv("CMTOPT")+'"]')
2006  # I don't know why this syntax doesn't work. Maybe it is because of the python version. Indeed,
2007  # This works well in the python terminal. So I have to make a for:
2008  for site in newdataset.getiterator() :
2009  if site.get("OSPlatform") == os.uname()[4]: # and site.get("BuildStamp") == result["qmtest.start_time"] and:
2010  # Here we can add some variable to define the difference beetween 2 site
2011  self._site = site
2012  break
2013  else :
2014  site = None
2015 
2016 
2017  if site is None :
2018  import socket
2019  import multiprocessing
2020  attrib = {
2021  "BuildName" : os.getenv("CMTCONFIG"),
2022  "Name" : os.uname()[1] ,
2023  "Generator" : "QMTest "+qm.version ,
2024  "OSName" : os.uname()[0] ,
2025  "Hostname" : socket.gethostname() ,
2026  "OSRelease" : os.uname()[2] ,
2027  "OSVersion" :os.uname()[3] ,
2028  "OSPlatform" :os.uname()[4] ,
2029  "Is64Bits" : "unknown" ,
2030  "VendorString" : "unknown" ,
2031  "VendorID" :"unknown" ,
2032  "FamilyID" :"unknown" ,
2033  "ModelID" :"unknown" ,
2034  "ProcessorCacheSize" :"unknown" ,
2035  "NumberOfLogicalCPU" : str(multiprocessing.cpu_count()) ,
2036  "NumberOfPhysicalCPU" : "0" ,
2037  "TotalVirtualMemory" : "0" ,
2038  "TotalPhysicalMemory" : "0" ,
2039  "LogicalProcessorsPerPhysical" : "0" ,
2040  "ProcessorClockFrequency" : "0" ,
2041  }
2042  self._site = ET.SubElement(newdataset, "Site", attrib)
2043  self._Testing = ET.SubElement(self._site,"Testing")
2044 
2045  # Start time elements
2046  self._StartDateTime = ET.SubElement(self._Testing, "StartDateTime")
2047 
2048  self._StartTestTime = ET.SubElement(self._Testing, "StartTestTime")
2049 
2050 
2051  self._TestList = ET.SubElement(self._Testing, "TestList")
2052 
2053  ## End time elements
2054  self._EndDateTime = ET.SubElement(self._Testing, "EndDateTime")
2055 
2056 
2057  self._EndTestTime = ET.SubElement(self._Testing, "EndTestTime")
2058 
2059 
2060 
2061  self._ElapsedMinutes = ET.SubElement(self._Testing, "ElapsedMinutes")
2062 
2063 
2064  else : # We get the elements
2065  self._Testing = self._site.find("Testing")
2066  self._StartDateTime = self._Testing.find("StartDateTime")
2067  self._StartTestTime = self._Testing.find("StartTestTime")
2068  self._TestList = self._Testing.find("TestList")
2069  self._EndDateTime = self._Testing.find("EndDateTime")
2070  self._EndTestTime = self._Testing.find("EndTestTime")
2071  self._ElapsedMinutes = self._Testing.find("ElapsedMinutes")
2072 
2073  """
2074  # Add some non-QMTest attributes
2075  if "CMTCONFIG" in os.environ:
2076  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
2077  import socket
2078  self.WriteAnnotation("hostname", socket.gethostname())
2079  """
2080 
2081 
_EndDateTime
End time elements.
Definition: GaudiTest.py:2054
def __init__(self, arguments=None, args)
Definition: GaudiTest.py:1976

Member Function Documentation

def GaudiTest.XMLResultStream.Summarize (   self)

Definition at line 2231 of file GaudiTest.py.

2231  def Summarize(self):
2232 
2233  # Set the final end date time
2234  self._EndTestTime.text = str(self._endTime)
2235  self._EndDateTime.text = time.strftime("%b %d %H:%M %Z", time.localtime(self._endTime))
2236 
2237  # Compute the total duration
2238  if self._endTime and self._startTime:
2239  delta = self._endTime - self._startTime
2240  else:
2241  delta = 0
2242  self._ElapsedMinutes.text = str(delta/60)
2243 
2244  # Write into the file
2245  self._tree.write(self._xmlFile, "utf-8") #,True) in python 2.7 to add the xml header
2246 
def GaudiTest.XMLResultStream.WriteAnnotation (   self,
  key,
  value 
)

Definition at line 2082 of file GaudiTest.py.

2082  def WriteAnnotation(self, key, value):
2083  if key == "qmtest.run.start_time":
2084  if self._site.get("qmtest.run.start_time") is not None :
2085  return None
2086  self._site.set(str(key),str(value))
def WriteAnnotation(self, key, value)
Definition: GaudiTest.py:2082
def GaudiTest.XMLResultStream.WriteResult (   self,
  result 
)
Prepare the test result directory in the destination directory storing
into it the result fields.
A summary of the test result is stored both in a file in the test directory
and in the global summary file.

Definition at line 2087 of file GaudiTest.py.

2087  def WriteResult(self, result):
2088  """Prepare the test result directory in the destination directory storing
2089  into it the result fields.
2090  A summary of the test result is stored both in a file in the test directory
2091  and in the global summary file.
2092  """
2093  summary = {}
2094  summary["id"] = result.GetId()
2095  summary["outcome"] = result.GetOutcome()
2096  summary["cause"] = result.GetCause()
2097  summary["fields"] = result.keys()
2098  summary["fields"].sort()
2099 
2100 
2101  # Since we miss proper JSON support, I hack a bit
2102  for f in ["id", "outcome", "cause"]:
2103  summary[f] = str(summary[f])
2104  summary["fields"] = map(str, summary["fields"])
2105 
2106 
2107  # format
2108  # package_Test.xml
2109 
2110  if "qmtest.start_time" in summary["fields"]:
2111  haveStartDate = True
2112  else :
2113  haveStartDate = False
2114  if "qmtest.end_time" in summary["fields"]:
2115  haveEndDate = True
2116  else :
2117  haveEndDate = False
2118 
2119  # writing the start date time
2120  if haveStartDate:
2121  self._startTime = calendar.timegm(time.strptime(result["qmtest.start_time"], "%Y-%m-%dT%H:%M:%SZ"))
2122  if self._StartTestTime.text is None:
2123  self._StartDateTime.text = time.strftime("%b %d %H:%M %Z", time.localtime(self._startTime))
2124  self._StartTestTime.text = str(self._startTime)
2125  self._site.set("BuildStamp" , result["qmtest.start_time"] )
2126 
2127  #Save the end date time in memory
2128  if haveEndDate:
2129  self._endTime = calendar.timegm(time.strptime(result["qmtest.end_time"], "%Y-%m-%dT%H:%M:%SZ"))
2130 
2131 
2132  #add the current test to the test list
2133  tl = ET.Element("Test")
2134  tl.text = summary["id"]
2135  self._TestList.insert(0,tl)
2136 
2137  #Fill the current test
2138  Test = ET.Element("Test")
2139  if summary["outcome"] == "PASS":
2140  Test.set("Status", "passed")
2141  elif summary["outcome"] == "FAIL":
2142  Test.set("Status", "failed")
2143  elif summary["outcome"] == "SKIPPED" or summary["outcome"] == "UNTESTED":
2144  Test.set("Status", "skipped")
2145  elif summary["outcome"] == "ERROR":
2146  Test.set("Status", "failed")
2147  Name = ET.SubElement(Test, "Name",)
2148  Name.text = summary["id"]
2149  Results = ET.SubElement(Test, "Results")
2150 
2151  # add the test after the other test
2152  self._Testing.insert(3,Test)
2153 
2154  if haveStartDate and haveEndDate:
2155  # Compute the test duration
2156  delta = self._endTime - self._startTime
2157  testduration = str(delta)
2158  Testduration= ET.SubElement(Results,"NamedMeasurement")
2159  Testduration.set("name","Execution Time")
2160  Testduration.set("type","numeric/float" )
2161  value = ET.SubElement(Testduration, "Value")
2162  value.text = testduration
2163 
2164  #remove the fields that we store in a different way
2165  for n in ("qmtest.end_time", "qmtest.start_time", "qmtest.cause", "ExecTest.stdout"):
2166  if n in summary["fields"]:
2167  summary["fields"].remove(n)
2168 
2169  # Here we can add some NamedMeasurment which we know the type
2170  #
2171  if "ExecTest.exit_code" in summary["fields"] :
2172  summary["fields"].remove("ExecTest.exit_code")
2173  ExitCode= ET.SubElement(Results,"NamedMeasurement")
2174  ExitCode.set("name","exit_code")
2175  ExitCode.set("type","numeric/integer" )
2176  value = ET.SubElement(ExitCode, "Value")
2177  value.text = convert_xml_illegal_chars(result["ExecTest.exit_code"])
2178 
2179  TestStartTime= ET.SubElement(Results,"NamedMeasurement")
2180  TestStartTime.set("name","Start_Time")
2181  TestStartTime.set("type","String" )
2182  value = ET.SubElement(TestStartTime, "Value")
2183  if haveStartDate :
2184  value.text = escape_xml_illegal_chars(time.strftime("%b %d %H:%M %Z %Y", time.localtime(self._startTime)))
2185  else :
2186  value.text = ""
2187 
2188  TestEndTime= ET.SubElement(Results,"NamedMeasurement")
2189  TestEndTime.set("name","End_Time")
2190  TestEndTime.set("type","String" )
2191  value = ET.SubElement(TestEndTime, "Value")
2192  if haveStartDate :
2193  value.text = escape_xml_illegal_chars(time.strftime("%b %d %H:%M %Z %Y", time.localtime(self._endTime)))
2194  else :
2195  value.text = ""
2196 
2197  if summary["cause"]:
2198  FailureCause= ET.SubElement(Results,"NamedMeasurement")
2199  FailureCause.set("name", "Cause")
2200  FailureCause.set("type", "String" )
2201  value = ET.SubElement(FailureCause, "Value")
2202  value.text = escape_xml_illegal_chars(summary["cause"])
2203 
2204  #Fill the result
2205  fields = {}
2206  for field in summary["fields"] :
2207  fields[field] = ET.SubElement(Results, "NamedMeasurement")
2208  fields[field].set("type","String")
2209  fields[field].set("name",field)
2210  value = ET.SubElement(fields[field], "Value")
2211  # to escape the <pre></pre>
2212  if "<pre>" in result[field][0:6] :
2213  value.text = convert_xml_illegal_chars(result[field][5:-6])
2214  else :
2215  value.text = convert_xml_illegal_chars(result[field])
2216 
2217 
2218  if result.has_key("ExecTest.stdout" ) : #"ExecTest.stdout" in result :
2219  Measurement = ET.SubElement(Results, "Measurement")
2220  value = ET.SubElement(Measurement, "Value")
2221  if "<pre>" in result["ExecTest.stdout"][0:6] :
2222  value.text = convert_xml_illegal_chars(result["ExecTest.stdout"][5:-6])
2223  else :
2224  value.text = convert_xml_illegal_chars(result["ExecTest.stdout"])
2225 
2226 
2227  # write the file
2228  self._tree.write(self._xmlFile, "utf-8") #,True) in python 2.7 to add the xml header
2229 
2230 
def escape_xml_illegal_chars(val, replacement='?')
Definition: GaudiTest.py:340
def WriteResult(self, result)
Definition: GaudiTest.py:2087
struct GAUDI_API map
Parametrisation class for map-like implementation.
def convert_xml_illegal_chars(val)
Definition: GaudiTest.py:337

Member Data Documentation

GaudiTest.XMLResultStream._ElapsedMinutes
private

Definition at line 2061 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndDateTime
private

End time elements.

Definition at line 2054 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndTestTime
private

Definition at line 2057 of file GaudiTest.py.

GaudiTest.XMLResultStream._endTime
private

Definition at line 1988 of file GaudiTest.py.

GaudiTest.XMLResultStream._site
private

Definition at line 2011 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartDateTime
private

Definition at line 2046 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartTestTime
private

Definition at line 2048 of file GaudiTest.py.

GaudiTest.XMLResultStream._startTime
private

Definition at line 1987 of file GaudiTest.py.

GaudiTest.XMLResultStream._Testing
private

Definition at line 2043 of file GaudiTest.py.

GaudiTest.XMLResultStream._TestList
private

Definition at line 2051 of file GaudiTest.py.

GaudiTest.XMLResultStream._tree
private

Definition at line 1996 of file GaudiTest.py.

GaudiTest.XMLResultStream._xmlFile
private

Definition at line 1984 of file GaudiTest.py.

list GaudiTest.XMLResultStream.arguments
static
Initial value:
1 = [
2  qm.fields.TextField(
3  name = "dir",
4  title = "Destination Directory",
5  description = ,
6  verbatim = "true",
7  default_value = ""),
8  qm.fields.TextField(
9  name = "prefix",
10  title = "Output File Prefix",
11  description = ,
12  verbatim = "true",
13  default_value = ""),
14  ]

Definition at line 1958 of file GaudiTest.py.


The documentation for this class was generated from the following file: