[Python-checkins] python/dist/src/Lib/test test_datetime.py, 1.46, 1.47

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Mon Jun 7 19:05:03 EDT 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5714/Lib/test

Modified Files:
	test_datetime.py 
Log Message:
SF 952807:  Unpickling pickled instances of subclasses of datetime.date,
datetime.datetime and datetime.time could yield insane objects.  Thanks
to Jiwon Seo for the fix.

Bugfix candidate.  I'll backport it to 2.3.


Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_datetime.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** test_datetime.py	21 Mar 2004 23:38:41 -0000	1.46
--- test_datetime.py	7 Jun 2004 23:04:30 -0000	1.47
***************
*** 511,514 ****
--- 511,517 ----
          self.assertEqual(dt2, dt - days)
  
+ class SubclassDate(date):
+     sub_var = 1
+ 
  class TestDate(HarmlessMixedComparison):
      # Tests here should pass for both dates and datetimes, except for a
***************
*** 1030,1033 ****
--- 1033,1045 ----
          self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7)
  
+     def test_pickling_subclass_date(self):
+ 
+         args = 6, 7, 23
+         orig = SubclassDate(*args)
+         for pickler, unpickler, proto in pickle_choices:
+             green = pickler.dumps(orig, proto)
+             derived = unpickler.loads(green)
+             self.assertEqual(orig, derived)
+ 
      def test_backdoor_resistance(self):
          # For fast unpickling, the constructor accepts a pickle string.
***************
*** 1054,1057 ****
--- 1066,1072 ----
  # datetime tests
  
+ class SubclassDatetime(datetime):
+     sub_var = 1
+ 
  class TestDateTime(TestDate):
  
***************
*** 1297,1300 ****
--- 1312,1323 ----
          self.assertEqual(b.day, 7)
  
+     def test_pickling_subclass_datetime(self):
+         args = 6, 7, 23, 20, 59, 1, 64**2
+         orig = SubclassDatetime(*args)
+         for pickler, unpickler, proto in pickle_choices:
+             green = pickler.dumps(orig, proto)
+             derived = unpickler.loads(green)
+             self.assertEqual(orig, derived)
+ 
      def test_more_compare(self):
          # The test_compare() inherited from TestDate covers the error cases.
***************
*** 1501,1504 ****
--- 1524,1530 ----
                                            dt1.second - 7)
  
+ class SubclassTime(time):
+     sub_var = 1
+ 
  class TestTime(HarmlessMixedComparison):
  
***************
*** 1701,1704 ****
--- 1727,1738 ----
              self.assertEqual(orig, derived)
  
+     def test_pickling_subclass_time(self):
+         args = 20, 59, 16, 64**2
+         orig = SubclassTime(*args)
+         for pickler, unpickler, proto in pickle_choices:
+             green = pickler.dumps(orig, proto)
+             derived = unpickler.loads(green)
+             self.assertEqual(orig, derived)
+ 
      def test_bool(self):
          cls = self.theclass




More information about the Python-checkins mailing list