[py-svn] r56968 - in py/branch/event/py/test2: . rsession/testing testing

hpk at codespeak.net hpk at codespeak.net
Mon Aug 4 14:13:31 CEST 2008


Author: hpk
Date: Mon Aug  4 14:13:29 2008
New Revision: 56968

Modified:
   py/branch/event/py/test2/repevent.py
   py/branch/event/py/test2/rsession/testing/test_masterslave.py
   py/branch/event/py/test2/runner.py
   py/branch/event/py/test2/testing/test_repevent.py
   py/branch/event/py/test2/testing/test_runner.py
Log:
make items and ItemTestReports serialized via pickle


Modified: py/branch/event/py/test2/repevent.py
==============================================================================
--- py/branch/event/py/test2/repevent.py	(original)
+++ py/branch/event/py/test2/repevent.py	Mon Aug  4 14:13:29 2008
@@ -68,36 +68,14 @@
         exec "%s = property(lambda self: self.outcome == %r)\n" %(_,_)
     failed = property(lambda self: self.outcome.startswith("failed"))
 
-    @classmethod
-    def fromdumps(cls, string):
-        d = marshal.loads(string)
-        assert isinstance(d, dict)
-        return cls(**d)
-        
-    def __init__(self, trail, outcome, repr_run, repr_path, outerr=None):
-        self.trail = trail 
+    def __init__(self, item, outcome, repr_run, repr_path, outerr=None):
+        self.item = item 
         assert outcome in validoutcomes
         self.outcome = outcome
         self.repr_run = repr_run
         self.repr_path = repr_path
         self.outerr = outerr
 
-    def dumps(self):
-        """ marshal all possible attr to a string. """ 
-        # as this might run in some remote process
-        # where we might not see exceptions we try 
-        # to make this code here robust.  
-        # XXX just dump __dict__, ensure debuggability otherwise
-        d = {}
-        for name, value in self.__dict__.items():
-            try:
-                marshal.dumps(value)
-            except ValueError: 
-                pass
-            else:
-                d[name] = value 
-        return marshal.dumps(d)
-
 
 # ----------------------------------------------------------------------
 # Distributed Testing Events 

Modified: py/branch/event/py/test2/rsession/testing/test_masterslave.py
==============================================================================
--- py/branch/event/py/test2/rsession/testing/test_masterslave.py	(original)
+++ py/branch/event/py/test2/rsession/testing/test_masterslave.py	Mon Aug  4 14:13:29 2008
@@ -80,7 +80,7 @@
         event = queue.get(timeout=2.0)
         assert event.passed 
         assert not self.node.pending
-        assert event.trail == item._get_collector_trail()
+        assert event.item == item
         #assert event.item == item 
         #assert event.item is not item 
 

Modified: py/branch/event/py/test2/runner.py
==============================================================================
--- py/branch/event/py/test2/runner.py	(original)
+++ py/branch/event/py/test2/runner.py	Mon Aug  4 14:13:29 2008
@@ -70,14 +70,13 @@
 
 def makereport(runinfo):
     item = runinfo.item 
-    trail = item._get_collector_trail()
     repr_path = item.repr_path()
     if runinfo.outcome not in ("failed_setup", "failed_teardown"):
         repr_run = item.repr_run(runinfo)
     else:
         repr_run = pypresent.python_repr_run(runinfo, 
             title="failure during setup/teardown")
-    return repevent.ItemTestReport(trail, runinfo.outcome, repr_run, repr_path)
+    return repevent.ItemTestReport(item, runinfo.outcome, repr_run, repr_path)
 
 NORESULT = object()
 # 
@@ -111,6 +110,9 @@
         pdb(runinfo)
     return makereport(runinfo)
 
+from cPickle import Pickler, Unpickler
+from cStringIO import StringIO
+
 def forked_run_report(item, setupstate, getcapture, pdb=None):
     EXITSTATUS_TESTEXIT = 4
 
@@ -120,13 +122,22 @@
         except (KeyboardInterrupt, Exit): 
             os._exit(EXITSTATUS_TESTEXIT)
         testrep = makereport(runinfo)
-        return testrep.dumps() 
+        f = StringIO()
+        p = Pickler(f, -1)
+        p.dump(item._config)
+        p.dump(testrep)
+        return f.getvalue()
 
     ff = py.io.ForkedFunc(runforked)
     result = ff.waitfinish()
     print vars(result)
     if result.retval is not None:
-        return repevent.ItemTestReport.fromdumps(result.retval) 
+        f = StringIO(result.retval)
+        u = Unpickler(f)
+        config = u.load()
+        config._initafterpickle(item._config.topdir) 
+        ev = u.load()
+        return ev 
     else:
         if result.exitstatus == EXITSTATUS_TESTEXIT:
             itemrepr = item.repr_path()
@@ -139,6 +150,5 @@
     tw.sep("!", "CRASHED with signal=%d: %s" %
            (result.signal, repr_path))
     repr_run = tw.stringio.getvalue()
-    trail = item._get_collector_trail()
-    testrep = repevent.ItemTestReport(trail, "failed_crashed", repr_run, repr_path)
+    testrep = repevent.ItemTestReport(item, "failed_crashed", repr_run, repr_path)
     return testrep 

Modified: py/branch/event/py/test2/testing/test_repevent.py
==============================================================================
--- py/branch/event/py/test2/testing/test_repevent.py	(original)
+++ py/branch/event/py/test2/testing/test_repevent.py	Mon Aug  4 14:13:29 2008
@@ -3,15 +3,6 @@
 import setupdata, suptest
 
 class TestItemTestReport(object):
-    def test_dumps_loads(self):
-        for example in "filetest.py", "test_threepass.py":
-            sorter = suptest.events_run_example(example)
-            reports = sorter.get(repevent.ItemTestReport)
-            ev1 = reports[0] 
-            ev2 = repevent.ItemTestReport.fromdumps(ev1.dumps())
-            assert ev1.repr_path == ev2.repr_path
-            assert ev1.repr_run == ev2.repr_run
-            assert ev1.outcome == ev2.outcome
 
     def test_failing(self):
         sorter = suptest.events_run_example("filetest.py")

Modified: py/branch/event/py/test2/testing/test_runner.py
==============================================================================
--- py/branch/event/py/test2/testing/test_runner.py	(original)
+++ py/branch/event/py/test2/testing/test_runner.py	Mon Aug  4 14:13:29 2008
@@ -7,6 +7,12 @@
 class MockItem:
     def __init__(self, func):
         self.func = func
+        self._config = py.test2.config._reparse([])
+
+    def __getstate__(self):
+        return (self._config, )
+    def __setstate__(self, repr):
+        self._config, = repr 
 
     def _get_collector_trail(self):
         return "MockItem.trail"



More information about the pytest-commit mailing list