[PyObjC-svn] r2227 - in trunk/pyobjc/pyobjc-core: . Lib/objc Lib/objc/test

[email protected] Thu, 21 May 2009 01:16:51 -0500
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Thu May 21 01:16:51 2009
New Revision: 2227

Log:
Fix the two remaining test failures in pyobjc-core. One was a genuine bug,
the other was an incorrect workaround for a Cocoa feature.


Modified:
   trunk/pyobjc/pyobjc-core/Lib/objc/_pycoder.py
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py
   trunk/pyobjc/pyobjc-core/NEWS.txt

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_pycoder.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_pycoder.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_pycoder.py	Thu May 21 01:16:51 2009
@@ -41,6 +41,7 @@
     kOP_LIST=11
     kOP_DICT=12
     kOP_GLOBAL_EXT=13
+    kOP_FLOAT_STR=14
 
     kKIND = NSString.stringWithString_(u"kind")
     kFUNC = NSString.stringWithString_(u"func")
@@ -133,8 +134,11 @@
     encode_dispatch[long] = save_long
 
     def save_float(coder, obj):
-        coder.encodeInt_forKey_(kOP_FLOAT, kKIND)
-        coder.encodeDouble_forKey_(obj, kVALUE)
+        # Encode floats as strings, this seems to be needed to get
+        # 100% reliable round-trips.
+        coder.encodeInt_forKey_(kOP_FLOAT_STR, kKIND)
+        coder.encodeObject_forKey_(unicode(repr(obj)), kVALUE)
+        #coder.encodeDouble_forKey_(obj, kVALUE)
     encode_dispatch[float] = save_float
 
     def save_string(coder, obj):
@@ -155,7 +159,6 @@
 
     def save_dict(coder, obj):
         coder.encodeInt_forKey_(kOP_DICT, kKIND)
-
         v = NSDictionary.dictionaryWithDictionary_(obj)
         coder.encodeObject_forKey_(v, kVALUE)
     encode_dispatch[dict] = save_dict
@@ -222,6 +225,10 @@
         return coder.decodeFloatForKey_(kVALUE)
     decode_dispatch[kOP_FLOAT] = load_float
 
+    def load_float_str(coder, setValue):
+        return float(coder.decodeObjectForKey_(kVALUE))
+    decode_dispatch[kOP_FLOAT_STR] = load_float_str
+
     def load_tuple(coder, setValue):
         return tuple(coder.decodeObjectForKey_(kVALUE))
     decode_dispatch[kOP_TUPLE] = load_tuple

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py	Thu May 21 01:16:51 2009
@@ -129,18 +129,19 @@
         else:
             self.assertEquals(OC_TestNumber.numberAsUnsignedLong_(v), 18446744073709551488)
 
-        # XXX: the next one is actually incorrect (as can be seen by the following C code,
-        # but is what NSNumber returns).
+        # The first entry in the tuple below is incorrect, that happens to be what
+        # is returned by NSNumber on some platforms (in particular, any Python where
+        # the python framework itself is linked against the 10.4 SDK)
         #
         #   double v = -127.6;
         #   unsigned long long lv = v;
         #   printf("%llu\n", lv);
+        # 
 
-        if int(os.uname()[2].split('.')[0]) == 8:
-            self.assertEquals(OC_TestNumber.numberAsUnsignedLongLong_(v), 18446744073709551489)
+        self.failUnless(
+                OC_TestNumber.numberAsUnsignedLongLong_(v) in 
+                    (18446744073709551489, 18446744073709551488))
 
-        else:
-            self.assertEquals(OC_TestNumber.numberAsUnsignedLongLong_(v), 18446744073709551488)
         self.assertEquals(OC_TestNumber.numberAsDouble_(v), -127.6)
 
         # Overflow

Modified: trunk/pyobjc/pyobjc-core/NEWS.txt
==============================================================================
--- trunk/pyobjc/pyobjc-core/NEWS.txt	(original)
+++ trunk/pyobjc/pyobjc-core/NEWS.txt	Thu May 21 01:16:51 2009
@@ -7,6 +7,14 @@
 Version 2.2 (...)
 -----------------
 
+- BUGFIX: Storing pure python objects in a ``NSKeydArchiver`` archive didn't 
+  work 100% reliably for Python floats. I've changed the implementation on 
+  for encoding floats a little and now floats do get rounddtripped properly.
+
+  The side effect of this is that archives written by PyObjC 2.2b2 or later
+  cannot always be read by earlier versions (but PyObjC 2.2b2 can read archives
+  created with earlier versions).
+
 - BUGFIX: Enable building from source with the Python.org binary distribution.
 
 - BUGFIX: Fix crash when using the animotor proxy feature of CoreAnimation. 

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com