[pypy-commit] pypy py3.5: Split off the pickle tests that cannot possibly work on appdirect to a separate class

rlamy pypy.commits at gmail.com
Tue Oct 11 13:40:08 EDT 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r87718:be1170fa2db1
Date: 2016-10-11 18:39 +0100
http://bitbucket.org/pypy/pypy/changeset/be1170fa2db1/

Log:	Split off the pickle tests that cannot possibly work on appdirect to
	a separate class

diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py b/pypy/interpreter/test/test_zzpickle_and_slow.py
--- a/pypy/interpreter/test/test_zzpickle_and_slow.py
+++ b/pypy/interpreter/test/test_zzpickle_and_slow.py
@@ -71,17 +71,10 @@
 
 
 class AppTestInterpObjectPickling:
-    pytestmark = py.test.mark.skipif("config.option.runappdirect")
     spaceconfig = {
         "usemodules": ["struct", "binascii"]
     }
 
-    def setup_class(cls):
-        _attach_helpers(cls.space)
-
-    def teardown_class(cls):
-        _detach_helpers(cls.space)
-
     def test_pickle_basic(self):
         import pickle
         pckl = pickle.dumps((u'abc', 0))
@@ -161,123 +154,6 @@
         assert cell == result
         assert not (cell != result)
 
-    def test_pickle_frame(self):
-        #import sys
-        # avoid creating a closure for now
-        def f():
-            try:
-                raise Exception()
-            except:
-                import sys
-                exc_type, exc, tb = sys.exc_info()
-                return tb.tb_frame
-        import pickle
-        f1     = f()
-        saved = hide_top_frame(f1)
-        pckl   = pickle.dumps(f1)
-        restore_top_frame(f1, saved)
-        f2     = pickle.loads(pckl)
-
-        assert type(f1) is type(f2)
-        assert dir(f1) == dir(f2)
-        assert f1.__doc__ == f2.__doc__
-        assert f2.f_back is None # because we pruned it
-        assert f1.f_builtins is f2.f_builtins
-        assert f1.f_code == f2.f_code
-        assert f1.f_exc_traceback is f2.f_exc_traceback
-        assert f1.f_exc_type is f2.f_exc_type
-        assert f1.f_exc_value is f2.f_exc_value
-        assert f1.f_lasti == f2.f_lasti
-        assert f1.f_lineno == f2.f_lineno
-        assert f1.f_restricted is f2.f_restricted
-        assert f1.f_trace is f2.f_trace
-
-    def test_pickle_frame_with_exc(self):
-        #import sys
-        # avoid creating a closure for now
-        self = None
-        def f():
-            try:
-                raise ValueError
-            except:
-                import sys, pickle
-                f = sys._getframe()
-                saved = hide_top_frame(f)
-                pckl = pickle.dumps(f)
-                restore_top_frame(f, saved)
-                return pckl
-
-        import pickle
-        pckl   = f()
-        f2     = pickle.loads(pckl)
-
-        assert read_exc_type(f2) is ValueError
-
-    def test_pickle_frame_with_exc_nested(self):
-        # avoid creating a closure for now
-        self = None
-        def f():
-            try:
-                1/0
-            except:
-                try:
-                    raise ValueError
-                except:
-                    import sys, pickle
-                    f = sys._getframe()
-                    saved = hide_top_frame(f)
-                    pckl = pickle.dumps(f)
-                    restore_top_frame(f, saved)
-                    return pckl
-
-        import pickle
-        pckl   = f()
-        f2     = pickle.loads(pckl)
-
-        assert read_exc_type(f2) is ValueError
-
-    def test_pickle_frame_clos(self):
-        # similar to above, therefore skipping the asserts.
-        # we just want to see that the closure works
-        import sys # this is the difference!
-        def f():
-            try:
-                raise Exception()
-            except:
-                exc_type, exc, tb = sys.exc_info()
-                return tb.tb_frame
-        import pickle
-        f1     = f()
-        saved = hide_top_frame(f1)
-        pckl   = pickle.dumps(f1)
-        restore_top_frame(f1, saved)
-        f2     = pickle.loads(pckl)
-
-    def test_frame_setstate_crash(self):
-        import sys
-        raises(ValueError, sys._getframe().__setstate__, [])
-
-    def test_pickle_traceback(self):
-        def f():
-            try:
-                raise Exception()
-            except:
-                from sys import exc_info
-                exc_type, exc, tb = exc_info()
-                return tb
-        import pickle
-        tb     = f()
-        saved = hide_top_frame(tb.tb_frame)
-        pckl   = pickle.dumps(tb)
-        result = pickle.loads(pckl)
-
-        assert type(tb) is type(result)
-        assert tb.tb_lasti == result.tb_lasti
-        assert tb.tb_lineno == result.tb_lineno
-        assert tb.tb_next == result.tb_next
-
-        restore_top_frame(tb.tb_frame, saved)
-
     def test_pickle_module(self):
         import pickle
         mod    = pickle
