| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
GaudiTest.HTMLResultStream Class Reference
Inheritance diagram for GaudiTest.HTMLResultStream:
[legend]
Collaboration diagram for GaudiTest.HTMLResultStream:
[legend]

## Public Member Functions
def | __init__ (self, arguments=None, **args)
def | WriteAnnotation (self, key, value)
def | WriteResult (self, result)
def | Summarize (self)

## Static Public Attributes
list | arguments

## Private Member Functions
def | _updateSummary (self)

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

## Constructor & Destructor Documentation

## ◆ __init__()

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

1978 def __init__(self, arguments=None, **args):
1979 """Prepare the destination directory.
1980
1981 Creates the destination directory and store in it some preliminary
1982 annotations and the static files found in the template directory
1983 'html_report'.
1984 """
1985 ResultStream.__init__(self, arguments, **args)
1986 self._summary = []
1987 self._summaryFile = os.path.join(self.dir, "summary.json")
1988 self._annotationsFile = os.path.join(self.dir, "annotations.json")
1989 # Prepare the destination directory using the template
1990 templateDir = os.path.join(os.path.dirname(__file__), "html_report")
1991 if not os.path.isdir(self.dir):
1992 os.makedirs(self.dir)
1993 # Copy the files in the template directory excluding the directories
1994 for f in os.listdir(templateDir):
1995 src = os.path.join(templateDir, f)
1996 dst = os.path.join(self.dir, f)
1997 if not os.path.isdir(src) and not os.path.exists(dst):
1998 shutil.copy(src, dst)
1999 # Add some non-QMTest attributes
2000 if "CMTCONFIG" in os.environ:
2001 self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
2002 import socket
2003 self.WriteAnnotation("hostname", socket.gethostname())
2004

## Member Function Documentation

## ◆ _updateSummary()

def GaudiTest.HTMLResultStream._updateSummary | ( |  | self | ) |
| private

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

Definition at line 2005 of file GaudiTest.py.

2005 def _updateSummary(self):
2006 """Helper function to extend the global summary file in the destination
2007 directory.
2008 """
2009 if os.path.exists(self._summaryFile):
2010 oldSummary = json.load(open(self._summaryFile))
2011 else:
2012 oldSummary = []
2013 ids = set([i["id"] for i in self._summary])
2014 newSummary = [i for i in oldSummary if i["id"] not in ids]
2015 newSummary.extend(self._summary)
2016 json.dump(newSummary, open(self._summaryFile, "w"), sort_keys=True)
2017

## ◆ Summarize()

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

Definition at line 2091 of file GaudiTest.py.

2091 def Summarize(self):
2092 # Not implemented.
2093 pass
2094
2095

## ◆ WriteAnnotation()

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

2018 def WriteAnnotation(self, key, value):
2019 """Writes the annotation to the annotation file.
2020 If the key is already present with a different value, the value becomes
2021 a list and the new value is appended to it, except for start_time and
2022 end_time.
2023 """
2024 # Initialize the annotation dict from the file (if present)
2025 if os.path.exists(self._annotationsFile):
2026 annotations = json.load(open(self._annotationsFile))
2027 else:
2028 annotations = {}
2029 # hack because we do not have proper JSON support
2030 key, value = map(str, [key, value])
2031 if key == "qmtest.run.start_time":
2032 # Special handling of the start time:
2033 # if we are updating a result, we have to keep the original start
2034 # time, but remove the original end time to mark the report to be
2035 # in progress.
2036 if key not in annotations:
2037 annotations[key] = value
2038 if "qmtest.run.end_time" in annotations:
2039 del annotations["qmtest.run.end_time"]
2040 else:
2041 # All other annotations are added to a list
2042 if key in annotations:
2043 old = annotations[key]
2044 if type(old) is list:
2045 if value not in old:
2046 annotations[key].append(value)
2047 elif value != old:
2048 annotations[key] = [old, value]
2049 else:
2050 annotations[key] = value
2051 # Write the new annotations file
2052 json.dump(
2053 annotations, open(self._annotationsFile, "w"), sort_keys=True)
2054
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:25
gaudirun.type
type
Definition: gaudirun.py:142

## ◆ WriteResult()

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

2055 def WriteResult(self, result):
2056 """Prepare the test result directory in the destination directory storing
2057 into it the result fields.
2058 A summary of the test result is stored both in a file in the test directory
2059 and in the global summary file.
2060 """
2061 summary = {}
2062 summary["id"] = result.GetId()
2063 summary["outcome"] = result.GetOutcome()
2064 summary["cause"] = result.GetCause()
2065 summary["fields"] = result.keys()
2066 summary["fields"].sort()
2067
2068 # Since we miss proper JSON support, I hack a bit
2069 for f in ["id", "outcome", "cause"]:
2070 summary[f] = str(summary[f])
2071 summary["fields"] = map(str, summary["fields"])
2072
2073 self._summary.append(summary)
2074
2075 # format:
2076 # testname/summary.json
2077 # testname/field1
2078 # testname/field2
2079 testOutDir = os.path.join(self.dir, summary["id"])
2080 if not os.path.isdir(testOutDir):
2081 os.makedirs(testOutDir)
2082 json.dump(
2083 summary,
2084 open(os.path.join(testOutDir, "summary.json"), "w"),
2085 sort_keys=True)
2086 for f in summary["fields"]:
2087 open(os.path.join(testOutDir, f), "w").write(result[f])
2088
2089 self._updateSummary()
2090
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:25

## Member Data Documentation

## ◆ _annotationsFile

GaudiTest.HTMLResultStream._annotationsFile
| private

Definition at line 1988 of file GaudiTest.py.

## ◆ _summary

GaudiTest.HTMLResultStream._summary
| private

Definition at line 1986 of file GaudiTest.py.

## ◆ _summaryFile

GaudiTest.HTMLResultStream._summaryFile
| private

Definition at line 1987 of file GaudiTest.py.

## ◆ arguments

list GaudiTest.HTMLResultStream.arguments
| static

Initial value:
= [
qm.fields.TextField(
name="dir",
title="Destination Directory",
description=,
verbatim="true",
default_value=""),
]

Definition at line 1967 of file GaudiTest.py.

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

- GaudiPolicy/qmtest_classes/GaudiTest.py