Commits

Anonymous committed 2452de8

added Foundation tests. moved some from objc to Foundation.

Comments (0)

Files changed (4)

 2002-10-22  Bill Bumgarner  <bbum@codefab.com>
+	* Updated objc unit tests a bit.
+	* Added Foundation unit tests.
+	* Moved a number of tests from objc -> Foundation.
+
 	* Updated the MANIFEST (too bad we can't effectively use MANIFEST.in)
 	* Slight correction/addition to setup.py
 

pyobjc/Lib/Foundation/test/test_subclassing.py

+import unittest
+import objc
+
+from Foundation import *
+
+class TestSubclassing( unittest.TestCase ):
+    def testBasicSubclassing( self ):
+        class NSObjectSubclass( NSObject ):
+            def someRandomMethod(self):
+                return 42
+
+        subclassClass = NSClassFromString( "NSObjectSubclass" )
+
+        self.assert_( subclassClass , "Failed to subclass NSObject." )
+
+        subclassInstance = subclassClass.new()
+        self.assert_( isinstance( subclassInstance, subclassClass ), "Subclass instance was not an instance of NSObjectSubclass." )
+        self.assert_( isinstance( subclassInstance, NSObject ), "Subclass instance was not a subclass of NSObject." )
+        self.assert_( not isinstance( subclassInstance, NSArray ), "Not a subclass of NSArray, but instanceof() thinks so." )
+
+        subclassInstance.description()
+        self.assert_( subclassInstance.someRandomMethod() == 42, "someRandomMethod() did not return expected response." )
+
+        self.assert_( subclassInstance is subclassInstance, "Identity check failed." )
+        self.assert_( subclassInstance is subclassInstance.self(), "Identity check failed." )
+    
+
+class TestNSObjectInteraction( unittest.TestCase ):
+    def testNSObjectClass( self ):
+        self.assert_( NSObject.instancesRespondToSelector_( "description" ), "NSObject class claims it doesn't respond to a selector that it does." )
+        # self.assert_( NSObject.description(), "NSObject class failed to respond to +description selector." )
+
+    def testNSObjectInstance( self ):
+        instance = NSObject.new()
+
+        self.assert_( instance, "Failed to instantiate an instance" )
+        self.assert_( instance.description(), "NSObject instance didn't respond to -description selector." )
+        self.assert_( not instance.isProxy(), "Instance of NSObject claimed it was a proxy.   That seems odd." )
+        self.assert_( isinstance( instance, objc.runtime.NSObject ), "Instantiated object not an instance of NSObject." )
+        self.assert_( instance == instance, "Python identity check failed." )
+        self.assert_( instance.isEqual_( instance ), "Obj-C identity check failed." )
+        
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest( unittest.makeSuite( TestNSObjectInteraction ) )
+    suite.addTest( unittest.makeSuite( TestSubclassing ) )
+    return suite
+
+if __name__ == '__main__':
+    unittest.main( )

pyobjc/Lib/objc/test/test_objc.py

 
 import objc
 
-class TestBOOL(unittest.TestCase):
+class TestConstants(unittest.TestCase):
     def testBooleans(self):
         self.assert_( objc.YES, "YES was not true." )
         self.assert_( not objc.NO, "NO was true." )
+
+    def testNil(self):
+        from types import NoneType
+        self.assert_( not objc.nil, "nil is not nil/None." )
     
 class TestClassLookup(unittest.TestCase):
     def testLookupClassNoSuchClassErrorRaised(self):
         self.assert_( objc.runtime.NSException in objc.class_list(), "class_list() does not appear to contain NSException class" )
         self.assert_( objc.runtime.NSMutableArray in objc.class_list(), "class_list() does not appear to contain NSMutableArray class" )
 
-class TestObjectInstantiation(unittest.TestCase):
-    def testInstantiation(self):
-        anInstance = objc.runtime.NSObject.new()
-        self.assert_( anInstance, "Failed to instantiate an instance" )
-        self.assert_( isinstance( anInstance, objc.runtime.NSObject ), "Instantiated object not an instance of NSObject." )
-        self.assert_( anInstance.isEqual_( anInstance ), "Instance !isEqual: to itself." )
-
 class TestMethodInvocation(unittest.TestCase):
     def setUp(self):
         self.NSObjectInstance = objc.runtime.NSObject.alloc()
 
 def suite():
     suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( TestBOOL ) )
+    suite.addTest( unittest.makeSuite( TestConstants ) )
     suite.addTest( unittest.makeSuite( TestClassLookup ) )
-    suite.addTest( unittest.makeSuite( TestObjectInstantiation ) )
     suite.addTest( unittest.makeSuite( TestMethodInvocation ) )
     return suite
 
 		   ],
 		   extra_link_args=[
 			'-g', '-framework', 'AppKit'
-		   ]),
+		   ])
 	]
 CocoaPackages = [ 'Foundation', 'AppKit' ]
 CocoaExtensions = [