Gaudi Framework, version v21r11

Home   Generated: 30 Sep 2010

GaudiTest::HTMLResultStream Class Reference

Inheritance diagram for GaudiTest::HTMLResultStream:
[legend]
Collaboration diagram for GaudiTest::HTMLResultStream:
[legend]

List of all members.

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


Member Function 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 1689 of file GaudiTest.py.

01689                                                 :
01690         """Prepare the destination directory.
01691 
01692         Creates the destination directory and store in it some preliminary
01693         annotations and the static files found in the template directory
01694         'html_report'.
01695         """
01696         ResultStream.__init__(self, arguments, **args)
01697         self._summary = []
01698         self._summaryFile = os.path.join(self.dir, "summary.json")
01699         self._annotationsFile = os.path.join(self.dir, "annotations.json")
01700         # Prepare the destination directory using the template
01701         templateDir = os.path.join(os.path.dirname(__file__), "html_report")
01702         if not os.path.isdir(self.dir):
01703             os.makedirs(self.dir)
01704         # Copy the files in the template directory excluding the directories
01705         for f in os.listdir(templateDir):
01706             src = os.path.join(templateDir, f)
01707             dst = os.path.join(self.dir, f)
01708             if not os.path.isdir(src) and not os.path.exists(dst):
01709                 shutil.copy(src, dst)
01710         # Add some non-QMTest attributes
01711         if "CMTCONFIG" in os.environ:
01712             self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
01713         import socket
01714         self.WriteAnnotation("hostname", socket.gethostname())
01715 
    def _updateSummary(self):

def GaudiTest::HTMLResultStream::_updateSummary (   self  )  [private]

Helper function to extend the global summary file in the destination
directory.

Definition at line 1716 of file GaudiTest.py.

01716                             :
01717         """Helper function to extend the global summary file in the destination
01718         directory.
01719         """
01720         if os.path.exists(self._summaryFile):
01721             oldSummary = json.load(open(self._summaryFile))
01722         else:
01723             oldSummary = []
01724         ids = set([ i["id"] for i in self._summary ])
01725         newSummary = [ i for i in oldSummary if i["id"] not in ids ]
01726         newSummary.extend(self._summary)
01727         json.dump(newSummary, open(self._summaryFile, "w"),
01728                   sort_keys = True)
01729 
    def WriteAnnotation(self, key, value):

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

01730                                          :
01731         """Writes the annotation to the annotation file.
01732         If the key is already present with a different value, the value becomes
01733         a list and the new value is appended to it, except for start_time and
01734         end_time.
01735         """
01736         # Initialize the annotation dict from the file (if present)
01737         if os.path.exists(self._annotationsFile):
01738             annotations = json.load(open(self._annotationsFile))
01739         else:
01740             annotations = {}
01741         # hack because we do not have proper JSON support
01742         key, value = map(str, [key, value])
01743         if key == "qmtest.run.start_time":
01744             # Special handling of the start time:
01745             # if we are updating a result, we have to keep the original start
01746             # time, but remove the original end time to mark the report to be
01747             # in progress.
01748             if key not in annotations:
01749                 annotations[key] = value
01750             if "qmtest.run.end_time" in annotations:
01751                 del annotations["qmtest.run.end_time"]
01752         else:
01753             # All other annotations are added to a list
01754             if key in annotations:
01755                 old = annotations[key]
01756                 if type(old) is list:
01757                     if value not in old:
01758                         annotations[key].append(value)
01759                 elif value != old:
01760                     annotations[key] = [old, value]
01761             else:
01762                 annotations[key] = value
01763         # Write the new annotations file
01764         json.dump(annotations, open(self._annotationsFile, "w"),
01765                   sort_keys = True)
01766 
    def WriteResult(self, result):

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

01767                                  :
01768         """Prepare the test result directory in the destination directory storing
01769         into it the result fields.
01770         A summary of the test result is stored both in a file in the test directory
01771         and in the global summary file.
01772         """
01773         summary = {}
01774         summary["id"] = result.GetId()
01775         summary["outcome"] = result.GetOutcome()
01776         summary["cause"] = result.GetCause()
01777         summary["fields"] = result.keys()
01778         summary["fields"].sort()
01779 
01780         # Since we miss proper JSON support, I hack a bit
01781         for f in ["id", "outcome", "cause"]:
01782             summary[f] = str(summary[f])
01783         summary["fields"] = map(str, summary["fields"])
01784 
01785         self._summary.append(summary)
01786 
01787         # format:
01788         # testname/summary.json
01789         # testname/field1
01790         # testname/field2
01791         testOutDir = os.path.join(self.dir, summary["id"])
01792         if not os.path.isdir(testOutDir):
01793             os.makedirs(testOutDir)
01794         json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
01795                   sort_keys = True)
01796         for f in summary["fields"]:
01797             open(os.path.join(testOutDir, f), "w").write(result[f])
01798 
01799         self._updateSummary()
01800 
    def Summarize(self):

def GaudiTest::HTMLResultStream::Summarize (   self  ) 

Definition at line 1801 of file GaudiTest.py.

01801                        :
01802         # Not implemented.
01803         pass
        pass


Member Data Documentation

Initial value:

[
        qm.fields.TextField(
            name = "dir",
            title = "Destination Directory",
            description = """The name of the directory.All results will be written to the directory indicated.""",
            verbatim = "true",
            default_value = ""),
    ]

Definition at line 1678 of file GaudiTest.py.

Definition at line 1697 of file GaudiTest.py.

Definition at line 1698 of file GaudiTest.py.

Definition at line 1699 of file GaudiTest.py.


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

Generated at Thu Sep 30 09:59:02 2010 for Gaudi Framework, version v21r11 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004