Gaudi Framework, version v23r7

Home   Generated: Wed Mar 20 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 1707 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 1727 of file GaudiTest.py.

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

1755  def _updateSummary(self):
1756  """Helper function to extend the global summary file in the destination
1757  directory.
1758  """
1759  if os.path.exists(self._summaryFile):
1760  oldSummary = json.load(open(self._summaryFile))
1761  else:
1762  oldSummary = []
1763  ids = set([ i["id"] for i in self._summary ])
1764  newSummary = [ i for i in oldSummary if i["id"] not in ids ]
1765  newSummary.extend(self._summary)
1766  json.dump(newSummary, open(self._summaryFile, "w"),
1767  sort_keys = True)
def GaudiTest.HTMLResultStream.Summarize (   self)

Definition at line 1839 of file GaudiTest.py.

1840  def Summarize(self):
1841  # Not implemented.
1842  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 1768 of file GaudiTest.py.

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

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

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1737 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1735 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

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


The documentation for this class was generated from the following file:
Generated at Wed Mar 20 2013 17:59:51 for Gaudi Framework, version v23r7 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004