GaudiTest.HTMLResultStream Class Reference
Inheritance diagram for GaudiTest.HTMLResultStream:
Collaboration diagram for GaudiTest.HTMLResultStream:

Public Member Functions

def __init__ (self, arguments=None, args)
 
def WriteAnnotation (self, key, value)
 
def WriteResult (self, result)
 
def Summarize (self)
 
def __init__ (self, arguments=None, args)
 
def WriteAnnotation (self, key, value)
 
def WriteResult (self, result)
 
def Summarize (self)
 

Static Public Attributes

list arguments
 

Private Member Functions

def _updateSummary (self)
 
def _updateSummary (self)
 

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 1805 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 1825 of file GaudiTest.py.

1825  def __init__(self, arguments = None, **args):
1826  """Prepare the destination directory.
1827 
1828  Creates the destination directory and store in it some preliminary
1829  annotations and the static files found in the template directory
1830  'html_report'.
1831  """
1832  ResultStream.__init__(self, arguments, **args)
1833  self._summary = []
1834  self._summaryFile = os.path.join(self.dir, "summary.json")
1835  self._annotationsFile = os.path.join(self.dir, "annotations.json")
1836  # Prepare the destination directory using the template
1837  templateDir = os.path.join(os.path.dirname(__file__), "html_report")
1838  if not os.path.isdir(self.dir):
1839  os.makedirs(self.dir)
1840  # Copy the files in the template directory excluding the directories
1841  for f in os.listdir(templateDir):
1842  src = os.path.join(templateDir, f)
1843  dst = os.path.join(self.dir, f)
1844  if not os.path.isdir(src) and not os.path.exists(dst):
1845  shutil.copy(src, dst)
1846  # Add some non-QMTest attributes
1847  if "CMTCONFIG" in os.environ:
1848  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
1849  import socket
1850  self.WriteAnnotation("hostname", socket.gethostname())
1851 
def __init__(self, arguments=None, args)
Definition: GaudiTest.py:1825
def WriteAnnotation(self, key, value)
Definition: GaudiTest.py:1866
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 1825 of file GaudiTest.py.

1825  def __init__(self, arguments = None, **args):
1826  """Prepare the destination directory.
1827 
1828  Creates the destination directory and store in it some preliminary
1829  annotations and the static files found in the template directory
1830  'html_report'.
1831  """
1832  ResultStream.__init__(self, arguments, **args)
1833  self._summary = []
1834  self._summaryFile = os.path.join(self.dir, "summary.json")
1835  self._annotationsFile = os.path.join(self.dir, "annotations.json")
1836  # Prepare the destination directory using the template
1837  templateDir = os.path.join(os.path.dirname(__file__), "html_report")
1838  if not os.path.isdir(self.dir):
1839  os.makedirs(self.dir)
1840  # Copy the files in the template directory excluding the directories
1841  for f in os.listdir(templateDir):
1842  src = os.path.join(templateDir, f)
1843  dst = os.path.join(self.dir, f)
1844  if not os.path.isdir(src) and not os.path.exists(dst):
1845  shutil.copy(src, dst)
1846  # Add some non-QMTest attributes
1847  if "CMTCONFIG" in os.environ:
1848  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
1849  import socket
1850  self.WriteAnnotation("hostname", socket.gethostname())
1851 
def __init__(self, arguments=None, args)
Definition: GaudiTest.py:1825
def WriteAnnotation(self, key, value)
Definition: GaudiTest.py:1866

Member Function Documentation

def GaudiTest.HTMLResultStream._updateSummary (   self)
private
Helper function to extend the global summary file in the destination
directory.

Definition at line 1852 of file GaudiTest.py.

