[pypy-svn] r26421 - in pypy/dist/pypy: interpreter interpreter/test module/_pickle_support

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Apr 27 10:44:45 CEST 2006


Author: ericvrp
Date: Thu Apr 27 10:44:36 2006
New Revision: 26421

Modified:
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/test/test_pickle.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/module/_pickle_support/__init__.py
   pypy/dist/pypy/module/_pickle_support/maker.py
Log:
More pickle tests (they are currently skipped)


Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Thu Apr 27 10:44:36 2006
@@ -169,6 +169,33 @@
     def descr_function_repr(self):
         return self.getrepr(self.space, 'function %s' % (self.name,))
 
+    def descr__reduce__(self, space):
+        '''
+        w_mod    = space.getbuiltinmodule('_pickle_support')
+        mod      = space.interp_w(MixedModule, w_mod)
+        new_inst = mod.get('code_new')
+        w        = space.wrap
+        tup      = [
+            w(self.co_argcount), 
+            w(self.co_nlocals), 
+            w(self.co_stacksize), 
+            w(self.co_flags),
+            w(self.co_code), 
+            space.newtuple(self.co_consts_w), 
+            space.newtuple(self.co_names_w), 
+            space.newtuple([w(v) for v in self.co_varnames]), 
+            w(self.co_filename),
+            w(self.co_name), 
+            w(self.co_firstlineno),
+            w(self.co_lnotab), 
+            space.newtuple([w(v) for v in self.co_freevars]),
+            space.newtuple([w(v) for v in self.co_cellvars]),
+            #hidden_applevel=False, magic = 62061 | 0x0a0d0000
+        ]
+        return space.newtuple([new_inst, space.newtuple(tup)])
+        '''
+        raise 'Function.desc__reduce__ here'
+        
     def fget_func_defaults(space, self):
         values_w = self.defs_w
         if not values_w:

Modified: pypy/dist/pypy/interpreter/test/test_pickle.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_pickle.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_pickle.py	Thu Apr 27 10:44:36 2006
@@ -1,72 +1,142 @@
 class AppTestInterpObjectPickling:
 
     def test_pickle_code(self):
-        import pickle
         def f():
             return 42
+        import pickle
         code = f.func_code
         pckl = pickle.dumps(code)
         result = pickle.loads(pckl)
         assert code == result
 
-    def DONTtest_pickle_func(self):
-        pass
-    
+    def test_pickle_func(self):
+        skip("work in progress")
+        def func():
+            return 42
+        import pickle
+        pckl = pickle.dumps(func)
+        result = pickle.loads(pckl)
+        assert func == result
+        
     def test_pickle_cell(self):
-        import pickle       
         def g():
             x = [42]
             def f():
                 x[0] += 1
                 return x
             return f.func_closure[0]
+        import pickle       
         cell = g()
-        pckl = pickle.dumps(g())
+        pckl = pickle.dumps(cell)
         result = pickle.loads(pckl)
         assert cell == result
         assert not (cell != result)
 
-    def DONTtest_pickle_frame(self):
-        pass
-
-    def DONTtest_pickle_traceback(self):
-        pass
-
-    def DONTtest_pickle_module(self):
-        pass
-
-    def DONTtest_pickle_moduledict(self):
-        pass
-
-    def DONTtest_pickle_iter(self):
-        pass
-
-    def DONTtest_pickle_method(self):
-        pass
-
-    def DONTtest_pickle_dictiter(self):
-        pass
+    def test_pickle_frame(self):
+        skip("work in progress")
+        from sys import exc_info
+        def f():
+            try:
+                raise Exception()
+            except:
+                exc_type, exc, tb = exc_info()
+                return tb.tb_frame
+        import pickle
+        frame  = f()
+        pckl   = pickle.dumps(frame)
+        result = pickle.loads(pckl)
+        assert frame == result
+        
+    def test_pickle_traceback(self):
+        skip("work in progress")
+        def f():
+            try:
+                raise Exception()
+            except:
+                from sys import exc_info
+                exc_type, exc, tb = exc_info()
+                return tb
+        import pickle
+        tb     = f()
+        pckl   = pickle.dumps(tb)
+        result = pickle.loads(pckl)
+        assert tb == result
 
-    def DONTtest_pickle_enum(self):
-        pass
+    def test_pickle_module(self): #XXX this passes for the wrong reason!
+        skip("work in progress")
+        def f():
+            pass
+        import pickle
+        mod    = f.__module__ #XXX returns a string?
+        pckl   = pickle.dumps(mod)
+        result = pickle.loads(pckl)
+        assert mod == result
 
