The Gaudi Framework  v29r0 (ff2e7097)
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
 
 _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 2039 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 2066 of file GaudiTest.py.

2066  def __init__(self, arguments=None, **args):
2067  """Prepare the destination directory.
2068 
2069  Creates the destination directory and store in it some preliminary
2070  annotations .
2071  """
2072  ResultStream.__init__(self, arguments, **args)
2073 
2074  self._xmlFile = os.path.join(self.dir, self.prefix + 'Test.xml')
2075 
2076  # add some global variable
2077  self._startTime = None
2078  self._endTime = None
2079  # Format the XML file if it not exists
2080  if not os.path.isfile(self._xmlFile):
2081  # check that the container directory exists and create it if not
2082  if not os.path.exists(os.path.dirname(self._xmlFile)):
2083  os.makedirs(os.path.dirname(self._xmlFile))
2084 
2085  newdataset = ET.Element("newdataset")
2086  self._tree = ET.ElementTree(newdataset)
2087  self._tree.write(self._xmlFile)
2088  else:
2089  # Read the xml file
2090  self._tree = ET.parse(self._xmlFile)
2091  newdataset = self._tree.getroot()
2092 
2093  # Find the corresponding site, if do not exist, create it
2094 
2095  #site = newdataset.find('Site[@BuildStamp="'+result["qmtest.start_time"]+'"][@OSPlatform="'+os.getenv("CMTOPT")+'"]')
2096  # I don't know why this syntax doesn't work. Maybe it is because of the python version. Indeed,
2097  # This works well in the python terminal. So I have to make a for:
2098  for site in newdataset.getiterator():
2099  # and site.get("BuildStamp") == result["qmtest.start_time"] and:
2100  if site.get("OSPlatform") == os.uname()[4]:
2101  # Here we can add some variable to define the difference beetween 2 site
2102  self._site = site
2103  break
2104  else:
2105  site = None
2106 
2107  if site is None:
2108  import socket
2109  import multiprocessing
2110  attrib = {
2111  "BuildName": os.getenv("CMTCONFIG"),
2112  "Name": os.uname()[1],
2113  "Generator": "QMTest " + qm.version,
2114  "OSName": os.uname()[0],
2115  "Hostname": socket.gethostname(),
2116  "OSRelease": os.uname()[2],
2117  "OSVersion": os.uname()[3],
2118  "OSPlatform": os.uname()[4],
2119  "Is64Bits": "unknown",
2120  "VendorString": "unknown",
2121  "VendorID": "unknown",
2122  "FamilyID": "unknown",
2123  "ModelID": "unknown",
2124  "ProcessorCacheSize": "unknown",
2125  "NumberOfLogicalCPU": str(multiprocessing.cpu_count()),
2126  "NumberOfPhysicalCPU": "0",
2127  "TotalVirtualMemory": "0",
2128  "TotalPhysicalMemory": "0",
2129  "LogicalProcessorsPerPhysical": "0",
2130  "ProcessorClockFrequency": "0",
2131  }
2132  self._site = ET.SubElement(newdataset, "Site", attrib)
2133  self._Testing = ET.SubElement(self._site, "Testing")
2134 
2135  # Start time elements
2136  self._StartDateTime = ET.SubElement(self._Testing, "StartDateTime")
2137 
2138  self._StartTestTime = ET.SubElement(self._Testing, "StartTestTime")
2139 
2140  self._TestList = ET.SubElement(self._Testing, "TestList")
2141 
2142  # End time elements
2143  self._EndDateTime = ET.SubElement(self._Testing, "EndDateTime")
2144 
2145  self._EndTestTime = ET.SubElement(self._Testing, "EndTestTime")
2146 
2147  self._ElapsedMinutes = ET.SubElement(
2148  self._Testing, "ElapsedMinutes")
2149 
2150  else: # We get the elements
2151  self._Testing = self._site.find("Testing")
2152  self._StartDateTime = self._Testing.find("StartDateTime")
2153  self._StartTestTime = self._Testing.find("StartTestTime")
2154  self._TestList = self._Testing.find("TestList")
2155  self._EndDateTime = self._Testing.find("EndDateTime")
2156  self._EndTestTime = self._Testing.find("EndTestTime")
2157  self._ElapsedMinutes = self._Testing.find("ElapsedMinutes")
2158 
2159  """
2160  # Add some non-QMTest attributes
2161  if "CMTCONFIG" in os.environ:
2162  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
2163  import socket
2164  self.WriteAnnotation("hostname", socket.gethostname())
2165  """
2166 
def __init__(self, arguments=None, args)
Definition: GaudiTest.py:2066

