Commits

Ronald Oussoren committed 3beb73f

- Add unittest for calling methods on unitialized objects
- Swallow warnings in the test of the methods in our category on
NSAutoreleasePool. This makes the output of the unittests nicer.

Comments (0)

Files changed (2)

pyobjc/Lib/Foundation/test/test_nsautoreleasepool.py

 from Foundation import *
 
 class TestNSAutoreleasePoolInteraction(unittest.TestCase):
+
     def testNSAutoreleasePoolPlain(self):
         pool = NSAutoreleasePool.alloc().init()
         bar = NSMutableArray.array()
         bar.addObject_( "a" ) # should still exist because of python GC
 
     def testNSAutoreleasePool(self):
-        NSAutoreleasePool.pyobjcPushPool()
-        bar = NSMutableArray.array()
-        NSAutoreleasePool.pyobjcPopPool()
-        bar.addObject_( "a" ) # should still exist because of python GC
+
+        # The actual test will issue a DeprecationWarning, the warnings code
+        # below surpresses that warning.
+        import warnings
+        warnings.simplefilter('ignore', category=DeprecationWarning)
+        try:
+            NSAutoreleasePool.pyobjcPushPool()
+            bar = NSMutableArray.array()
+            NSAutoreleasePool.pyobjcPopPool()
+            bar.addObject_( "a" ) # should still exist because of python GC
+        finally:
+            del warnings.filters[0]
 
 if __name__ == '__main__':
     unittest.main( )

pyobjc/Lib/objc/test/test_regr.py

         self.assertRaises(TypeError, fm.stringWithFileSystemRepresentation_length_, "/var")
         self.assertEquals(u"/var", fm.stringWithFileSystemRepresentation_length_("/var/boo", 4))
 
+    def testUninitWarning(self):
+        """
+        Check that calling methods on unitialized objects raises an error
+        """
+        import warnings
+        import Foundation
+
+        o = Foundation.NSObject.alloc() # Not yet initialized
+        warnings.simplefilter('error', RuntimeWarning)
+        try:
+            self.assertRaises(RuntimeWarning, o.description)
+        finally:
+            del warnings.filters[0]
+
 if __name__ == '__main__':
     unittest.main()