Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 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 1718 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 1738 of file GaudiTest.py.

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

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

Definition at line 1850 of file GaudiTest.py.

1851  def Summarize(self):
1852  # Not implemented.
1853  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 1779 of file GaudiTest.py.

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

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

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1748 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1746 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

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


The documentation for this class was generated from the following file:
Generated at Thu Jul 18 2013 12:18:15 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004