1. Ronald Oussoren
  2. pyobjc

Commits

Ronald Oussoren  committed 11a5499

Add testcase that illustrates problem with NSNumber -> Python number
conversion in combination with property lists. This test passes in my
tree when using Python 2.3, but not with Python 2.2 (which doesn't have
a proper boolean type)

  • Participants
  • Parent commits d696cdc
  • Branches default

Comments (0)

Files changed (1)

File pyobjc/Lib/Foundation/test/test_nsnumber.py

View file
                 self.assertEquals(NSNumber.numberWithInt_(0), 0)
                 self.assertEquals(NSNumber.numberWithFloat_(0.0), 0,0)
             
+    PLIST="""\
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>bool</key>
+	<true/>
+	<key>plain</key>
+	<integer>1</integer>
+</dict>
+</plist>
+"""
+
+    class TestPropList (unittest.TestCase):
+        """
+        Test if numbers are stored properly in property-list. The most 
+        important part of the testcase are boolean values.
+        """
+
+        def testPropertyList1(self):
+            d = NSMutableDictionary.dictionary()
+
+            # Python 2.3 only...
+            d['plain'] = 1
+            d['bool'] = objc.YES
+
+            self.assertEquals(d.writeToFile_atomically_(
+                "/tmp/pyobjctest.plist", 0), 1)
+            
+            fd = open('/tmp/pyobjctest.plist', 'ru')
+            data = fd.read()
+            fd.close()
+
+            self.assertEquals(data, PLIST)
+
+        def testPropertyList1(self):
+            d = NSMutableDictionary.dictionary()
+
+            d['plain'] = NSNumber.numberWithLong_(1)
+            d['bool'] = NSNumber.numberWithBool_(1)
+
+            self.assertEquals(d.writeToFile_atomically_(
+                "/tmp/pyobjctest.plist", 0), 1)
+            
+            fd = open('/tmp/pyobjctest.plist', 'ru')
+            data = fd.read()
+            fd.close()
+
+            self.assertEquals(data, PLIST)
 
 def suite():
     suite = unittest.TestSuite()