[pypy-svn] r58068 - in pypy/branch/pypy-pytrunk/pypy: . tool/pytest tool/pytest/test

pedronis at codespeak.net pedronis at codespeak.net
Thu Sep 11 16:05:38 CEST 2008


Author: pedronis
Date: Thu Sep 11 16:05:34 2008
New Revision: 58068

Added:
   pypy/branch/pypy-pytrunk/pypy/tool/pytest/filelog.py   (contents, props changed)
   pypy/branch/pypy-pytrunk/pypy/tool/pytest/test/test_filelog.py   (contents, props changed)
Modified:
   pypy/branch/pypy-pytrunk/pypy/conftest.py
Log:
(iko, pedronis)

start of a py.test Session subclass that additionally also records outcome events in a log file in a format similar to
htmlconftest outcome



Modified: pypy/branch/pypy-pytrunk/pypy/conftest.py
==============================================================================
--- pypy/branch/pypy-pytrunk/pypy/conftest.py	(original)
+++ pypy/branch/pypy-pytrunk/pypy/conftest.py	Thu Sep 11 16:05:34 2008
@@ -29,7 +29,10 @@
                help="run applevel tests directly on python interpreter (not through PyPy)"),
         Option('--direct', action="store_true",
                default=False, dest="rundirect",
-               help="run pexpect tests directly")
+               help="run pexpect tests directly"),
+        Option('--filelog', action="store",
+               default=None, dest="filelog",
+               help="path for FileLogSession logging")
     )
 
 _SPACECACHE={}
@@ -494,3 +497,5 @@
         # disable recursion in symlinked subdirectories
         return (py.test.collect.Directory.recfilter(self, path)
                 and path.check(link=0))
+
+from pypy.tool.pytest.filelog import FileLogSession

Added: pypy/branch/pypy-pytrunk/pypy/tool/pytest/filelog.py
==============================================================================
--- (empty file)
+++ pypy/branch/pypy-pytrunk/pypy/tool/pytest/filelog.py	Thu Sep 11 16:05:34 2008
@@ -0,0 +1,23 @@
+from py.__.test.session import Session
+from py.__.test import event
+
+class FileLogSession(Session):
+
+    def __init__(self, config):
+        super(FileLogSession, self).__init__(config)
+        self.bus.subscribe(self.log_event_to_file)
+        if hasattr(config.option, 'filelog'):
+            filelog = config.option.filelog
+            self.logfile = open(filelog, 'w') # line buffering ?
+
+
+    def log_event_to_file(self, ev):
+        if isinstance(ev, event.ItemTestReport):
+            outcome = ev.outcome
+            metainfo = ev.colitem.repr_metainfo()
+            path = metainfo.fspath
+            modpath = metainfo.modpath
+            if modpath:
+                path += ":%s" % modpath
+            print >>self.logfile, "%s %s" % (outcome.shortrepr, path)
+

Added: pypy/branch/pypy-pytrunk/pypy/tool/pytest/test/test_filelog.py
==============================================================================
--- (empty file)
+++ pypy/branch/pypy-pytrunk/pypy/tool/pytest/test/test_filelog.py	Thu Sep 11 16:05:34 2008
@@ -0,0 +1,72 @@
+from pypy.tool.pytest import filelog
+import os, StringIO
+
+from py.__.test.event import ItemTestReport
+
+
+class Fake(object):
+    def __init__(self, **kwds):
+        self.__dict__.update(kwds)
+
+
+class TestFileLogSession(object):
+
+
+    def test_sanity(self):
+        option = Fake(eventlog=None)
+        config = Fake(option=option)
+        
+        filelog.FileLogSession(config)
+
+    def test_open_logfile(self):
+        logfname = os.tempnam()
+        
+        option = Fake(eventlog=None, filelog=logfname)        
+        config = Fake(option=option)
+        
+        sess = filelog.FileLogSession(config)
+
+        assert len(sess.bus._subscribers) == 1
+
+        assert sess.logfile
+        assert os.path.exists(logfname)
+
+        sess.logfile.close()
+        os.unlink(logfname)
+
+    def test_item_test_passed_or_skipped(self):            
+        option = Fake(eventlog=None)
+        config = Fake(option=option)
+        sess = filelog.FileLogSession(config)
+        sess.logfile = StringIO.StringIO()
+
+        colitem = Fake(repr_metainfo=lambda: Fake(fspath='some/path',
+                                                  modpath="a.b"))
+        outcome=Fake(shortrepr='.')
+        rep_ev = ItemTestReport(colitem, outcome=outcome)
+
+        sess.bus.notify(rep_ev)
+
+        lines = sess.logfile.getvalue().splitlines()
+        assert len(lines) == 1
+        line = lines[0]
+        assert line.startswith(". ")
+        assert line[2:] == 'some/path:a.b'
+
+        sess.logfile = StringIO.StringIO()
+        colitem = Fake(repr_metainfo=lambda: Fake(fspath='some/path',
+                                                  modpath=None))
+        outcome=Fake(shortrepr='s')
+        rep_ev = ItemTestReport(colitem, outcome=outcome)
+
+        sess.bus.notify(rep_ev)
+
+        lines = sess.logfile.getvalue().splitlines()
+        assert len(lines) == 1
+        line = lines[0]
+
+        assert line.startswith("s ")
+        assert line[2:] == 'some/path'        
+        
+
+# XXX integration tests



More information about the Pypy-commit mailing list