[pypy-svn] r10007 - in pypy/dist/pypy/objspace: . test

arigo at codespeak.net arigo at codespeak.net
Mon Mar 21 18:44:30 CET 2005


Author: arigo
Date: Mon Mar 21 18:44:30 2005
New Revision: 10007

Added:
   pypy/dist/pypy/objspace/test/test_thunkobjspace.py   (contents, props changed)
Modified:
   pypy/dist/pypy/objspace/thunk.py
Log:
fixeol, typo, test for thunkobjspace.



Added: pypy/dist/pypy/objspace/test/test_thunkobjspace.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/objspace/test/test_thunkobjspace.py	Mon Mar 21 18:44:30 2005
@@ -0,0 +1,35 @@
+
+class AppTest_Thunk:
+
+    objspacename = 'thunk'
+
+    def test_simple(self):
+        computed = []
+        def f():
+            computed.append(True)
+            return 6*7
+        x = thunk(f)
+        assert computed == []
+        t = type(x)
+        assert t is int
+        assert computed == [True]
+        t = type(x)
+        assert t is int
+        assert computed == [True]
+
+    def test_setitem(self):
+        computed = []
+        def f():
+            computed.append(True)
+            return 6*7
+        x = thunk(f)
+        d = {5: x}
+        d[6] = x
+        d[7] = []
+        d[7].append(x)
+        assert computed == []
+        y = d[5], d[6], d.values(), d.items()
+        assert computed == []
+        d[7][0] += 1
+        assert computed == [True]
+        assert d[7] == [43]

Modified: pypy/dist/pypy/objspace/thunk.py
==============================================================================
--- pypy/dist/pypy/objspace/thunk.py	(original)
+++ pypy/dist/pypy/objspace/thunk.py	Mon Mar 21 18:44:30 2005
@@ -23,14 +23,14 @@
 
 # __________________________________________________________________________
 
-class Thunk(W_Root, object):
+class W_Thunk(W_Root, object):
     def __init__(w_self, space, w_callable):
         w_self.space = space
         w_self.w_callable = w_callable
         w_self.w_value = None
 
 def force(w_self):
-    while isinstance(w_self, Thunk):
+    while isinstance(w_self, W_Thunk):
         if w_self.w_value is None:
             w_self.w_value = w_self.space.call_function(w_self.w_callable)
             w_self.w_callable = None
@@ -38,7 +38,7 @@
     return w_self
 
 def thunk(space, w_callable):
-    return Thunk(space, w_callable)
+    return W_Thunk(space, w_callable)
 app_thunk = gateway.interp2app(thunk)
 
 # __________________________________________________________________________



More information about the Pypy-commit mailing list