[Python-checkins] python/dist/src/Lib/test pickletester.py,1.25,1.26

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 28 Jan 2003 11:48:21 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv19333/test

Modified Files:
	pickletester.py 
Log Message:
The default __reduce__ on the base object type obscured any
possibility of calling save_reduce().  Add a special hack for this.
The tests for this are much simpler now (no __getstate__ or
__getnewargs__ needed).


Index: pickletester.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/pickletester.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** pickletester.py	28 Jan 2003 17:55:05 -0000	1.25
--- pickletester.py	28 Jan 2003 19:48:18 -0000	1.26
***************
*** 302,342 ****
  
      def test_newobj_tuple(self):
!         x = MyTuple([1, 2, 3], foo=42, bar="hello")
          s = self.dumps(x, 2)
          y = self.loads(s)
          self.assertEqual(tuple(x), tuple(y))
          self.assertEqual(x.__dict__, y.__dict__)
  
      def test_newobj_list(self):
!         x = MyList([1, 2, 3], foo=42, bar="hello")
          s = self.dumps(x, 2)
          y = self.loads(s)
          self.assertEqual(list(x), list(y))
          self.assertEqual(x.__dict__, y.__dict__)
  
  class MyTuple(tuple):
!     def __new__(cls, *args, **kwds):
!         # Ignore **kwds
!         return tuple.__new__(cls, *args)
!     def __getnewargs__(self):
!         return (tuple(self),)
!     def __init__(self, *args, **kwds):
!         for k, v in kwds.items():
!             setattr(self, k, v)
  
  class MyList(list):
!     def __new__(cls, *args, **kwds):
!         # Ignore **kwds
!         return list.__new__(cls, *args)
!     def __init__(self, *args, **kwds):
!         for k, v in kwds.items():
!             setattr(self, k, v)
!     def __getstate__(self):
!         return list(self), self.__dict__
!     def __setstate__(self, arg):
!         lst, dct = arg
!         for x in lst:
!             self.append(x)
!         self.__init__(**dct)
  
  class AbstractPickleModuleTests(unittest.TestCase):
--- 302,333 ----
  
      def test_newobj_tuple(self):
!         x = MyTuple([1, 2, 3])
!         x.foo = 42
!         x.bar = "hello"
          s = self.dumps(x, 2)
          y = self.loads(s)
          self.assertEqual(tuple(x), tuple(y))
          self.assertEqual(x.__dict__, y.__dict__)
+ ##         import pickletools
+ ##         print
+ ##         pickletools.dis(s)
  
      def test_newobj_list(self):
!         x = MyList([1, 2, 3])
!         x.foo = 42
!         x.bar = "hello"
          s = self.dumps(x, 2)
          y = self.loads(s)
          self.assertEqual(list(x), list(y))
          self.assertEqual(x.__dict__, y.__dict__)
+ ##         import pickletools
+ ##         print
+ ##         pickletools.dis(s)
  
  class MyTuple(tuple):
!     pass
  
  class MyList(list):
!     pass
  
  class AbstractPickleModuleTests(unittest.TestCase):