@@ -644,3 +520,133 @@
             raises(StopIteration, next, g2)
             raises(StopIteration, next, g3)
             raises(StopIteration, next, g4)
+
+class AppTestFramePickling(object):
+    pytestmark = py.test.mark.skipif("config.option.runappdirect")
+    spaceconfig = {
+        "usemodules": ["struct"]
+    }
+
+    def setup_class(cls):
+        _attach_helpers(cls.space)
+
+    def teardown_class(cls):
+        _detach_helpers(cls.space)
+
+    def test_pickle_frame(self):
+        #import sys
+        # avoid creating a closure for now
+        def f():
+            try:
+                raise Exception()
+            except:
+                import sys
+                exc_type, exc, tb = sys.exc_info()
+                return tb.tb_frame
+        import pickle
+        f1     = f()
+        saved = hide_top_frame(f1)
+        pckl   = pickle.dumps(f1)
+        restore_top_frame(f1, saved)
+        f2     = pickle.loads(pckl)
+
+        assert type(f1) is type(f2)
+        assert dir(f1) == dir(f2)
+        assert f1.__doc__ == f2.__doc__
+        assert f2.f_back is None # because we pruned it
+        assert f1.f_builtins is f2.f_builtins
+        assert f1.f_code == f2.f_code
+        assert f1.f_exc_traceback is f2.f_exc_traceback
+        assert f1.f_exc_type is f2.f_exc_type
+        assert f1.f_exc_value is f2.f_exc_value
+        assert f1.f_lasti == f2.f_lasti
+        assert f1.f_lineno == f2.f_lineno
+        assert f1.f_restricted is f2.f_restricted
+        assert f1.f_trace is f2.f_trace
+
+    def test_pickle_frame_with_exc(self):
+        #import sys
+        # avoid creating a closure for now
+        self = None
+        def f():
+            try:
+                raise ValueError
+            except:
+                import sys, pickle
+                f = sys._getframe()
+                saved = hide_top_frame(f)
+                pckl = pickle.dumps(f)
+                restore_top_frame(f, saved)
+                return pckl
+
+        import pickle
+        pckl   = f()
+        f2     = pickle.loads(pckl)
+
+        assert read_exc_type(f2) is ValueError
+
+    def test_pickle_frame_with_exc_nested(self):
+        # avoid creating a closure for now
+        self = None
+        def f():
+            try:
+                1/0
+            except:
+                try:
+                    raise ValueError
+                except:
+                    import sys, pickle
+                    f = sys._getframe()
+                    saved = hide_top_frame(f)
+                    pckl = pickle.dumps(f)
+                    restore_top_frame(f, saved)
+                    return pckl
+
+        import pickle
+        pckl   = f()
+        f2     = pickle.loads(pckl)
+
+        assert read_exc_type(f2) is ValueError
+
+    def test_pickle_frame_clos(self):
+        # similar to above, therefore skipping the asserts.
+        # we just want to see that the closure works
+        import sys # this is the difference!
+        def f():
+            try:
+                raise Exception()
+            except:
+                exc_type, exc, tb = sys.exc_info()
+                return tb.tb_frame
+        import pickle
+        f1     = f()
+        saved = hide_top_frame(f1)
+        pckl   = pickle.dumps(f1)
+        restore_top_frame(f1, saved)
+        f2     = pickle.loads(pckl)
+
+    def test_frame_setstate_crash(self):
+        import sys
+        raises(ValueError, sys._getframe().__setstate__, [])
+
+    def test_pickle_traceback(self):
+        def f():
+            try:
+                raise Exception()
+            except:
+                from sys import exc_info
+                exc_type, exc, tb = exc_info()
+                return tb
+        import pickle
+        tb     = f()
+        saved = hide_top_frame(tb.tb_frame)
+        pckl   = pickle.dumps(tb)
+        result = pickle.loads(pckl)
+
+        assert type(tb) is type(result)
+        assert tb.tb_lasti == result.tb_lasti
+        assert tb.tb_lineno == result.tb_lineno
+        assert tb.tb_next == result.tb_next
+
+        restore_top_frame(tb.tb_frame, saved)
+


More information about the pypy-commit mailing list