Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 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 1791 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 1811 of file GaudiTest.py.

1812  def __init__(self, arguments = None, **args):
1813  """Prepare the destination directory.
1814 
1815  Creates the destination directory and store in it some preliminary
1816  annotations and the static files found in the template directory
1817  'html_report'.
1818  """
1819  ResultStream.__init__(self, arguments, **args)
1820  self._summary = []
1821  self._summaryFile = os.path.join(self.dir, "summary.json")
1822  self._annotationsFile = os.path.join(self.dir, "annotations.json")
1823  # Prepare the destination directory using the template
1824  templateDir = os.path.join(os.path.dirname(__file__), "html_report")
1825  if not os.path.isdir(self.dir):
1826  os.makedirs(self.dir)
1827  # Copy the files in the template directory excluding the directories
1828  for f in os.listdir(templateDir):
1829  src = os.path.join(templateDir, f)
1830  dst = os.path.join(self.dir, f)
1831  if not os.path.isdir(src) and not os.path.exists(dst):
1832  shutil.copy(src, dst)
1833  # Add some non-QMTest attributes
1834  if "CMTCONFIG" in os.environ:
1835  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
1836  import socket
1837  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 1838 of file GaudiTest.py.

1839  def _updateSummary(self):
1840  """Helper function to extend the global summary file in the destination
1841  directory.
1842  """
1843  if os.path.exists(self._summaryFile):
1844  oldSummary = json.load(open(self._summaryFile))
1845  else:
1846  oldSummary = []
1847  ids = set([ i["id"] for i in self._summary ])
1848  newSummary = [ i for i in oldSummary if i["id"] not in ids ]
1849  newSummary.extend(self._summary)
1850  json.dump(newSummary, open(self._summaryFile, "w"),
1851  sort_keys = True)
def GaudiTest.HTMLResultStream.Summarize (   self)

Definition at line 1923 of file GaudiTest.py.

1924  def Summarize(self):
1925  # Not implemented.
1926  pass
1927 
1928 
1929 
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 1852 of file GaudiTest.py.

1853  def WriteAnnotation(self, key, value):
1854  """Writes the annotation to the annotation file.
1855  If the key is already present with a different value, the value becomes
1856  a list and the new value is appended to it, except for start_time and
1857  end_time.
1858  """
1859  # Initialize the annotation dict from the file (if present)
1860  if os.path.exists(self._annotationsFile):
1861  annotations = json.load(open(self._annotationsFile))
1862  else:
1863  annotations = {}
1864  # hack because we do not have proper JSON support
1865  key, value = map(str, [key, value])
1866  if key == "qmtest.run.start_time":
1867  # Special handling of the start time:
1868  # if we are updating a result, we have to keep the original start
1869  # time, but remove the original end time to mark the report to be
1870  # in progress.
1871  if key not in annotations:
1872  annotations[key] = value
1873  if "qmtest.run.end_time" in annotations:
1874  del annotations["qmtest.run.end_time"]
1875  else:
1876  # All other annotations are added to a list
1877  if key in annotations:
1878  old = annotations[key]
1879  if type(old) is list:
1880  if value not in old:
1881  annotations[key].append(value)
1882  elif value != old:
1883  annotations[key] = [old, value]
1884  else:
1885  annotations[key] = value
1886  # Write the new annotations file
1887  json.dump(annotations, open(self._annotationsFile, "w"),
1888  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 1889 of file GaudiTest.py.

1890  def WriteResult(self, result):
1891  """Prepare the test result directory in the destination directory storing
1892  into it the result fields.
1893  A summary of the test result is stored both in a file in the test directory
1894  and in the global summary file.
1895  """
1896  summary = {}
1897  summary["id"] = result.GetId()
1898  summary["outcome"] = result.GetOutcome()
1899  summary["cause"] = result.GetCause()
1900  summary["fields"] = result.keys()
1901  summary["fields"].sort()
1902 
1903  # Since we miss proper JSON support, I hack a bit
1904  for f in ["id", "outcome", "cause"]:
1905  summary[f] = str(summary[f])
1906  summary["fields"] = map(str, summary["fields"])
1907 
1908  self._summary.append(summary)
1909 
1910  # format:
1911  # testname/summary.json
1912  # testname/field1
1913  # testname/field2
1914  testOutDir = os.path.join(self.dir, summary["id"])
1915  if not os.path.isdir(testOutDir):
1916  os.makedirs(testOutDir)
1917  json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
1918  sort_keys = True)
1919  for f in summary["fields"]:
1920  open(os.path.join(testOutDir, f), "w").write(result[f])
1921 
1922  self._updateSummary()

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1821 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1819 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

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


The documentation for this class was generated from the following file:
Generated at Wed Jun 4 2014 14:49:06 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004