[pypy-svn] r11847 - in pypy/dist/pypy/tool/pytest: . test

hpk at codespeak.net hpk at codespeak.net
Tue May 3 14:09:03 CEST 2005


Author: hpk
Date: Tue May  3 14:09:03 2005
New Revision: 11847

Added:
   pypy/dist/pypy/tool/pytest/overview.py
   pypy/dist/pypy/tool/pytest/test/   (props changed)
   pypy/dist/pypy/tool/pytest/test/__init__.py
      - copied unchanged from r11839, pypy/dist/pypy/tool/pytest/__init__.py
   pypy/dist/pypy/tool/pytest/test/test_overview.py
Modified:
   pypy/dist/pypy/tool/pytest/genreportdata.py
   pypy/dist/pypy/tool/pytest/htmlreport.py
   pypy/dist/pypy/tool/pytest/result.py
Log:
separate result parsing from reporting some more 



Modified: pypy/dist/pypy/tool/pytest/genreportdata.py
==============================================================================
--- pypy/dist/pypy/tool/pytest/genreportdata.py	(original)
+++ pypy/dist/pypy/tool/pytest/genreportdata.py	Tue May  3 14:09:03 2005
@@ -15,7 +15,7 @@
 
     print "traversing", mydir 
     rep = htmlreport.HtmlReport()
-    rep.parse_all(testresultdir)
+    rep.parselatest()
 
     print "making html files"
     rep.makeindex(testresultdir.join('index.html'))

Modified: pypy/dist/pypy/tool/pytest/htmlreport.py
==============================================================================
--- pypy/dist/pypy/tool/pytest/htmlreport.py	(original)
+++ pypy/dist/pypy/tool/pytest/htmlreport.py	Tue May  3 14:09:03 2005
@@ -7,6 +7,7 @@
 import sys, os, re
 import py 
 from pypy.tool.pytest import result
+from pypy.tool.pytest.overview import ResultCache 
 
 # 
 # various interesting path objects 
@@ -16,63 +17,14 @@
 
 class HtmlReport(object): 
     def __init__(self): 
-        self.results = []
-        self.name2result = {}
-
-    def parse_all(self, testresultdir): 
-        def filefilter(p): 
-            return p.check(fnmatch='test_*.txt', file=1)
-        def rec(p): 
-            return p.check(dotfile=0)
-        for x in testresultdir.visit(filefilter, rec): 
-            self.parse_one(x)
-    
-    def parse_one(self, resultpath): 
-        try: 
-            res = result.ResultFromMime(resultpath) 
-            ver = res['testreport-version']
-            if ver != "1.1":
-                raise TypeError
-        except TypeError: 
-            return
-        #else: 
-        #    print "sucess", resultpath 
-        self.results.append(res) 
-        name = res.fspath.purebasename 
-        self.name2result.setdefault(name, []).append(res) 
-        return res 
+        self.resultcache = ResultCache()
+    def parselatest(self): 
+        self.resultcache.parselatest()
 
     # 
     # rendering 
     # 
 
-    def get_latest_results(self, checkerfunc=None): 
-        names = self.name2result.keys()
-        names.sort(lambda x,y: cmp(x.lower(), y.lower()))
-        l = []
-        for name in names: 
-            resultlist = self.name2result[name]
-            maxrev = 0
-            maxresult = None
-            for res in resultlist: 
-                resrev = res['pypy-revision']
-                if resrev != 'unknown' and not res.istimeout(): 
-                    if resrev > maxrev: 
-                        maxrev = resrev 
-                        maxresult = res 
-            if not maxresult: 
-                for res in resultlist: 
-                    resrev = res['pypy-revision']
-                    if resrev != 'unknown': 
-                        if resrev > maxrev: 
-                            maxrev = resrev
-                            maxresult = res 
-            assert maxresult
-
-            if not checkerfunc or checkerfunc(maxresult): 
-                l.append(maxresult) 
-        return l 
-
     def render_latest_table(self, results): 
         table = html.table(
                     [html.th(x, align='left') 
@@ -137,11 +89,14 @@
             return 'core' in result.get('options', []) 
         coretests = []
         noncoretests = [] 
-        for x in self.get_latest_results() : 
-            if iscore(x): 
-                coretests.append(x)
+        for name in self.resultcache.getnames(): 
+            result = self.resultcache.getlatest(name, error=1, ok=1)
+            if not result: 
+                result = self.resultcache.getlatest(name) 
+            if iscore(result): 
+                coretests.append(result)
             else: 
-                noncoretests.append(x) 
+                noncoretests.append(result) 
         return coretests, noncoretests 
     
     # generate html files 
@@ -155,7 +110,7 @@
                        "core tests"))
 
         ok = len([x for x in coretests if x.isok()])
