[pypy-svn] r28738 - in pypy/dist/pypy: lib module/_stackless/test

stephan at codespeak.net stephan at codespeak.net
Tue Jun 13 12:24:23 CEST 2006


Author: stephan
Date: Tue Jun 13 12:24:19 2006
New Revision: 28738

Added:
   pypy/dist/pypy/module/_stackless/test/test_stackless_counter.py   (contents, props changed)
   pypy/dist/pypy/module/_stackless/test/test_stackless_with_channel.py   (contents, props changed)
Removed:
   pypy/dist/pypy/module/_stackless/test/coro1.py
   pypy/dist/pypy/module/_stackless/test/coroutine_dummy.py
   pypy/dist/pypy/module/_stackless/test/counter.py
   pypy/dist/pypy/module/_stackless/test/stack1.py
   pypy/dist/pypy/module/_stackless/test/stack2.py
   pypy/dist/pypy/module/_stackless/test/stackless_firsttry.py
Modified:
   pypy/dist/pypy/lib/stackless.py
   pypy/dist/pypy/module/_stackless/test/test_stackless.py
Log:
add some stackless tests (and delete it's non test counterparts)


Modified: pypy/dist/pypy/lib/stackless.py
==============================================================================
--- pypy/dist/pypy/lib/stackless.py	(original)
+++ pypy/dist/pypy/lib/stackless.py	Tue Jun 13 12:24:19 2006
@@ -299,7 +299,6 @@
     if DEBUG:
         print 'stackless.run()'
     me = scheduler.current_remove()
-    print 'me is', me
     if me is not main_tasklet:
         raise RuntimeError("run() must be run from the main thread's \
                              main tasklet")

Modified: pypy/dist/pypy/module/_stackless/test/test_stackless.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_stackless.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_stackless.py	Tue Jun 13 12:24:19 2006
@@ -6,7 +6,7 @@
         space = gettestobjspace(usemodules=('_stackless',))
         cls.space = space
 
-    def test_one(self):
+    def x_test_one(self):
         import stackless
         print stackless.__file__
         t = stackless.tasklet()
@@ -19,3 +19,28 @@
         x = A("heinz")
         x.demo()
         print x.name
+
+    def test_simple(self):
+        import stackless
+
+        rlist = []
+
+        def f():
+            rlist.append('f')
+
+        def g():
+            rlist.append('g')
+            stackless.schedule()
+
+        def main():
+            rlist.append('m')
+            cg = stackless.tasklet(g)()
+            cf = stackless.tasklet(f)()
+            stackless.run()
+            rlist.append('m')
+
+        main()
+
+        assert stackless.getcurrent() is stackless.main_tasklet
+        assert rlist == 'm g f m'.split()
+

Added: pypy/dist/pypy/module/_stackless/test/test_stackless_counter.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/_stackless/test/test_stackless_counter.py	Tue Jun 13 12:24:19 2006
@@ -0,0 +1,32 @@
+from pypy.conftest import gettestobjspace
+
+class AppTest_Stackless:
+
+    def setup_class(cls):
+        space = gettestobjspace(usemodules=('_stackless',))
+        cls.space = space
+
+    def test_this(self):
+        import random
+        import stackless
+
+        numbers = range(20)
+        random.shuffle(numbers)
+
+        def counter(n, ch):
+            for i in xrange(n):
+                stackless.schedule()
+            ch.send(n)
+
+        ch = stackless.channel()
+        for each in numbers:
+            stackless.tasklet(counter)(each, ch)
+
+        stackless.run()
+
+        rlist = []
+        while ch.balance:
+            rlist.append(ch.receive())
+
+        numbers.sort()
+        assert rlist == numbers

Added: pypy/dist/pypy/module/_stackless/test/test_stackless_with_channel.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/_stackless/test/test_stackless_with_channel.py	Tue Jun 13 12:24:19 2006
@@ -0,0 +1,36 @@
+from pypy.conftest import gettestobjspace
+
+class AppTest_Stackless:
+
+    def setup_class(cls):
+        space = gettestobjspace(usemodules=('_stackless',))
+        cls.space = space
+
+    def test_with_channel(self):
+        import stackless
+
+        rlist = []
+        def f(outchan):
+            for i in range(10):
+                rlist.append('s%s' % i)
+                outchan.send(i)
+            outchan.send(-1)
+
+        def g(inchan):
+            while 1:
+                val = inchan.receive()
+                if val == -1:
+                    break
+                rlist.append('r%s' % val)
+
+        ch = stackless.channel()
+        t1 = stackless.tasklet(f)(ch)
+        t2 = stackless.tasklet(g)(ch)
+
+        stackless.run()
+
+        assert len(rlist) == 20
+        for i in range(10):
+            (s,r), rlist = rlist[:2], rlist[2:]
+            assert s == 's%s' % i
+            assert r == 'r%s' % i



More information about the Pypy-commit mailing list