Gaudi Framework, version v23r10

Home   Generated: Mon Sep 30 2013
 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 1721 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 1741 of file GaudiTest.py.

1742  def __init__(self, arguments = None, **args):
1743  """Prepare the destination directory.
1744 
1745  Creates the destination directory and store in it some preliminary
1746  annotations and the static files found in the template directory
1747  'html_report'.
1748  """
1749  ResultStream.__init__(self, arguments, **args)
1750  self._summary = []
1751  self._summaryFile = os.path.join(self.dir, "summary.json")
1752  self._annotationsFile = os.path.join(self.dir, "annotations.json")
1753  # Prepare the destination directory using the template
1754  templateDir = os.path.join(os.path.dirname(__file__), "html_report")
1755  if not os.path.isdir(self.dir):
1756  os.makedirs(self.dir)
1757  # Copy the files in the template directory excluding the directories
1758  for f in os.listdir(templateDir):
1759  src = os.path.join(templateDir, f)
1760  dst = os.path.join(self.dir, f)
1761  if not os.path.isdir(src) and not os.path.exists(dst):
1762  shutil.copy(src, dst)
1763  # Add some non-QMTest attributes
1764  if "CMTCONFIG" in os.environ:
1765  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
1766  import socket
1767  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 1768 of file GaudiTest.py.

1769  def _updateSummary(self):
1770  """Helper function to extend the global summary file in the destination
1771  directory.
1772  """
1773  if os.path.exists(self._summaryFile):
1774  oldSummary = json.load(open(self._summaryFile))
1775  else:
1776  oldSummary = []
1777  ids = set([ i["id"] for i in self._summary ])
1778  newSummary = [ i for i in oldSummary if i["id"] not in ids ]
1779  newSummary.extend(self._summary)
1780  json.dump(newSummary, open(self._summaryFile, "w"),
1781  sort_keys = True)
def GaudiTest.HTMLResultStream.Summarize (   self)

Definition at line 1853 of file GaudiTest.py.

1854  def Summarize(self):
1855  # Not implemented.
1856  pass
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 1782 of file GaudiTest.py.

1783  def WriteAnnotation(self, key, value):
1784  """Writes the annotation to the annotation file.
1785  If the key is already present with a different value, the value becomes
1786  a list and the new value is appended to it, except for start_time and
1787  end_time.
1788  """
1789  # Initialize the annotation dict from the file (if present)
1790  if os.path.exists(self._annotationsFile):
1791  annotations = json.load(open(self._annotationsFile))
1792  else:
1793  annotations = {}
1794  # hack because we do not have proper JSON support
1795  key, value = map(str, [key, value])
1796  if key == "qmtest.run.start_time":
1797  # Special handling of the start time:
1798  # if we are updating a result, we have to keep the original start
1799  # time, but remove the original end time to mark the report to be
1800  # in progress.
1801  if key not in annotations:
1802  annotations[key] = value
1803  if "qmtest.run.end_time" in annotations:
1804  del annotations["qmtest.run.end_time"]
1805  else:
1806  # All other annotations are added to a list
1807  if key in annotations:
1808  old = annotations[key]
1809  if type(old) is list:
1810  if value not in old:
1811  annotations[key].append(value)
1812  elif value != old:
1813  annotations[key] = [old, value]
1814  else:
1815  annotations[key] = value
1816  # Write the new annotations file
1817  json.dump(annotations, open(self._annotationsFile, "w"),
1818  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 1819 of file GaudiTest.py.

1820  def WriteResult(self, result):
1821  """Prepare the test result directory in the destination directory storing
1822  into it the result fields.
1823  A summary of the test result is stored both in a file in the test directory
1824  and in the global summary file.
1825  """
1826  summary = {}
1827  summary["id"] = result.GetId()
1828  summary["outcome"] = result.GetOutcome()
1829  summary["cause"] = result.GetCause()
1830  summary["fields"] = result.keys()
1831  summary["fields"].sort()
1832 
1833  # Since we miss proper JSON support, I hack a bit
1834  for f in ["id", "outcome", "cause"]:
1835  summary[f] = str(summary[f])
1836  summary["fields"] = map(str, summary["fields"])
1837 
1838  self._summary.append(summary)
1839 
1840  # format:
1841  # testname/summary.json
1842  # testname/field1
1843  # testname/field2
1844  testOutDir = os.path.join(self.dir, summary["id"])
1845  if not os.path.isdir(testOutDir):
1846  os.makedirs(testOutDir)
1847  json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
1848  sort_keys = True)
1849  for f in summary["fields"]:
1850  open(os.path.join(testOutDir, f), "w").write(result[f])
1851 
1852  self._updateSummary()

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1751 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1749 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

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


The documentation for this class was generated from the following file:
Generated at Mon Sep 30 2013 14:52:08 for Gaudi Framework, version v23r10 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004