[Python-checkins] python/dist/src/Lib/test pickletester.py,1.29,1.30 test_pickle.py,1.14,1.15

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 29 Jan 2003 09:58:46 -0800


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

Modified Files:
	pickletester.py test_pickle.py 
Log Message:
Implement appropriate __getnewargs__ for all immutable subclassable builtin
types.  The special handling for these can now be removed from save_newobj().
Add some testing for this.

Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.

Index: pickletester.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/pickletester.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** pickletester.py	29 Jan 2003 06:12:46 -0000	1.29
--- pickletester.py	29 Jan 2003 17:58:44 -0000	1.30
***************
*** 325,328 ****
--- 325,343 ----
  ##         pickletools.dis(s)
  
+     def test_newobj_generic(self):
+         for proto in [0, 1, 2]:
+             for C in myclasses:
+                 B = C.__base__
+                 x = C(C.sample)
+                 x.foo = 42
+                 s = self.dumps(x, proto)
+ ##                import pickletools
+ ##                print
+ ##                pickletools.dis(s)
+                 y = self.loads(s)
+                 detail = (proto, C, B, x, y, type(y))
+                 self.assertEqual(B(x), B(y), detail)
+                 self.assertEqual(x.__dict__, y.__dict__, detail)
+ 
  # XXX Temporary hack, so long as the C implementation of pickle protocol
  # XXX 2 isn't ready.  When it is, move the methods in TempAbstractPickleTests
***************
*** 406,414 ****
              copy_reg.remove_extension(__name__, "MyList", 0xfffff0)
  
  class MyTuple(tuple):
!     pass
  
  class MyList(list):
!     pass
  
  class SlotList(MyList):
--- 421,456 ----
              copy_reg.remove_extension(__name__, "MyList", 0xfffff0)
  
+ class MyInt(int):
+     sample = 1
+ 
+ class MyLong(long):
+     sample = 1L
+ 
+ class MyFloat(float):
+     sample = 1.0
+ 
+ class MyComplex(complex):
+     sample = 1.0 + 0.0j
+ 
+ class MyStr(str):
+     sample = "hello"
+ 
+ class MyUnicode(unicode):
+     sample = u"hello \u1234"
+ 
  class MyTuple(tuple):
!     sample = (1, 2, 3)
  
  class MyList(list):
!     sample = [1, 2, 3]
! 
! class MyDict(dict):
!     sample = {"a": 1, "b": 2}
! 
! myclasses = [MyInt, MyLong, MyFloat,
!              # MyComplex, # XXX complex somehow doesn't work here :-(
!              MyStr, MyUnicode,
!              MyTuple, MyList, MyDict]
! 
  
  class SlotList(MyList):

Index: test_pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pickle.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_pickle.py	28 Jan 2003 22:34:11 -0000	1.14
--- test_pickle.py	29 Jan 2003 17:58:44 -0000	1.15
***************
*** 12,18 ****
  class PickleTests(AbstractPickleTests, AbstractPickleModuleTests, XXXTemp):
  
!     def setUp(self):
!         self.dumps = pickle.dumps
!         self.loads = pickle.loads
  
      module = pickle
--- 12,22 ----
  class PickleTests(AbstractPickleTests, AbstractPickleModuleTests, XXXTemp):
  
!     def dumps(self, arg, proto=0, fast=0):
!         # Ignore fast
!         return pickle.dumps(arg, proto)
! 
!     def loads(self, buf):
!         # Ignore fast
!         return pickle.loads(buf)
  
      module = pickle
***************
*** 23,29 ****
      error = KeyError
  
!     def dumps(self, arg, proto=0):
          f = StringIO()
          p = pickle.Pickler(f, proto)
          p.dump(arg)
          f.seek(0)
--- 27,35 ----
      error = KeyError
  
!     def dumps(self, arg, proto=0, fast=0):
          f = StringIO()
          p = pickle.Pickler(f, proto)
+         if fast:
+             p.fast = fast
          p.dump(arg)
          f.seek(0)
***************
*** 37,41 ****
  class PersPicklerTests(AbstractPersistentPicklerTests):
  
!     def dumps(self, arg, proto=0):
          class PersPickler(pickle.Pickler):
              def persistent_id(subself, obj):
--- 43,47 ----
  class PersPicklerTests(AbstractPersistentPicklerTests):
  
!     def dumps(self, arg, proto=0, fast=0):
          class PersPickler(pickle.Pickler):
              def persistent_id(subself, obj):
***************
*** 43,46 ****
--- 49,54 ----
          f = StringIO()
          p = PersPickler(f, proto)
+         if fast:
+             p.fast = fast
          p.dump(arg)
          f.seek(0)