Member Function Documentation

def GaudiTest.XMLResultStream.Summarize (   self)

Definition at line 2320 of file GaudiTest.py.

2320  def Summarize(self):
2321 
2322  # Set the final end date time
2323  self._EndTestTime.text = str(self._endTime)
2324  self._EndDateTime.text = time.strftime(
2325  "%b %d %H:%M %Z", time.localtime(self._endTime))
2326 
2327  # Compute the total duration
2328  if self._endTime and self._startTime:
2329  delta = self._endTime - self._startTime
2330  else:
2331  delta = 0
2332  self._ElapsedMinutes.text = str(delta / 60)
2333 
2334  # Write into the file
2335  # ,True) in python 2.7 to add the xml header
2336  self._tree.write(self._xmlFile, "utf-8")
def GaudiTest.XMLResultStream.WriteAnnotation (   self,
  key,
  value 
)

Definition at line 2167 of file GaudiTest.py.

2167  def WriteAnnotation(self, key, value):
2168  if key == "qmtest.run.start_time":
2169  if self._site.get("qmtest.run.start_time") is not None:
2170  return None
2171  self._site.set(str(key), str(value))
2172 
def WriteAnnotation(self, key, value)
Definition: GaudiTest.py:2167
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 2173 of file GaudiTest.py.

