[pypy-svn] r9926 - pypy/dist/pypy/lib/test2

alex at codespeak.net alex at codespeak.net
Sun Mar 20 16:45:35 CET 2005


Author: alex
Date: Sun Mar 20 16:45:34 2005
New Revision: 9926

Modified:
   pypy/dist/pypy/lib/test2/test_obj.py
Log:
add test for pickling object w/__reduce__ returning a 2-tuple



Modified: pypy/dist/pypy/lib/test2/test_obj.py
==============================================================================
--- pypy/dist/pypy/lib/test2/test_obj.py	(original)
+++ pypy/dist/pypy/lib/test2/test_obj.py	Sun Mar 20 16:45:34 2005
@@ -3,11 +3,16 @@
 import sys, cStringIO, pickle
 
 class Picklable(object):
-    def __init__(self):
-        self.a = 5
+    def __init__(self, a=5):
+        self.a = a
     def __eq__(self, other):
         return self.a == other.a
-    
+    def __str__(self):
+        return '%s(%r)' % (self.__class__.__name__, self.a)
+
+class PicklableSpecial2(Picklable):
+    def __reduce__(self):
+        return self.__class__, (self.a,)
 
 class ObjectTest(unittest.TestCase):
 
@@ -23,13 +28,18 @@
         l = range(5)
         self.assertRaises(TypeError, hash, l)
 
-    def test_pickle_plain(self):
-        x = Picklable()
+    def _pickle_some(self, x):
         for proto in range(pickle.HIGHEST_PROTOCOL + 1):
             s = pickle.dumps(x, proto)
             y = pickle.loads(s)
             self.assertEqual(x, y)
 
+    def test_pickle_plain(self):
+        self._pickle_some(Picklable())
+
+    def test_pickle_special2(self):
+        self._pickle_some(PicklableSpecial2())
+
 def test_main():
     test.test_support.run_unittest(ObjectTest)
 



More information about the Pypy-commit mailing list