Gaudi Framework, version v23r8

Home   Generated: Fri May 31 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 1719 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 1739 of file GaudiTest.py.

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

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

Definition at line 1851 of file GaudiTest.py.

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

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

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

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1749 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1747 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

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


The documentation for this class was generated from the following file:
Generated at Fri May 31 2013 15:09:28 for Gaudi Framework, version v23r8 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004