[py-svn] r35593 - in py/branch/rsession-cleanup/py/test/rsession: . testing

fijal at codespeak.net fijal at codespeak.net
Mon Dec 11 19:47:29 CET 2006


Author: fijal
Date: Mon Dec 11 19:47:28 2006
New Revision: 35593

Modified:
   py/branch/rsession-cleanup/py/test/rsession/executor.py
   py/branch/rsession-cleanup/py/test/rsession/testing/test_executor.py
Log:
Added async executor


Modified: py/branch/rsession-cleanup/py/test/rsession/executor.py
==============================================================================
--- py/branch/rsession-cleanup/py/test/rsession/executor.py	(original)
+++ py/branch/rsession-cleanup/py/test/rsession/executor.py	Mon Dec 11 19:47:28 2006
@@ -64,3 +64,28 @@
                 b.stdoutrepr, b.stderrrepr)
         else:
             return (False, False, None, False, False, b.signal, b.stdoutrepr, b.stderrrepr)
+
+class AsyncExecutor(RunExecutor):
+    """ same as box executor, but instead it returns function to continue
+    computations (more async mode)
+    """
+    wraps = True
+    
+    def execute(self):
+        def fun():
+            outcome = RunExecutor.execute(self)
+            return outcome.make_repr()
+        
+        b = Box(fun)
+        parent, pid = b.run(continuation=True)
+        
+        def cont():
+            parent(pid)
+            if b.retval is not None:
+                passed, setupfailure, excinfo, skipped, critical, _, _, _ = b.retval
+                return (passed, setupfailure, excinfo, skipped, critical, 0,
+                    b.stdoutrepr, b.stderrrepr)
+            else:
+                return (False, False, None, False, False, b.signal, b.stdoutrepr, b.stderrrepr)
+        
+        return cont, pid

Modified: py/branch/rsession-cleanup/py/test/rsession/testing/test_executor.py
==============================================================================
--- py/branch/rsession-cleanup/py/test/rsession/testing/test_executor.py	(original)
+++ py/branch/rsession-cleanup/py/test/rsession/testing/test_executor.py	Mon Dec 11 19:47:28 2006
@@ -2,13 +2,16 @@
 import py
 import example1
 
-from py.__.test.rsession.executor import RunExecutor, BoxExecutor
+from py.__.test.rsession.executor import RunExecutor, BoxExecutor,\
+    AsyncExecutor
 from py.__.test.rsession.outcome import ReprOutcome
 from py.__.test.rsession.testing.test_slave import funcprint_spec, \
     funcprintfail_spec
 
 def setup_module(mod):
     mod.rootdir = py.path.local(py.__file__).dirpath().dirpath()
+    from py.__.test.rsession.rsession import remote_options
+    remote_options['nice_level'] = 0
     
 def XXXtest_executor_passing_function():
     ex = Executor(example1.f1)
@@ -107,3 +110,14 @@
     outcome = ReprOutcome(outcome_repr)
     assert not outcome.passed
     assert outcome.stdout == "samfing elz\n"
+
+def test_cont_executor():
+    rootcol = py.test.collect.Directory(rootdir)
+    item = rootcol.getitembynames(funcprintfail_spec)
+    ex = AsyncExecutor(item)
+    cont, pid = ex.execute()
+    assert pid
+    outcome_repr = cont()
+    outcome = ReprOutcome(outcome_repr)
+    assert not outcome.passed
+    assert outcome.stdout == "samfing elz\n"



More information about the pytest-commit mailing list