]> rtime.felk.cvut.cz Git - omk.git/commitdiff
Added statistics to test results.
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 15 Mar 2007 08:34:00 +0000 (08:34 +0000)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 15 Mar 2007 08:34:00 +0000 (08:34 +0000)
darcs-hash:20070315083416-f2ef6-8898f17e4b9691b38275548c9b1e8198d17514aa.gz

tests/tester.py

index 2b622967dec380cf47752b2e380b54251ff8c9c4..0f0d111a906709d6f886d2a9846e6c5473312f40 100755 (executable)
@@ -23,6 +23,10 @@ class Results(dict):
         self.time = time.gmtime()
         self.datetime = time.strftime("%Y-%m-%d %H:%M:%S +0000", self.time)
         self.filename = "results-"+time.strftime("%Y%m%d-%H%M%S", self.time)+".html"
+        self.stats = None
+
+    def genStats(self):
+        self.stats = Stats(self)
         
     def toHtml(self):
         s="""
@@ -36,8 +40,9 @@ class Results(dict):
   <title>OMK test report %(datetime)s</title>
 </head>
 <body>
-<h2>Summary</h2>TODO
+<h2>Summary</h2>
         """ % self.__dict__
+        s+=self.stats.toHtml()
         s+="""
 <h2>Chart</h2>
 <table cellpadding='2' border='1'>
@@ -140,6 +145,72 @@ class ResultEntry:
 <pre>%(stderr)s</pre>""" % vals
         return s
 
+class RulesStat:
+    def __init__(self, rules):
+        self.rules = rules
+        self.tests = 0
+        self.success = 0
+        self.errors = 0
+        self.canttest = 0
+        self.unknown = 0
+    def update(self, testCaseResult):
+        try:
+            resultEntry = testCaseResult[self.rules]
+            self.tests+=1
+            if resultEntry.exitcode == 0: self.success+=1
+            elif resultEntry.exitcode == 1: self.errors+=1
+            elif resultEntry.exitcode == 2: self.canttest+=1
+            else: self.unknown+=1
+        except KeyError:
+            pass
+    def toHtml(self):
+        if self.errors == 0 and self.canttest == 0: self.color=''
+        elif self.errors != 0:   self.color=' bgcolor="red"'
+        elif self.canttest != 0: self.color=' bgcolor="yellow"'
+        else: self.color = ' bgcolor="gray"'
+        s="""
+  <tr%(color)s>
+    <td>%(rules)s</td>
+    <td>%(tests)d</td>
+    <td>%(success)d</td>
+    <td>%(errors)d</td>
+    <td>%(canttest)d</td>
+    <td>%(unknown)d</td>
+  </tr>
+        """ % self.__dict__
+        return s
+
+class Stats(dict):
+    def __init__(self, results):
+        rules = rulesdef.rules.keys()
+        for rule in rules:
+            rulesStat = RulesStat(rule)
+            self[rule]=rulesStat
+            for resultEntry in results.values():
+                rulesStat.update(resultEntry)
+        
+    def toHtml(self):
+        s="""
+<table cellpadding='2' border='1'>
+<col />
+<col span='5' align='right' />
+<thead><tr>
+  <td>Rules</td>
+  <td>Total</td>
+  <td>Success</td>
+  <td>Errors</td>
+  <td>Can't test</td>
+  <td>Unknown</td>
+</tr></thead>
+<tbody>
+        """
+        rules = sorted(self.keys())
+        for r in rules:
+            s+=self[r].toHtml()
+        s+="""
+</tbody></table>"""
+        return s;
+
 class TestCase:
     def __init__(self, directory, executable):
         self.directory = directory      # Absolute directory
@@ -265,8 +336,9 @@ for dirpath, dirnames, filenames in os.walk(invokeDir):
         results[t.name] = t.results
 
 os.chdir(invokeDir)
+results.genStats()
 results.save()
 
 # Local Variables:
-# compile-command: "python runtests.py"
+# compile-command: "python tester.py"
 # End: