Gaudi Framework, version v25r1

Home   Generated: Mon Mar 24 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
GaudiTest.HTMLResultStream Class Reference
Inheritance diagram for GaudiTest.HTMLResultStream:
Inheritance graph
[legend]
Collaboration diagram for GaudiTest.HTMLResultStream:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def WriteAnnotation
 
def WriteResult
 
def Summarize
 

Static Public Attributes

list arguments
 

Private Member Functions

def _updateSummary
 

Private Attributes

 _summary
 
 _summaryFile
 
 _annotationsFile
 

Detailed Description

An 'HTMLResultStream' writes its output to a set of HTML files.

The argument 'dir' is used to select the destination directory for the HTML
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 extended to
include the new data.

Definition at line 1777 of file GaudiTest.py.

Constructor & Destructor Documentation

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

Creates the destination directory and store in it some preliminary
annotations and the static files found in the template directory
'html_report'.

Definition at line 1797 of file GaudiTest.py.

1798  def __init__(self, arguments = None, **args):
1799  """Prepare the destination directory.
1800 
1801  Creates the destination directory and store in it some preliminary
1802  annotations and the static files found in the template directory
1803  'html_report'.
1804  """
1805  ResultStream.__init__(self, arguments, **args)
1806  self._summary = []
1807  self._summaryFile = os.path.join(self.dir, "summary.json")
1808  self._annotationsFile = os.path.join(self.dir, "annotations.json")
1809  # Prepare the destination directory using the template
1810  templateDir = os.path.join(os.path.dirname(__file__), "html_report")
1811  if not os.path.isdir(self.dir):
1812  os.makedirs(self.dir)
1813  # Copy the files in the template directory excluding the directories
1814  for f in os.listdir(templateDir):
1815  src = os.path.join(templateDir, f)
1816  dst = os.path.join(self.dir, f)
1817  if not os.path.isdir(src) and not os.path.exists(dst):
1818  shutil.copy(src, dst)
1819  # Add some non-QMTest attributes
1820  if "CMTCONFIG" in os.environ:
1821  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
1822  import socket
1823  self.WriteAnnotation("hostname", socket.gethostname())

Member Function Documentation

def GaudiTest.HTMLResultStream._updateSummary (   self)
private
Helper function to extend the global summary file in the destination
directory.

Definition at line 1824 of file GaudiTest.py.

1825  def _updateSummary(self):
1826  """Helper function to extend the global summary file in the destination
1827  directory.
1828  """
1829  if os.path.exists(self._summaryFile):
1830  oldSummary = json.load(open(self._summaryFile))
1831  else:
1832  oldSummary = []
1833  ids = set([ i["id"] for i in self._summary ])
1834  newSummary = [ i for i in oldSummary if i["id"] not in ids ]
1835  newSummary.extend(self._summary)
1836  json.dump(newSummary, open(self._summaryFile, "w"),
1837  sort_keys = True)
def GaudiTest.HTMLResultStream.Summarize (   self)

Definition at line 1909 of file GaudiTest.py.

1910  def Summarize(self):
1911  # Not implemented.
1912  pass
1913 
1914 
1915 
def GaudiTest.HTMLResultStream.WriteAnnotation (   self,
  key,
  value 
)
Writes the annotation to the annotation file.
If the key is already present with a different value, the value becomes
a list and the new value is appended to it, except for start_time and
end_time.

Definition at line 1838 of file GaudiTest.py.

1839  def WriteAnnotation(self, key, value):
1840  """Writes the annotation to the annotation file.
1841  If the key is already present with a different value, the value becomes
1842  a list and the new value is appended to it, except for start_time and
1843  end_time.
1844  """
1845  # Initialize the annotation dict from the file (if present)
1846  if os.path.exists(self._annotationsFile):
1847  annotations = json.load(open(self._annotationsFile))
1848  else:
1849  annotations = {}
1850  # hack because we do not have proper JSON support
1851  key, value = map(str, [key, value])
1852  if key == "qmtest.run.start_time":
1853  # Special handling of the start time:
1854  # if we are updating a result, we have to keep the original start
1855  # time, but remove the original end time to mark the report to be
1856  # in progress.
1857  if key not in annotations:
1858  annotations[key] = value
1859  if "qmtest.run.end_time" in annotations:
1860  del annotations["qmtest.run.end_time"]
1861  else:
1862  # All other annotations are added to a list
1863  if key in annotations:
1864  old = annotations[key]
1865  if type(old) is list:
1866  if value not in old:
1867  annotations[key].append(value)
1868  elif value != old:
1869  annotations[key] = [old, value]
1870  else:
1871  annotations[key] = value
1872  # Write the new annotations file
1873  json.dump(annotations, open(self._annotationsFile, "w"),
1874  sort_keys = True)
def GaudiTest.HTMLResultStream.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 1875 of file GaudiTest.py.

1876  def WriteResult(self, result):
1877  """Prepare the test result directory in the destination directory storing
1878  into it the result fields.
1879  A summary of the test result is stored both in a file in the test directory
1880  and in the global summary file.
1881  """
1882  summary = {}
1883  summary["id"] = result.GetId()
1884  summary["outcome"] = result.GetOutcome()
1885  summary["cause"] = result.GetCause()
1886  summary["fields"] = result.keys()
1887  summary["fields"].sort()
1888 
1889  # Since we miss proper JSON support, I hack a bit
1890  for f in ["id", "outcome", "cause"]:
1891  summary[f] = str(summary[f])
1892  summary["fields"] = map(str, summary["fields"])
1893 
1894  self._summary.append(summary)
1895 
1896  # format:
1897  # testname/summary.json
1898  # testname/field1
1899  # testname/field2
1900  testOutDir = os.path.join(self.dir, summary["id"])
1901  if not os.path.isdir(testOutDir):
1902  os.makedirs(testOutDir)
1903  json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
1904  sort_keys = True)
1905  for f in summary["fields"]:
1906  open(os.path.join(testOutDir, f), "w").write(result[f])
1907 
1908  self._updateSummary()

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1807 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1805 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

Definition at line 1806 of file GaudiTest.py.

list GaudiTest.HTMLResultStream.arguments
static
Initial value:
1 [
2  qm.fields.TextField(
3  name = "dir",
4  title = "Destination Directory",
5  description = """The name of the directory.All results will be written to the directory indicated.""",
6  verbatim = "true",
7  default_value = ""),
8  ]

Definition at line 1786 of file GaudiTest.py.


The documentation for this class was generated from the following file:
Generated at Mon Mar 24 2014 18:27:53 for Gaudi Framework, version v25r1 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004