|
Gaudi Framework, version v21r9 |
| Home | Generated: 3 May 2010 |


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 | |
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 1661 of file GaudiTest.py.
| 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 1681 of file GaudiTest.py.
01681 : 01682 """Prepare the destination directory. 01683 01684 Creates the destination directory and store in it some preliminary 01685 annotations and the static files found in the template directory 01686 'html_report'. 01687 """ 01688 ResultStream.__init__(self, arguments, **args) 01689 self._summary = [] 01690 self._summaryFile = os.path.join(self.dir, "summary.json") 01691 self._annotationsFile = os.path.join(self.dir, "annotations.json") 01692 # Prepare the destination directory using the template 01693 templateDir = os.path.join(os.path.dirname(__file__), "html_report") 01694 if not os.path.isdir(self.dir): 01695 os.makedirs(self.dir) 01696 # Copy the files in the template directory excluding the directories 01697 for f in os.listdir(templateDir): 01698 src = os.path.join(templateDir, f) 01699 dst = os.path.join(self.dir, f) 01700 if not os.path.isdir(src) and not os.path.exists(dst): 01701 shutil.copy(src, dst) 01702 # Add some non-QMTest attributes 01703 if "CMTCONFIG" in os.environ: 01704 self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"]) 01705 import socket 01706 self.WriteAnnotation("hostname", socket.gethostname()) 01707 def _updateSummary(self):
| def GaudiTest::HTMLResultStream::_updateSummary | ( | self | ) | [private] |
Helper function to extend the global summary file in the destination directory.
Definition at line 1708 of file GaudiTest.py.
01708 : 01709 """Helper function to extend the global summary file in the destination 01710 directory. 01711 """ 01712 if os.path.exists(self._summaryFile): 01713 oldSummary = json.load(open(self._summaryFile)) 01714 else: 01715 oldSummary = [] 01716 ids = set([ i["id"] for i in self._summary ]) 01717 newSummary = [ i for i in oldSummary if i["id"] not in ids ] 01718 newSummary.extend(self._summary) 01719 json.dump(newSummary, open(self._summaryFile, "w"), 01720 sort_keys = True) 01721 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 1722 of file GaudiTest.py.
01722 : 01723 """Writes the annotation to the annotation file. 01724 If the key is already present with a different value, the value becomes 01725 a list and the new value is appended to it, except for start_time and 01726 end_time. 01727 """ 01728 # Initialize the annotation dict from the file (if present) 01729 if os.path.exists(self._annotationsFile): 01730 annotations = json.load(open(self._annotationsFile)) 01731 else: 01732 annotations = {} 01733 # hack because we do not have proper JSON support 01734 key, value = map(str, [key, value]) 01735 if key == "qmtest.run.start_time": 01736 # Special handling of the start time: 01737 # if we are updating a result, we have to keep the original start 01738 # time, but remove the original end time to mark the report to be 01739 # in progress. 01740 if key not in annotations: 01741 annotations[key] = value 01742 if "qmtest.run.end_time" in annotations: 01743 del annotations["qmtest.run.end_time"] 01744 else: 01745 # All other annotations are added to a list 01746 if key in annotations: 01747 old = annotations[key] 01748 if type(old) is list: 01749 if value not in old: 01750 annotations[key].append(value) 01751 elif value != old: 01752 annotations[key] = [old, value] 01753 else: 01754 annotations[key] = value 01755 # Write the new annotations file 01756 json.dump(annotations, open(self._annotationsFile, "w"), 01757 sort_keys = True) 01758 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 1759 of file GaudiTest.py.
01759 : 01760 """Prepare the test result directory in the destination directory storing 01761 into it the result fields. 01762 A summary of the test result is stored both in a file in the test directory 01763 and in the global summary file. 01764 """ 01765 summary = {} 01766 summary["id"] = result.GetId() 01767 summary["outcome"] = result.GetOutcome() 01768 summary["cause"] = result.GetCause() 01769 summary["fields"] = result.keys() 01770 summary["fields"].sort() 01771 01772 # Since we miss proper JSON support, I hack a bit 01773 for f in ["id", "outcome", "cause"]: 01774 summary[f] = str(summary[f]) 01775 summary["fields"] = map(str, summary["fields"]) 01776 01777 self._summary.append(summary) 01778 01779 # format: 01780 # testname/summary.json 01781 # testname/field1 01782 # testname/field2 01783 testOutDir = os.path.join(self.dir, summary["id"]) 01784 if not os.path.isdir(testOutDir): 01785 os.makedirs(testOutDir) 01786 json.dump(summary, open(os.path.join(testOutDir, "summary.json"), "w"), 01787 sort_keys = True) 01788 for f in summary["fields"]: 01789 open(os.path.join(testOutDir, f), "w").write(result[f]) 01790 01791 self._updateSummary() 01792 def Summarize(self):
| def GaudiTest::HTMLResultStream::Summarize | ( | self | ) |
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 1670 of file GaudiTest.py.
GaudiTest::HTMLResultStream::_summary [private] |
Definition at line 1689 of file GaudiTest.py.
Definition at line 1690 of file GaudiTest.py.
Definition at line 1691 of file GaudiTest.py.