Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 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 1723 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 1743 of file GaudiTest.py.

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

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

Definition at line 1855 of file GaudiTest.py.

1856  def Summarize(self):
1857  # Not implemented.
1858  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 1784 of file GaudiTest.py.

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

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

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1753 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1751 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

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


The documentation for this class was generated from the following file:
Generated at Wed Dec 4 2013 14:33:23 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004