Gaudi Framework, version v21r10p1

Home   Generated: 29 Jul 2010

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

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

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

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

Definition at line 1707 of file GaudiTest.py.

01707                             :
01708         """Helper function to extend the global summary file in the destination
01709         directory.
01710         """
01711         if os.path.exists(self._summaryFile):
01712             oldSummary = json.load(open(self._summaryFile))
01713         else:
01714             oldSummary = []
01715         ids = set([ i["id"] for i in self._summary ])
01716         newSummary = [ i for i in oldSummary if i["id"] not in ids ]
01717         newSummary.extend(self._summary)
01718         json.dump(newSummary, open(self._summaryFile, "w"),
01719                   sort_keys = True)
01720     
    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 1721 of file GaudiTest.py.

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

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

def GaudiTest::HTMLResultStream::Summarize (   self  ) 

Definition at line 1792 of file GaudiTest.py.

01792                        :
01793         # Not implemented.
01794         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 1669 of file GaudiTest.py.

Definition at line 1688 of file GaudiTest.py.

Definition at line 1689 of file GaudiTest.py.

Definition at line 1690 of file GaudiTest.py.


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

Generated at Thu Jul 29 10:19:54 2010 for Gaudi Framework, version v21r10p1 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004