-        err = len([x for x in coretests if x.iserr()])
+        err = len([x for x in coretests if x.iserror()])
         to = len([x for x in coretests if x.istimeout()])
         sum = ok + err + to
         sum100 = sum / 100.0
@@ -191,7 +146,7 @@
 def getresultcolor(result): 
     if result.isok(): 
         color = "#00ee00"
-    elif result.iserr(): 
+    elif result.iserror(): 
         color = "#ee0000" 
     elif result.istimeout: 
         color = "#0000ee"

Added: pypy/dist/pypy/tool/pytest/overview.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/pytest/overview.py	Tue May  3 14:09:03 2005
@@ -0,0 +1,50 @@
+from pypy.tool.pytest.confpath import testresultdir 
+from pypy.tool.pytest import result 
+
+
+class ResultCache: 
+    def __init__(self): 
+        self.name2result = {}
+
+    def parselatest(self): 
+        def filefilter(p): 
+            return p.check(fnmatch='test_*.txt', file=1)
+        def rec(p): 
+            return p.check(dotfile=0)
+        for x in testresultdir.visit(filefilter, rec): 
+            self.parse_one(x)
+    
+    def parse_one(self, resultpath): 
+        try: 
+            res = result.ResultFromMime(resultpath) 
+            ver = res['testreport-version']
+            if ver != "1.1":
+                raise TypeError
+        except TypeError: 
+            return
+        name = res.fspath.purebasename 
+        self.name2result.setdefault(name, []).append(res) 
+        return res 
+
+    def getnames(self): 
+        return self.name2result.keys()
+
+    def getlatest(self, name, timeout=0, error=0, ok=0): 
+        l = []
+        resultlist = self.name2result[name]
+        maxrev = 0
+        maxresult = None
+        for res in resultlist: 
+            resrev = res['pypy-revision']
+            if resrev == 'unknown': 
+                continue 
+            if resrev <= maxrev: 
+                continue 
+            if timeout or error or ok:
+                if not (timeout and res.istimeout() or
+                        error and res.iserror() or 
+                        ok and res.isok()): 
+                    continue 
+            maxrev = resrev 
+            maxresult = res 
+        return maxresult 

Modified: pypy/dist/pypy/tool/pytest/result.py
==============================================================================
--- pypy/dist/pypy/tool/pytest/result.py	(original)
+++ pypy/dist/pypy/tool/pytest/result.py	Tue May  3 14:09:03 2005
@@ -66,7 +66,7 @@
 
     def isok(self): 
         return self['outcome'].lower() == 'ok'
-    def iserr(self): 
+    def iserror(self): 
         return self['outcome'].lower()[:3] == 'err'
     def istimeout(self): 
         return self['outcome'].lower() == 't/o'
@@ -96,6 +96,11 @@
                 fn = submsg.get_filename() 
                 assert fn
                 self.addnamedtext(fn, submsg.get_payload())
+    def __repr__(self): 
+        return '<%s (%s) %r rev=%s>' %(self.__class__.__name__, 
+                                  self['outcome'], 
+                                  self.fspath.purebasename, 
+                                  self['pypy-revision'])
 
 def stdinit(result): 
     import getpass

Added: pypy/dist/pypy/tool/pytest/test/test_overview.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/pytest/test/test_overview.py	Tue May  3 14:09:03 2005
@@ -0,0 +1,20 @@
+
+import py
+from pypy.tool.pytest.overview import ResultCache 
+
+class TestResultCache: 
+    def setup_class(cls): 
+        cls.rc = ResultCache() 
+        cls.rc.parselatest()
+
+    def test_getlatest_all(self): 
+        for type in 'error', 'timeout', 'ok': 
+            for name in self.rc.getnames(): 
+                result = self.rc.getlatest(name, **{type:1})
+                if result: 
+                    meth = getattr(result, 'is'+type)
+                    assert meth()
+
+    def test_getlatest_datetime(self): 
+        result = self.rc.getlatest('test_datetime', ok=1) 
+        assert result



More information about the Pypy-commit mailing list