Commits

Ronald Oussoren  committed 074671f

- Fix PyArg_Parse... bug for the 10.1 specific files (I haven't check if
this compiles on a 10.1 box)
- Enhance the new test_methods2.py file: Also test calls from objective-C
to python. Calls from Objective-C that use pass-by-reference _C_IN arguments
don't work correctly (yet).
- Move using-nsscanner to the unittests: test_nsscanner.py
- Make 'forwardInvocation:' of python classes use the same logic as the
stub-function in the method table of the Objective-C class

  • Participants
  • Parent commits 4390a8e

Comments (0)

Files changed (9)

File pyobjc/Examples/using-nsscanner.py

-#
-# Using NSScanner. This demonstrates pass-by-reference output parameters
-#
-# TODO: Create a real (more usefull) example out of this.
-#
-# 
-
-from Foundation import NSScanner
-
-obj = NSScanner.scannerWithString_(u"1.2 2.4")
-converted, value =  obj.scanDouble_()
-print 'converted: %d, value: %s'%(converted, value)
-converted, value =  obj.scanFloat_()
-print 'converted: %d, value: %s'%(converted, value)
-print 'obj.retainCount:', obj.retainCount()

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

+import unittest
+import objc
+
+from Foundation import *
+
+class TestNSScannerUsage(unittest.TestCase):
+
+    # Python 2.2 doesn't have this one:
+    def assertAlmostEquals(self, val1, val2, message=None):
+        self.assert_ (abs (val1 - val2) < 0.00001, message)
+
+    def testUsage(self):
+        obj = NSScanner.scannerWithString_("1.2 2.4")
+
+        didConvert, value = obj.scanDouble_()
+        self.assert_(didConvert)
+        self.assertAlmostEquals(value, 1.2)
+
+        didConvert, value = obj.scanFloat_()
+        self.assert_(didConvert)
+        self.assertAlmostEquals(value, 2.4)
+
+if __name__ == '__main__':
+    unittest.main( )