| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 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 1659 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 1679 of file GaudiTest.py.

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

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

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

Definition at line 1706 of file GaudiTest.py.

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

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

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

def GaudiTest::HTMLResultStream::Summarize | ( |  | self | ) |

Definition at line 1791 of file GaudiTest.py.

    01791                        :
    01792         # Not implemented.
    01793         pass
            pass

## Member Data Documentation

list GaudiTest::HTMLResultStream::arguments`[static]`

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

GaudiTest::HTMLResultStream::_summary`[private]`

Definition at line 1687 of file GaudiTest.py.

GaudiTest::HTMLResultStream::_summaryFile`[private]`

Definition at line 1688 of file GaudiTest.py.

GaudiTest::HTMLResultStream::_annotationsFile`[private]`

Definition at line 1689 of file GaudiTest.py.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r8/GaudiPolicy/qmtest_classes/GaudiTest.py