Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 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 1707 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 1727 of file GaudiTest.py.

01728                                                 :
01729         """Prepare the destination directory.
01730 
01731         Creates the destination directory and store in it some preliminary
01732         annotations and the static files found in the template directory
01733         'html_report'.
01734         """
01735         ResultStream.__init__(self, arguments, **args)
01736         self._summary = []
01737         self._summaryFile = os.path.join(self.dir, "summary.json")
01738         self._annotationsFile = os.path.join(self.dir, "annotations.json")
01739         # Prepare the destination directory using the template
01740         templateDir = os.path.join(os.path.dirname(__file__), "html_report")
01741         if not os.path.isdir(self.dir):
01742             os.makedirs(self.dir)
01743         # Copy the files in the template directory excluding the directories
01744         for f in os.listdir(templateDir):
01745             src = os.path.join(templateDir, f)
01746             dst = os.path.join(self.dir, f)
01747             if not os.path.isdir(src) and not os.path.exists(dst):
01748                 shutil.copy(src, dst)
01749         # Add some non-QMTest attributes
01750         if "CMTCONFIG" in os.environ:
01751             self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
01752         import socket
01753         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 1754 of file GaudiTest.py.

01755                             :
01756         """Helper function to extend the global summary file in the destination
01757         directory.
01758         """
01759         if os.path.exists(self._summaryFile):
01760             oldSummary = json.load(open(self._summaryFile))
01761         else:
01762             oldSummary = []
01763         ids = set([ i["id"] for i in self._summary ])
01764         newSummary = [ i for i in oldSummary if i["id"] not in ids ]
01765         newSummary.extend(self._summary)
01766         json.dump(newSummary, open(self._summaryFile, "w"),
01767                   sort_keys = True)

def GaudiTest::HTMLResultStream::Summarize (   self )

Definition at line 1839 of file GaudiTest.py.

01840                        :
01841         # Not implemented.
01842         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 1768 of file GaudiTest.py.

01769                                          :
01770         """Writes the annotation to the annotation file.
01771         If the key is already present with a different value, the value becomes
01772         a list and the new value is appended to it, except for start_time and
01773         end_time.
01774         """
01775         # Initialize the annotation dict from the file (if present)
01776         if os.path.exists(self._annotationsFile):
01777             annotations = json.load(open(self._annotationsFile))
01778         else:
01779             annotations = {}
01780         # hack because we do not have proper JSON support
01781         key, value = map(str, [key, value])
01782         if key == "qmtest.run.start_time":
01783             # Special handling of the start time:
01784             # if we are updating a result, we have to keep the original start
01785             # time, but remove the original end time to mark the report to be
01786             # in progress.
01787             if key not in annotations:
01788                 annotations[key] = value
01789             if "qmtest.run.end_time" in annotations:
01790                 del annotations["qmtest.run.end_time"]
01791         else:
01792             # All other annotations are added to a list
01793             if key in annotations:
01794                 old = annotations[key]
01795                 if type(old) is list:
01796                     if value not in old:
01797                         annotations[key].append(value)
01798                 elif value != old:
01799                     annotations[key] = [old, value]
01800             else:
01801                 annotations[key] = value
01802         # Write the new annotations file
01803         json.dump(annotations, open(self._annotationsFile, "w"),
01804                   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 1805 of file GaudiTest.py.

01806                                  :
01807         """Prepare the test result directory in the destination directory storing
01808         into it the result fields.
01809         A summary of the test result is stored both in a file in the test directory
01810         and in the global summary file.
01811         """
01812         summary = {}
01813         summary["id"] = result.GetId()
01814         summary["outcome"] = result.GetOutcome()
01815         summary["cause"] = result.GetCause()
01816         summary["fields"] = result.keys()
01817         summary["fields"].sort()
01818 
01819         # Since we miss proper JSON support, I hack a bit
01820         for f in ["id", "outcome", "cause"]:
01821             summary[f] = str(summary[f])
01822         summary["fields"] = map(str, summary["fields"])
01823 
01824         self._summary.append(summary)
01825 
01826         # format:
01827         # testname/summary.json
01828         # testname/field1
01829         # testname/field2
01830         testOutDir = os.path.join(self.dir, summary["id"])
01831         if not os.path.isdir(testOutDir):
01832             os.makedirs(testOutDir)
01833         json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"),
01834                   sort_keys = True)
01835         for f in summary["fields"]:
01836             open(os.path.join(testOutDir, f), "w").write(result[f])
01837 
01838         self._updateSummary()


Member Data Documentation

Definition at line 1732 of file GaudiTest.py.

Definition at line 1732 of file GaudiTest.py.

Definition at line 1732 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 1716 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 Mon Sep 17 2012 13:49:58 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004