[Zope3-checkins] CVS: Zope3/lib/python/datetime/tests - test_datetime.py:1.3

Tim Peters tim.one@comcast.net
Sat, 21 Dec 2002 00:10:44 -0500


Update of /cvs-repository/Zope3/lib/python/datetime/tests
In directory cvs.zope.org:/tmp/cvs-serv20074/lib/python/datetime/tests

Modified Files:
	test_datetime.py 
Log Message:
Changes sufficient so that pickles written by the Python implementation
can be read by the C implementation.  I don't really understand this.

Added the large, but unreviewed & plain-text, doc file from the Python
CVS sandbox.

The docs have changed to note the new requirement that tzinfo subclasses
have _an _init__ method that can be called with no arguments.  They may
also need a __safe_for_unpickling__ magic attr, but that can be added to
a class later (it seems), and I hope won't be needed by the time Python
2.3 is real.


=== Zope3/lib/python/datetime/tests/test_datetime.py 1.2 => 1.3 ===
--- Zope3/lib/python/datetime/tests/test_datetime.py:1.2	Fri Dec 20 17:30:38 2002
+++ Zope3/lib/python/datetime/tests/test_datetime.py	Sat Dec 21 00:10:43 2002
@@ -51,6 +51,10 @@
     def dst(self, dt):
         return self.__dstoffset
 
+class PicklableFixedOffset(FixedOffset):
+    def __init__(self, offset=None, name=None, dstoffset=None):
+        FixedOffset.__init__(self, offset, name, dstoffset)
+
 class TestTZInfo(unittest.TestCase):
 
     def test_non_abstractness(self):
@@ -103,9 +107,9 @@
         import pickle, cPickle
 
         # Make sure we can pickle/unpickle an instance of a subclass.
-        orig = FixedOffset(-300, 'cookie')
+        orig = PicklableFixedOffset(-300, 'cookie')
         self.failUnless(isinstance(orig, tzinfo))
-        self.failUnless(type(orig) is FixedOffset)
+        self.failUnless(type(orig) is PicklableFixedOffset)
         self.assertEqual(orig.utcoffset(None), -300)
         self.assertEqual(orig.tzname(None), 'cookie')
         for pickler in pickle, cPickle:
@@ -113,7 +117,7 @@
                 green = pickler.dumps(orig, binary)
                 derived = pickler.loads(green)
                 self.failUnless(isinstance(derived, tzinfo))
-                self.failUnless(type(derived) is FixedOffset)
+                self.failUnless(type(derived) is PicklableFixedOffset)
                 self.assertEqual(derived.utcoffset(None), -300)
                 self.assertEqual(derived.tzname(None), 'cookie')
 
@@ -1614,13 +1618,13 @@
                 self.assertEqual(orig, derived)
 
         # Try one with a tzinfo.
-        tinfo = FixedOffset(-300, 'cookie')
+        tinfo = PicklableFixedOffset(-300, 'cookie')
         orig = self.theclass(5, 6, 7, tzinfo=tinfo)
         state = orig.__getstate__()
         derived = self.theclass()
         derived.__setstate__(state)
         self.assertEqual(orig, derived)
-        self.failUnless(isinstance(derived.tzinfo, FixedOffset))
+        self.failUnless(isinstance(derived.tzinfo, PicklableFixedOffset))
         self.assertEqual(derived.utcoffset(), -300)
         self.assertEqual(derived.tzname(), 'cookie')
 
@@ -1629,7 +1633,8 @@
                 green = pickler.dumps(orig, binary)
                 derived = pickler.loads(green)
                 self.assertEqual(orig, derived)
-                self.failUnless(isinstance(derived.tzinfo, FixedOffset))
+                self.failUnless(isinstance(derived.tzinfo,
+                                PicklableFixedOffset))
                 self.assertEqual(derived.utcoffset(), -300)
                 self.assertEqual(derived.tzname(), 'cookie')
 
@@ -1775,13 +1780,13 @@
                 self.assertEqual(orig, derived)
 
         # Try one with a tzinfo.
-        tinfo = FixedOffset(-300, 'cookie')
+        tinfo = PicklableFixedOffset(-300, 'cookie')
         orig = self.theclass(*args, **{'tzinfo': tinfo})
         state = orig.__getstate__()
         derived = self.theclass(1, 1, 1)
         derived.__setstate__(state)
         self.assertEqual(orig, derived)
-        self.failUnless(isinstance(derived.tzinfo, FixedOffset))
+        self.failUnless(isinstance(derived.tzinfo, PicklableFixedOffset))
         self.assertEqual(derived.utcoffset(), -300)
         self.assertEqual(derived.tzname(), 'cookie')
 
@@ -1790,7 +1795,8 @@
                 green = pickler.dumps(orig, binary)
                 derived = pickler.loads(green)
                 self.assertEqual(orig, derived)
-                self.failUnless(isinstance(derived.tzinfo, FixedOffset))
+                self.failUnless(isinstance(derived.tzinfo,
+                                PicklableFixedOffset))
                 self.assertEqual(derived.utcoffset(), -300)
                 self.assertEqual(derived.tzname(), 'cookie')