[pypy-svn] r28749 - pypy/dist/pypy/module/_stackless/test

stephan at codespeak.net stephan at codespeak.net
Tue Jun 13 18:14:35 CEST 2006


Author: stephan
Date: Tue Jun 13 18:14:33 2006
New Revision: 28749

Removed:
   pypy/dist/pypy/module/_stackless/test/stack3.py
   pypy/dist/pypy/module/_stackless/test/stack4.py
   pypy/dist/pypy/module/_stackless/test/test_scheduling.py
   pypy/dist/pypy/module/_stackless/test/test_stackless_counter.py
   pypy/dist/pypy/module/_stackless/test/test_stackless_with_channel.py
Modified:
   pypy/dist/pypy/module/_stackless/test/slp_test_pickle.py
   pypy/dist/pypy/module/_stackless/test/test_stackless.py
Log:
fixed stackless test problem and put all stackless tests into one file


Modified: pypy/dist/pypy/module/_stackless/test/slp_test_pickle.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/slp_test_pickle.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/slp_test_pickle.py	Tue Jun 13 18:14:33 2006
@@ -5,13 +5,13 @@
 class AppTest_Pickle:
 
     def setup_class(cls):
-        space = gettestobjspace(usemodules=('stackless',))
+        space = gettestobjspace(usemodules=('_stackless',))
         cls.space = space
 
     def test_simple_ish(self):
 
         output = []
-        import stackless
+        import _stackless
         def f(coro, n, x):
             if n == 0:
                 coro.switch()
@@ -20,8 +20,8 @@
             output.append(x)
 
         def example():
-            main_coro = stackless.coroutine.getcurrent()
-            sub_coro = stackless.coroutine()
+            main_coro = _stackless.coroutine.getcurrent()
+            sub_coro = _stackless.coroutine()
             sub_coro.bind(f, main_coro, 5, 1)
             sub_coro.switch()
 

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 18:14:33 2006
@@ -8,6 +8,7 @@
 
     def x_test_one(self):
         import stackless
+
         print stackless.__file__
         t = stackless.tasklet()
         t.demo()
@@ -22,6 +23,7 @@
 
     def test_simple(self):
         import stackless
+        stackless.__init()
 
         rlist = []
 
@@ -44,3 +46,58 @@
         assert stackless.getcurrent() is stackless.main_tasklet
         assert rlist == 'm g f m'.split()
 
+    def test_with_channel(self):
+        import stackless
+        stackless.__init()
+
+        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
+
+    def test_counter(self):
+        import random
+        import stackless
+        stackless.__init()
+
+        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



More information about the Pypy-commit mailing list