Gaudi Framework, version v23r2p1

Home   Generated: Fri Jun 29 2012
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 1687 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 1707 of file GaudiTest.py.

01708                                                 :
01709         """Prepare the destination directory.
01710 
01711         Creates the destination directory and store in it some preliminary
01712         annotations and the static files found in the template directory
01713         'html_report'.
01714         """
01715         ResultStream.__init__(self, arguments, **args)
01716         self._summary = []
01717         self._summaryFile = os.path.join(self.dir, "summary.json")
01718         self._annotationsFile = os.path.join(self.dir, "annotations.json")
01719         # Prepare the destination directory using the template
01720         templateDir = os.path.join(os.path.dirname(__file__), "html_report")
01721         if not os.path.isdir(self.dir):
01722             os.makedirs(self.dir)
01723         # Copy the files in the template directory excluding the directories
01724         for f in os.listdir(templateDir):
01725             src = os.path.join(templateDir, f)
01726             dst = os.path.join(self.dir, f)
01727             if not os.path.isdir(src) and not os.path.exists(dst):
01728                 shutil.copy(src, dst)
01729         # Add some non-QMTest attributes
01730         if "CMTCONFIG" in os.environ:
01731             self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
01732         import socket
01733         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 1734 of file GaudiTest.py.

01735                             :
01736         """Helper function to extend the global summary file in the destination
01737         directory.
01738         """
01739         if os.path.exists(self._summaryFile):
01740             oldSummary = json.load(open(self._summaryFile))
01741         else:
01742             oldSummary = []
01743         ids = set([ i["id"] for i in self._summary ])
01744         newSummary = [ i for i in oldSummary if i["id"] not in ids ]
01745         newSummary.extend(self._summary)
01746         json.dump(newSummary, open(self._summaryFile, "w"),
01747                   sort_keys = True)

def GaudiTest::HTMLResultStream::Summarize (   self )

Definition at line 1819 of file GaudiTest.py.

01820                        :
01821         # Not implemented.
01822         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 1748 of file GaudiTest.py.

01749                                          :
01750         """Writes the annotation to the annotation file.
01751         If the key is already present with a different value, the value becomes
01752         a list and the new value is appended to it, except for start_time and
01753         end_time.
01754         """
01755         # Initialize the annotation dict from the file (if present)
01756         if os.path.exists(self._annotationsFile):
01757             annotations = json.load(open(self._annotationsFile))
01758         else:
01759             annotations = {}
01760         # hack because we do not have proper JSON support
01761         key, value = map(str, [key, value])
01762         if key == "qmtest.run.start_time":
01763             # Special handling of the start time:
01764             # if we are updating a result, we have to keep the original start
01765             # time, but remove the original end time to mark the report to be
01766             # in progress.
01767             if key not in annotations:
01768                 annotations[key] = value
01769             if "qmtest.run.end_time" in annotations:
01770                 del annotations["qmtest.run.end_time"]
01771         else:
01772             # All other annotations are added to a list
01773             if key in annotations:
01774                 old = annotations[key]
01775                 if type(old) is list:
01776                     if value not in old:
01777                         annotations[key].append(value)
01778                 elif value != old:
01779                     annotations[key] = [old, value]
01780             else:
01781                 annotations[key] = value
01782         # Write the new annotations file
01783         json.dump(annotations, open(self._annotationsFile, "w"),
01784                   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 1785 of file GaudiTest.py.

01786                                  :
01787         """Prepare the test result directory in the destination directory storing
01788         into it the result fields.
01789         A summary of the test result is stored both in a file in the test directory
01790         and in the global summary file.
01791         """
01792         summary = {}
01793         summary["id"] = result.GetId()
01794         summary["outcome"] = result.GetOutcome()
01795         summary["cause"] = result.GetCause()
01796         summary["fields"] = result.keys()
01797         summary["fields"].sort()
01798 
01799         # Since we miss proper JSON support, I hack a bit
01800         for f in ["id", "outcome", "cause"]:
01801             summary[f] = str(summary[f])
01802         summary["fields"] = map(str, summary["fields"])
01803 
01804         self._summary.append(summary)
01805 
01806         # format:
01807         # testname/summary.json
01808         # testname/field1
01809         # testname/field2
01810         testOutDir = os.path.join(self.dir, summary["id"])
01811         if not os.path.isdir(testOutDir):
01812             os.makedirs(testOutDir)
01813         json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
01814                   sort_keys = True)
01815         for f in summary["fields"]:
01816             open(os.path.join(testOutDir, f), "w").write(result[f])
01817 
01818         self._updateSummary()


Member Data Documentation

Definition at line 1712 of file GaudiTest.py.

Definition at line 1712 of file GaudiTest.py.

Definition at line 1712 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 1696 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 Fri Jun 29 2012 15:44:14 for Gaudi Framework, version v23r2p1 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004