-    def DONTtest_pickle_enumfactory(self):
-        pass
+    def test_pickle_moduledict(self): #XXX this test is not correct!
+        skip("work in progress")
+        def f():
+            pass
+        import pickle
+        modedict = f.__module__.__dict__ 
+        pckl     = pickle.dumps(moddict)
+        result   = pickle.loads(pckl)
+        assert mod == result
+
+    def test_pickle_iter(self):
+        skip("work in progress")
+
+    def test_pickle_method(self):
+        skip("work in progress")
+        class C(object):
+            def f(self):
+                pass
+        import pickle
+        method   = C.f
+        pckl     = pickle.dumps(method)
+        result   = pickle.loads(pckl)
+        assert method == result
+        
+    def test_pickle_dictiter(self):
+        skip("work in progress")
+        import pickle
+        diter  = iter({})
+        pckl   = pickle.dumps(diter)
+        result = pickle.loads(pckl)
+        assert diter == result
 
-    def DONTtest_pickle_listiter(self):
-        pass
+    def test_pickle_enum(self):
+        skip("work in progress")
 
-    def DONTtest_pickle_rangeiter(self):
-        pass
+    def test_pickle_enumfactory(self):
+        skip("work in progress")
+        
+    def test_pickle_sequenceiter(self):
+        '''
+        In PyPy there is no distinction here between listiterator and
+        tupleiterator that is why you will find no test_pickle_listiter nor
+        test_pickle_tupleiter here, just this test.
+        '''
+        skip("work in progress")
+        import pickle
+        liter  = iter([])
+        pckl   = pickle.dumps(liter)
+        result = pickle.loads(pckl)
+        assert liter == result
 
-    def DONTtest_pickle_tupleiter(self):
-        pass
+    def test_pickle_rangeiter(self):
+        skip("work in progress")
+        import pickle
+        riter  = iter(xrange(5))
+        pckl   = pickle.dumps(riter)
+        result = pickle.loads(pckl)
+        assert riter == result
 
-    #def test_pickle_generator(self):
-    #    import pickle        
-    #    def giveme(n):
-    #        x = 0
-    #        while x < n:
-    #            yield x
-    #    generator = giveme(10)
-    #    print pickle.dumps(generator)
+    def test_pickle_generator(self):
+        skip("work in progress")
+        import pickle        
+        def giveme(n):
+            x = 0
+            while x < n:
+                yield x
+        generator = giveme(10)
+        print pickle.dumps(generator)

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Thu Apr 27 10:44:36 2006
@@ -483,6 +483,8 @@
                           unwrap_spec=['self', Arguments]),
     __get__ = interp2app(descr_function_get),
     __repr__ = interp2app(Function.descr_function_repr),
+    __reduce__ = interp2app(Function.descr__reduce__, 
+                            unwrap_spec=['self', ObjSpace]),
     func_code = getset_func_code, 
     func_doc = getset_func_doc,
     func_name = getset_func_name,

Modified: pypy/dist/pypy/module/_pickle_support/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_pickle_support/__init__.py	(original)
+++ pypy/dist/pypy/module/_pickle_support/__init__.py	Thu Apr 27 10:44:36 2006
@@ -9,4 +9,5 @@
     interpleveldefs = {
         'cell_new': 'maker.cell_new',
         'code_new': 'maker.code_new',
+        'func_new': 'maker.func_new',
     }

Modified: pypy/dist/pypy/module/_pickle_support/maker.py
==============================================================================
--- pypy/dist/pypy/module/_pickle_support/maker.py	(original)
+++ pypy/dist/pypy/module/_pickle_support/maker.py	Thu Apr 27 10:44:36 2006
@@ -1,5 +1,6 @@
 from pypy.interpreter.nestedscope import Cell
 from pypy.interpreter.pycode import PyCode
+from pypy.interpreter.function import Function
 from pypy.rpython.objectmodel import instantiate
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.baseobjspace import ObjSpace
@@ -11,9 +12,13 @@
 
 def cell_new(space):
     return space.wrap(instantiate(Cell))
-#cell_new.unwrap_spec = [...]
 
 def code_new(space, __args__):
-    w_codetype = space.gettypeobject(PyCode.typedef)
-    return space.call_args(w_codetype, __args__)
-code_new.unwrap_spec = [ObjSpace, Arguments]
\ No newline at end of file
+    w_type = space.gettypeobject(PyCode.typedef)
+    return space.call_args(w_type, __args__)
+code_new.unwrap_spec = [ObjSpace, Arguments]
+
+def func_new(space, __args__):
+    w_type = space.gettypeobject(Function.typedef)
+    return space.call_args(w_type, __args__)
+func_new.unwrap_spec = [ObjSpace, Arguments]



More information about the Pypy-commit mailing list