2173  def WriteResult(self, result):
2174  """Prepare the test result directory in the destination directory storing
2175  into it the result fields.
2176  A summary of the test result is stored both in a file in the test directory
2177  and in the global summary file.
2178  """
2179  summary = {}
2180  summary["id"] = result.GetId()
2181  summary["outcome"] = result.GetOutcome()
2182  summary["cause"] = result.GetCause()
2183  summary["fields"] = result.keys()
2184  summary["fields"].sort()
2185 
2186  # Since we miss proper JSON support, I hack a bit
2187  for f in ["id", "outcome", "cause"]:
2188  summary[f] = str(summary[f])
2189  summary["fields"] = map(str, summary["fields"])
2190 
2191  # format
2192  # package_Test.xml
2193 
2194  if "qmtest.start_time" in summary["fields"]:
2195  haveStartDate = True
2196  else:
2197  haveStartDate = False
2198  if "qmtest.end_time" in summary["fields"]:
2199  haveEndDate = True
2200  else:
2201  haveEndDate = False
2202 
2203  # writing the start date time
2204  if haveStartDate:
2205  self._startTime = calendar.timegm(time.strptime(
2206  result["qmtest.start_time"], "%Y-%m-%dT%H:%M:%SZ"))
2207  if self._StartTestTime.text is None:
2208  self._StartDateTime.text = time.strftime(
2209  "%b %d %H:%M %Z", time.localtime(self._startTime))
2210  self._StartTestTime.text = str(self._startTime)
2211  self._site.set("BuildStamp", result["qmtest.start_time"])
2212 
2213  # Save the end date time in memory
2214  if haveEndDate:
2215  self._endTime = calendar.timegm(time.strptime(
2216  result["qmtest.end_time"], "%Y-%m-%dT%H:%M:%SZ"))
2217 
2218  # add the current test to the test list
2219  tl = ET.Element("Test")
2220  tl.text = summary["id"]
2221  self._TestList.insert(0, tl)
2222 
2223  # Fill the current test
2224  Test = ET.Element("Test")
2225  if summary["outcome"] == "PASS":
2226  Test.set("Status", "passed")
2227  elif summary["outcome"] == "FAIL":
2228  Test.set("Status", "failed")
2229  elif summary["outcome"] == "SKIPPED" or summary["outcome"] == "UNTESTED":
2230  Test.set("Status", "skipped")
2231  elif summary["outcome"] == "ERROR":
2232  Test.set("Status", "failed")
2233  Name = ET.SubElement(Test, "Name",)
2234  Name.text = summary["id"]
2235  Results = ET.SubElement(Test, "Results")
2236 
2237  # add the test after the other test
2238  self._Testing.insert(3, Test)
2239 
2240  if haveStartDate and haveEndDate:
2241  # Compute the test duration
2242  delta = self._endTime - self._startTime
2243  testduration = str(delta)
2244  Testduration = ET.SubElement(Results, "NamedMeasurement")
2245  Testduration.set("name", "Execution Time")
2246  Testduration.set("type", "numeric/float")
2247  value = ET.SubElement(Testduration, "Value")
2248  value.text = testduration
2249 
2250  # remove the fields that we store in a different way
2251  for n in ("qmtest.end_time", "qmtest.start_time", "qmtest.cause", "ExecTest.stdout"):
2252  if n in summary["fields"]:
2253  summary["fields"].remove(n)
2254 
2255  # Here we can add some NamedMeasurment which we know the type
2256  #
2257  if "ExecTest.exit_code" in summary["fields"]:
2258  summary["fields"].remove("ExecTest.exit_code")
2259  ExitCode = ET.SubElement(Results, "NamedMeasurement")
2260  ExitCode.set("name", "exit_code")
2261  ExitCode.set("type", "numeric/integer")
2262  value = ET.SubElement(ExitCode, "Value")
2263  value.text = convert_xml_illegal_chars(
2264  result["ExecTest.exit_code"])
2265 
2266  TestStartTime = ET.SubElement(Results, "NamedMeasurement")
2267  TestStartTime.set("name", "Start_Time")
2268  TestStartTime.set("type", "String")
2269  value = ET.SubElement(TestStartTime, "Value")
2270  if haveStartDate:
2271  value.text = escape_xml_illegal_chars(time.strftime(
2272  "%b %d %H:%M %Z %Y", time.localtime(self._startTime)))
2273  else:
2274  value.text = ""
2275 
2276  TestEndTime = ET.SubElement(Results, "NamedMeasurement")
2277  TestEndTime.set("name", "End_Time")
2278  TestEndTime.set("type", "String")
2279  value = ET.SubElement(TestEndTime, "Value")
2280  if haveStartDate:
2281  value.text = escape_xml_illegal_chars(time.strftime(
2282  "%b %d %H:%M %Z %Y", time.localtime(self._endTime)))
2283  else:
2284  value.text = ""
2285 
2286  if summary["cause"]:
2287  FailureCause = ET.SubElement(Results, "NamedMeasurement")
2288  FailureCause.set("name", "Cause")
2289  FailureCause.set("type", "String")
2290  value = ET.SubElement(FailureCause, "Value")
2291  value.text = escape_xml_illegal_chars(summary["cause"])
2292 
2293  # Fill the result
2294  fields = {}
2295  for field in summary["fields"]:
2296  fields[field] = ET.SubElement(Results, "NamedMeasurement")
2297  fields[field].set("type", "String")
2298  fields[field].set("name", field)
2299  value = ET.SubElement(fields[field], "Value")
2300  # to escape the <pre></pre>
2301  if "<pre>" in result[field][0:6]:
2302  value.text = convert_xml_illegal_chars(result[field][5:-6])
2303  else:
2304  value.text = convert_xml_illegal_chars(result[field])
2305 
2306  if result.has_key("ExecTest.stdout"): # "ExecTest.stdout" in result :
2307  Measurement = ET.SubElement(Results, "Measurement")
2308  value = ET.SubElement(Measurement, "Value")
2309  if "<pre>" in result["ExecTest.stdout"][0:6]:
2310  value.text = convert_xml_illegal_chars(
2311  result["ExecTest.stdout"][5:-6])
2312  else:
2313  value.text = convert_xml_illegal_chars(
2314  result["ExecTest.stdout"])
2315 
2316  # write the file
2317  # ,True) in python 2.7 to add the xml header
2318  self._tree.write(self._xmlFile, "utf-8")
2319 
def escape_xml_illegal_chars(val, replacement='?')
Definition: GaudiTest.py:361
def WriteResult(self, result)
Definition: GaudiTest.py:2173
struct GAUDI_API map
Parametrisation class for map-like implementation.
def convert_xml_illegal_chars(val)
Definition: GaudiTest.py:357

Member Data Documentation

GaudiTest.XMLResultStream._ElapsedMinutes
private

Definition at line 2147 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndDateTime
private

Definition at line 2143 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndTestTime
private

Definition at line 2145 of file GaudiTest.py.

GaudiTest.XMLResultStream._endTime
private

Definition at line 2078 of file GaudiTest.py.

GaudiTest.XMLResultStream._site
private

Definition at line 2102 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartDateTime
private

Definition at line 2136 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartTestTime
private

Definition at line 2138 of file GaudiTest.py.

GaudiTest.XMLResultStream._startTime
private

Definition at line 2077 of file GaudiTest.py.

GaudiTest.XMLResultStream._Testing
private

Definition at line 2133 of file GaudiTest.py.

GaudiTest.XMLResultStream._TestList
private

Definition at line 2140 of file GaudiTest.py.

GaudiTest.XMLResultStream._tree
private

Definition at line 2086 of file GaudiTest.py.

GaudiTest.XMLResultStream._xmlFile
private

Definition at line 2074 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 2048 of file GaudiTest.py.


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