| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# 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 1669 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 1689 of file GaudiTest.py.

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

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

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

Definition at line 1716 of file GaudiTest.py.

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

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

Definition at line 1801 of file GaudiTest.py.

    01802                        :
    01803         # Not implemented.
    01804         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 1730 of file GaudiTest.py.

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

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

## Member Data Documentation

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

Definition at line 1699 of file GaudiTest.py.

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

Definition at line 1697 of file GaudiTest.py.

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

Definition at line 1698 of file GaudiTest.py.

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

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines