[Zope3-checkins] SVN: Zope3/trunk/src/zope/xmlpickle/tests/test_xmlpickle.py Fix Python 2.4 compatibility.

Fred L. Drake, Jr. fred at zope.com
Wed Jun 23 16:56:44 EDT 2004


Log message for revision 25965:
Fix Python 2.4 compatibility.
Merged from revision 25961 on the ZopeX3-3.0 branch.

Python 2.4 doesn't support the comparison of recursive objects, so we
have to implement the test of pickling/unpickling recursive objects
differently.



-=-
Modified: Zope3/trunk/src/zope/xmlpickle/tests/test_xmlpickle.py
===================================================================
--- Zope3/trunk/src/zope/xmlpickle/tests/test_xmlpickle.py	2004-06-23 20:45:43 UTC (rev 25964)
+++ Zope3/trunk/src/zope/xmlpickle/tests/test_xmlpickle.py	2004-06-23 20:56:44 UTC (rev 25965)
@@ -15,7 +15,7 @@
 
 $Id$
 """
-
+import pickle
 import unittest
 from zope.xmlpickle import dumps, loads
 
@@ -218,14 +218,28 @@
         self.__test(complex(1,2))
 
     def test_cycles(self):
+        # Python 2.4 does not support recursive comparisons to the
+        # same extent as Python 2.3, so we test these recursive
+        # structures by comparing the standard pickles of the original
+        # and pickled/unpickled copy.  This works for things like
+        # lists and tuples, but could easily break for dictionaries.
+
         l = [1, 2 , 3]
         l.append(l)
-        self.__test(l)
+        xml = dumps(l)
+        newl = loads(xml)
+        p1 = pickle.dumps(l)
+        p2 = pickle.dumps(newl)
+        self.assertEqual(p1, p2)
+
         t = l, l
         l.append(t)
-        self.__test(l)
+        xml = dumps(l)
+        newl = loads(xml)
+        p1 = pickle.dumps(l)
+        p2 = pickle.dumps(newl)
+        self.assertEqual(p1, p2)
 
-
     def test_list(self):
         self.__test([])
         self.__test([1,2,3])



More information about the Zope3-Checkins mailing list