1852  def _updateSummary(self):
1853  """Helper function to extend the global summary file in the destination
1854  directory.
1855  """
1856  if os.path.exists(self._summaryFile):
1857  oldSummary = json.load(open(self._summaryFile))
1858  else:
1859  oldSummary = []
1860  ids = set([ i["id"] for i in self._summary ])
1861  newSummary = [ i for i in oldSummary if i["id"] not in ids ]
1862  newSummary.extend(self._summary)
1863  json.dump(newSummary, open(self._summaryFile, "w"),
1864  sort_keys = True)
1865 
def GaudiTest.HTMLResultStream._updateSummary (   self)
private
Helper function to extend the global summary file in the destination
directory.

Definition at line 1852 of file GaudiTest.py.

1852  def _updateSummary(self):
1853  """Helper function to extend the global summary file in the destination
1854  directory.
1855  """
1856  if os.path.exists(self._summaryFile):
1857  oldSummary = json.load(open(self._summaryFile))
1858  else:
1859  oldSummary = []
1860  ids = set([ i["id"] for i in self._summary ])
1861  newSummary = [ i for i in oldSummary if i["id"] not in ids ]
1862  newSummary.extend(self._summary)
1863  json.dump(newSummary, open(self._summaryFile, "w"),
1864  sort_keys = True)
1865 
def GaudiTest.HTMLResultStream.Summarize (   self)

Definition at line 1937 of file GaudiTest.py.

1937  def Summarize(self):
1938  # Not implemented.
1939  pass
1940 
1941 
1942 
1943 
def GaudiTest.HTMLResultStream.Summarize (   self)

Definition at line 1937 of file GaudiTest.py.

1937  def Summarize(self):
1938  # Not implemented.
1939  pass
1940 
1941 
1942 
1943 
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 1866 of file GaudiTest.py.

1866  def WriteAnnotation(self, key, value):
1867  """Writes the annotation to the annotation file.
1868  If the key is already present with a different value, the value becomes
1869  a list and the new value is appended to it, except for start_time and
1870  end_time.
1871  """
1872  # Initialize the annotation dict from the file (if present)
1873  if os.path.exists(self._annotationsFile):
1874  annotations = json.load(open(self._annotationsFile))
1875  else:
1876  annotations = {}
1877  # hack because we do not have proper JSON support
1878  key, value = map(str, [key, value])
1879  if key == "qmtest.run.start_time":
1880  # Special handling of the start time:
1881  # if we are updating a result, we have to keep the original start
1882  # time, but remove the original end time to mark the report to be
1883  # in progress.
1884  if key not in annotations:
1885  annotations[key] = value
1886  if "qmtest.run.end_time" in annotations:
1887  del annotations["qmtest.run.end_time"]
1888  else:
1889  # All other annotations are added to a list
1890  if key in annotations:
1891  old = annotations[key]
1892  if type(old) is list:
1893  if value not in old:
1894  annotations[key].append(value)
1895  elif value != old:
1896  annotations[key] = [old, value]
1897  else:
1898  annotations[key] = value
1899  # Write the new annotations file
1900  json.dump(annotations, open(self._annotationsFile, "w"),
1901  sort_keys = True)
1902 
struct GAUDI_API map
Parametrisation class for map-like implementation.
def WriteAnnotation(self, key, value)
Definition: GaudiTest.py:1866
string type
Definition: gaudirun.py:151
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 1866 of file GaudiTest.py.

1866  def WriteAnnotation(self, key, value):
1867  """Writes the annotation to the annotation file.
1868  If the key is already present with a different value, the value becomes
1869  a list and the new value is appended to it, except for start_time and
1870  end_time.
1871  """
1872  # Initialize the annotation dict from the file (if present)
1873  if os.path.exists(self._annotationsFile):
1874  annotations = json.load(open(self._annotationsFile))
1875  else:
1876  annotations = {}
1877  # hack because we do not have proper JSON support
1878  key, value = map(str, [key, value])
1879  if key == "qmtest.run.start_time":
1880  # Special handling of the start time:
1881  # if we are updating a result, we have to keep the original start
1882  # time, but remove the original end time to mark the report to be
1883  # in progress.
1884  if key not in annotations:
1885  annotations[key] = value
1886  if "qmtest.run.end_time" in annotations:
1887  del annotations["qmtest.run.end_time"]
1888  else:
1889  # All other annotations are added to a list
1890  if key in annotations:
1891  old = annotations[key]
1892  if type(old) is list:
1893  if value not in old:
1894  annotations[key].append(value)
1895  elif value != old:
1896  annotations[key] = [old, value]
1897  else:
1898  annotations[key] = value
1899  # Write the new annotations file
1900  json.dump(annotations, open(self._annotationsFile, "w"),
1901  sort_keys = True)
1902 
struct GAUDI_API map
Parametrisation class for map-like implementation.
def WriteAnnotation(self, key, value)
Definition: GaudiTest.py:1866
string type
Definition: gaudirun.py:151
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 1903 of file GaudiTest.py.

