Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes

GaudiTest::HTMLResultStream Class Reference

Inheritance diagram for GaudiTest::HTMLResultStream:
Inheritance graph
[legend]
Collaboration diagram for GaudiTest::HTMLResultStream:
Collaboration graph
[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 1666 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 1686 of file GaudiTest.py.

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

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

def GaudiTest::HTMLResultStream::Summarize (   self )

Definition at line 1798 of file GaudiTest.py.

01799                        :
01800         # Not implemented.
01801         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 1727 of file GaudiTest.py.

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

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


Member Data Documentation

Definition at line 1691 of file GaudiTest.py.

Definition at line 1691 of file GaudiTest.py.

Definition at line 1691 of file GaudiTest.py.

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


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:55:38 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004