1903  def WriteResult(self, result):
1904  """Prepare the test result directory in the destination directory storing
1905  into it the result fields.
1906  A summary of the test result is stored both in a file in the test directory
1907  and in the global summary file.
1908  """
1909  summary = {}
1910  summary["id"] = result.GetId()
1911  summary["outcome"] = result.GetOutcome()
1912  summary["cause"] = result.GetCause()
1913  summary["fields"] = result.keys()
1914  summary["fields"].sort()
1915 
1916  # Since we miss proper JSON support, I hack a bit
1917  for f in ["id", "outcome", "cause"]:
1918  summary[f] = str(summary[f])
1919  summary["fields"] = map(str, summary["fields"])
1920 
1921  self._summary.append(summary)
1922 
1923  # format:
1924  # testname/summary.json
1925  # testname/field1
1926  # testname/field2
1927  testOutDir = os.path.join(self.dir, summary["id"])
1928  if not os.path.isdir(testOutDir):
1929  os.makedirs(testOutDir)
1930  json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
1931  sort_keys = True)
1932  for f in summary["fields"]:
1933  open(os.path.join(testOutDir, f), "w").write(result[f])
1934 
1935  self._updateSummary()
1936 
struct GAUDI_API map
Parametrisation class for map-like implementation.
def WriteResult(self, result)
Definition: GaudiTest.py:1903
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 1903 of file GaudiTest.py.

1903  def WriteResult(self, result):
1904  """Prepare the test result directory in the destination directory storing
1905  into it the result fields.
1906  A summary of the test result is stored both in a file in the test directory
1907  and in the global summary file.
1908  """
1909  summary = {}
1910  summary["id"] = result.GetId()
1911  summary["outcome"] = result.GetOutcome()
1912  summary["cause"] = result.GetCause()
1913  summary["fields"] = result.keys()
1914  summary["fields"].sort()
1915 
1916  # Since we miss proper JSON support, I hack a bit
1917  for f in ["id", "outcome", "cause"]:
1918  summary[f] = str(summary[f])
1919  summary["fields"] = map(str, summary["fields"])
1920 
1921  self._summary.append(summary)
1922 
1923  # format:
1924  # testname/summary.json
1925  # testname/field1
1926  # testname/field2
1927  testOutDir = os.path.join(self.dir, summary["id"])
1928  if not os.path.isdir(testOutDir):
1929  os.makedirs(testOutDir)
1930  json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
1931  sort_keys = True)
1932  for f in summary["fields"]:
1933  open(os.path.join(testOutDir, f), "w").write(result[f])
1934 
1935  self._updateSummary()
1936 
struct GAUDI_API map
Parametrisation class for map-like implementation.
def WriteResult(self, result)
Definition: GaudiTest.py:1903

Member Data Documentation

GaudiTest.HTMLResultStream._annotationsFile
private

Definition at line 1835 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summary
private

Definition at line 1833 of file GaudiTest.py.

GaudiTest.HTMLResultStream._summaryFile
private

Definition at line 1834 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 = ,
6  verbatim = "true",
7  default_value = ""),
8  ]

Definition at line 1814 of file GaudiTest.py.


The documentation for this class was generated from the following file: