Commits

Ronald Oussoren committed b2ac4a6

* Slightly better testing for objc.protocolNamed (now 100% coverage according to coverage.py)

* Surpress some warnings during testing

Comments (0)

Files changed (3)

pyobjc-core/PyObjCTest/test_bridgesupport.py

             yield item
 
     def test_system_bridgesupport(self):
-        # Check that all system bridgesupport files can be processed correctly
-        for fn in self.iter_system_bridgesupport_files():
-            with open(fn, 'r') as fp:
-                xmldata = fp.read()
+        with filterWarnings("ignore", RuntimeWarning):
+            # Check that all system bridgesupport files can be processed correctly
+            for fn in self.iter_system_bridgesupport_files():
+                with open(fn, 'r') as fp:
+                    xmldata = fp.read()
 
-            self.assert_valid_bridgesupport(os.path.basename(fn).split('.')[0], xmldata)
+                self.assert_valid_bridgesupport(os.path.basename(fn).split('.')[0], xmldata)
 
 
 

pyobjc-core/PyObjCTest/test_descriptors.py

         self.assertRaises(TypeError, objc.namedSelector(b"foo:bar:", b"q@:qq"), 42)
 
     def testNamedselector(self):
-        @objc.namedselector(b'foo:bar:')
-        def mymethod(self, a, b):
-            pass
+        with filterWarnings("ignore", RuntimeWarning):
+            @objc.namedselector(b'foo:bar:')
+            def mymethod(self, a, b):
+                pass
 
-        self.assertIsInstance(mymethod, objc.selector)
-        self.assertEqual(mymethod.signature, b"v@:@@")
-        self.assertEqual(mymethod.selector, b"foo:bar:")
+            self.assertIsInstance(mymethod, objc.selector)
+            self.assertEqual(mymethod.signature, b"v@:@@")
+            self.assertEqual(mymethod.selector, b"foo:bar:")
 
-        self.assertRaises(TypeError, objc.namedselector(b"foo:bar:"), None)
-        self.assertRaises(TypeError, objc.namedselector(b"foo:bar:"), 42)
+            self.assertRaises(TypeError, objc.namedselector(b"foo:bar:"), None)
+            self.assertRaises(TypeError, objc.namedselector(b"foo:bar:"), 42)
 
-        @objc.namedselector(b'foo:bar:', signature=b"q@:qq")
-        def mymethod(self, a, b):
-            pass
+            @objc.namedselector(b'foo:bar:', signature=b"q@:qq")
+            def mymethod(self, a, b):
+                pass
 
-        self.assertIsInstance(mymethod, objc.selector)
-        self.assertEqual(mymethod.signature, b"q@:qq")
-        self.assertEqual(mymethod.selector, b"foo:bar:")
+            self.assertIsInstance(mymethod, objc.selector)
+            self.assertEqual(mymethod.signature, b"q@:qq")
+            self.assertEqual(mymethod.selector, b"foo:bar:")
 
-        self.assertRaises(TypeError, objc.namedselector(b"foo:bar:", b"q@:qq"), None)
-        self.assertRaises(TypeError, objc.namedselector(b"foo:bar:", b"q@:qq"), 42)
+            self.assertRaises(TypeError, objc.namedselector(b"foo:bar:", b"q@:qq"), None)
+            self.assertRaises(TypeError, objc.namedselector(b"foo:bar:", b"q@:qq"), 42)
 
     # synthesize is tested in test_synthesize
 
         self.assertEqual(validateColor_error_.signature, objc._C_NSBOOL + b'@:N^@o^@')
 
     def test_Accessor(self):
-        # NOTE: the optional type argument is tested through the typedAccessor function
+        with filterWarnings("ignore", DeprecationWarning):
+            # NOTE: the optional type argument is tested through the typedAccessor function
 
-        # Basic properties:
-        
-        @objc.Accessor
-        def color(self):
-            return 42
+            # Basic properties:
+            
+            @objc.Accessor
+            def color(self):
+                return 42
 
-        @objc.Accessor
-        def isColor(self):
-            return 42
+            @objc.Accessor
+            def isColor(self):
+                return 42
 
-        @objc.Accessor
-        def setColor_(self, value):
-            pass
+            @objc.Accessor
+            def setColor_(self, value):
+                pass
 
-        self.assertIsInstance(color, objc.selector)
-        self.assertIsInstance(isColor, objc.selector)
-        self.assertIsInstance(setColor_, objc.selector)
+            self.assertIsInstance(color, objc.selector)
+            self.assertIsInstance(isColor, objc.selector)
+            self.assertIsInstance(setColor_, objc.selector)
 
-        self.assertEqual(color.signature, b"@@:")
-        self.assertEqual(isColor.signature, b"@@:")
-        self.assertEqual(setColor_.signature, b"v@:@")
+            self.assertEqual(color.signature, b"@@:")
+            self.assertEqual(isColor.signature, b"@@:")
+            self.assertEqual(setColor_.signature, b"v@:@")
 
 
-        # Indexed accessors
+            # Indexed accessors
 
-        @objc.Accessor
-        def countOfFlavors(self):
-            return 2
+            @objc.Accessor
+            def countOfFlavors(self):
+                return 2
 
-        @objc.Accessor
-        def objectInFlavorsAtIndex_(self, idx):
-            return "sour"
+            @objc.Accessor
+            def objectInFlavorsAtIndex_(self, idx):
+                return "sour"
 
-        @objc.Accessor
-        def flavorsAtIndexes_(sef, indices):
-            return ["sour", "sweet"]
+            @objc.Accessor
+            def flavorsAtIndexes_(sef, indices):
+                return ["sour", "sweet"]
 
-        @objc.Accessor
-        def getFlavors_range_(self, buffer, range):
-            return ["sour", "sweet"]
+            @objc.Accessor
+            def getFlavors_range_(self, buffer, range):
+                return ["sour", "sweet"]
 
 
-        self.assertIsInstance(countOfFlavors, objc.selector)
-        self.assertIsInstance(objectInFlavorsAtIndex_, objc.selector)
-        self.assertIsInstance(flavorsAtIndexes_, objc.selector)
-        self.assertIsInstance(getFlavors_range_, objc.selector)
+            self.assertIsInstance(countOfFlavors, objc.selector)
+            self.assertIsInstance(objectInFlavorsAtIndex_, objc.selector)
+            self.assertIsInstance(flavorsAtIndexes_, objc.selector)
+            self.assertIsInstance(getFlavors_range_, objc.selector)
 
-        self.assertEqual(countOfFlavors.signature, objc._C_NSUInteger + b"@:")
-        self.assertEqual(objectInFlavorsAtIndex_.signature, b"@@:" + objc._C_NSUInteger)
-        self.assertEqual(flavorsAtIndexes_.signature, b"@@:@")
+            self.assertEqual(countOfFlavors.signature, objc._C_NSUInteger + b"@:")
+            self.assertEqual(objectInFlavorsAtIndex_.signature, b"@@:" + objc._C_NSUInteger)
+            self.assertEqual(flavorsAtIndexes_.signature, b"@@:@")
 
-        # XXX: This needs even more work: also have to add custom metadata!
-        self.assertEqual(getFlavors_range_.signature, b"v@:o^@" + _C_NSRange)
+            # XXX: This needs even more work: also have to add custom metadata!
+            self.assertEqual(getFlavors_range_.signature, b"v@:o^@" + _C_NSRange)
 
-        # Mutable Indexed Accessors
+            # Mutable Indexed Accessors
 
-        @objc.Accessor
-        def insertObject_inFlavorsAtIndex_(self, value, idx):
-            pass
+            @objc.Accessor
+            def insertObject_inFlavorsAtIndex_(self, value, idx):
+                pass
 
-        @objc.Accessor
-        def insertFlavors_atIndexes_(self, values, indices):
-            pass
+            @objc.Accessor
+            def insertFlavors_atIndexes_(self, values, indices):
+                pass
 
-        @objc.Accessor
-        def removeObjectFromFlavorsAtIndex_(self, index):
-            pass
+            @objc.Accessor
+            def removeObjectFromFlavorsAtIndex_(self, index):
+                pass
 
-        @objc.Accessor
-        def removeFlavorsAtIndexes_(self, indices):
-            pass
+            @objc.Accessor
+            def removeFlavorsAtIndexes_(self, indices):
+                pass
 
-        @objc.Accessor
-        def replaceObjectInFlavorsAtIndex_withObject_(self, value, idx):
-            pass
+            @objc.Accessor
+            def replaceObjectInFlavorsAtIndex_withObject_(self, value, idx):
+                pass
 
-        @objc.Accessor
-        def replaceFlavorsAtIndexes_withFlavors_(self, indices, values):
-            pass
+            @objc.Accessor
+            def replaceFlavorsAtIndexes_withFlavors_(self, indices, values):
+                pass
 
 
-        self.assertIsInstance(insertObject_inFlavorsAtIndex_, objc.selector)
-        self.assertIsInstance(insertFlavors_atIndexes_, objc.selector)
-        self.assertIsInstance(removeObjectFromFlavorsAtIndex_, objc.selector)
-        self.assertIsInstance(removeFlavorsAtIndexes_, objc.selector)
-        self.assertIsInstance(replaceObjectInFlavorsAtIndex_withObject_, objc.selector)
-        self.assertIsInstance(replaceFlavorsAtIndexes_withFlavors_, objc.selector)
+            self.assertIsInstance(insertObject_inFlavorsAtIndex_, objc.selector)
+            self.assertIsInstance(insertFlavors_atIndexes_, objc.selector)
+            self.assertIsInstance(removeObjectFromFlavorsAtIndex_, objc.selector)
+            self.assertIsInstance(removeFlavorsAtIndexes_, objc.selector)
+            self.assertIsInstance(replaceObjectInFlavorsAtIndex_withObject_, objc.selector)
+            self.assertIsInstance(replaceFlavorsAtIndexes_withFlavors_, objc.selector)
 
-        self.assertEqual(insertObject_inFlavorsAtIndex_.signature, b"v@:@" + objc._C_NSUInteger)
-        self.assertEqual(insertFlavors_atIndexes_.signature, b"v@:@@")
-        self.assertEqual(removeObjectFromFlavorsAtIndex_.signature, b"v@:" + objc._C_NSUInteger)
-        self.assertEqual(removeFlavorsAtIndexes_.signature, b"v@:@")
-        self.assertEqual(replaceObjectInFlavorsAtIndex_withObject_.signature, b"v@:" + objc._C_NSUInteger + b"@")
-        self.assertEqual(replaceFlavorsAtIndexes_withFlavors_.signature, b"v@:@@")
+            self.assertEqual(insertObject_inFlavorsAtIndex_.signature, b"v@:@" + objc._C_NSUInteger)
+            self.assertEqual(insertFlavors_atIndexes_.signature, b"v@:@@")
+            self.assertEqual(removeObjectFromFlavorsAtIndex_.signature, b"v@:" + objc._C_NSUInteger)
+            self.assertEqual(removeFlavorsAtIndexes_.signature, b"v@:@")
+            self.assertEqual(replaceObjectInFlavorsAtIndex_withObject_.signature, b"v@:" + objc._C_NSUInteger + b"@")
+            self.assertEqual(replaceFlavorsAtIndexes_withFlavors_.signature, b"v@:@@")
 
 
-        # Getter Unordered Accessors
-        @objc.Accessor
-        def countOfLanguages(self):
-            pass
+            # Getter Unordered Accessors
+            @objc.Accessor
+            def countOfLanguages(self):
+                pass
 
-        @objc.Accessor
-        def enumeratorOfLanguages(self):
-            pass
+            @objc.Accessor
+            def enumeratorOfLanguages(self):
+                pass
 
-        @objc.Accessor
-        def memberOfLanguages_(self, value):
-            return False
+            @objc.Accessor
+            def memberOfLanguages_(self, value):
+                return False
 
-        self.assertIsInstance(countOfLanguages, objc.selector)
-        self.assertIsInstance(enumeratorOfLanguages, objc.selector)
-        self.assertIsInstance(memberOfLanguages_, objc.selector)
+            self.assertIsInstance(countOfLanguages, objc.selector)
+            self.assertIsInstance(enumeratorOfLanguages, objc.selector)
+            self.assertIsInstance(memberOfLanguages_, objc.selector)
 
-        self.assertEqual(countOfLanguages.signature, objc._C_NSUInteger + b"@:")
-        self.assertEqual(enumeratorOfLanguages.signature, b"@@:")
-        self.assertEqual(memberOfLanguages_.signature, objc._C_NSBOOL + b"@:@")
+            self.assertEqual(countOfLanguages.signature, objc._C_NSUInteger + b"@:")
+            self.assertEqual(enumeratorOfLanguages.signature, b"@@:")
+            self.assertEqual(memberOfLanguages_.signature, objc._C_NSBOOL + b"@:@")
 
-        # Mutable Unordered Accessors
-        
-        @objc.Accessor
-        def addLanguagesObject_(self, value):
-            pass
+            # Mutable Unordered Accessors
+            
+            @objc.Accessor
+            def addLanguagesObject_(self, value):
+                pass
 
-        @objc.Accessor
-        def addLanguagues_(self, values):
-            pass
+            @objc.Accessor
+            def addLanguagues_(self, values):
+                pass
 
-        @objc.Accessor
-        def intersectLanguagues_(self, values):
-            pass
+            @objc.Accessor
+            def intersectLanguagues_(self, values):
+                pass
 
-        self.assertIsInstance(addLanguagesObject_, objc.selector)
-        self.assertIsInstance(addLanguagues_, objc.selector)
-        self.assertIsInstance(intersectLanguagues_, objc.selector)
+            self.assertIsInstance(addLanguagesObject_, objc.selector)
+            self.assertIsInstance(addLanguagues_, objc.selector)
+            self.assertIsInstance(intersectLanguagues_, objc.selector)
 
-        self.assertEqual(addLanguagesObject_.signature, b"v@:@")
-        self.assertEqual(addLanguagues_.signature, b"v@:@")
-        self.assertEqual(intersectLanguagues_.signature, b"v@:@")
+            self.assertEqual(addLanguagesObject_.signature, b"v@:@")
+            self.assertEqual(addLanguagues_.signature, b"v@:@")
+            self.assertEqual(intersectLanguagues_.signature, b"v@:@")
 
-        # Validation
-        @objc.Accessor
-        def validateColor_error_(self, value, error):
-            return (False, None)
+            # Validation
+            @objc.Accessor
+            def validateColor_error_(self, value, error):
+                return (False, None)
 
-        self.assertIsInstance(validateColor_error_, objc.selector)
-        self.assertEqual(validateColor_error_.signature, objc._C_NSBOOL + b'@:N^@o^@')
+            self.assertIsInstance(validateColor_error_, objc.selector)
+            self.assertEqual(validateColor_error_.signature, objc._C_NSBOOL + b'@:N^@o^@')
 
 
 
-        # Keyword arguments (**kwds) and varargs (*args) are
-        # not supported:
+            # Keyword arguments (**kwds) and varargs (*args) are
+            # not supported:
 
-        def attrib(self, *args):
-            pass
-        self.assertRaises(TypeError, objc.Accessor, attrib)
+            def attrib(self, *args):
+                pass
+            self.assertRaises(TypeError, objc.Accessor, attrib)
 
-        def attrib(self, **kwds):
-            pass
-        self.assertRaises(TypeError, objc.Accessor, attrib)
+            def attrib(self, **kwds):
+                pass
+            self.assertRaises(TypeError, objc.Accessor, attrib)
 
-        # Not really an accessor
-        def attrib_error_(self, a, b):
-            pass
-        self.assertRaises(TypeError, objc.Accessor, attrib_error_)
+            # Not really an accessor
+            def attrib_error_(self, a, b):
+                pass
+            self.assertRaises(TypeError, objc.Accessor, attrib_error_)
 
-        # Argument counts that don't match
-        def validateObject_error_(self, a):
-            pass
-        self.assertRaises(TypeError, objc.Accessor, validateObject_error_)
+            # Argument counts that don't match
+            def validateObject_error_(self, a):
+                pass
+            self.assertRaises(TypeError, objc.Accessor, validateObject_error_)
 
-        def validateObject_error_(self, a, b, c):
-            pass
-        self.assertRaises(TypeError, objc.Accessor, validateObject_error_)
+            def validateObject_error_(self, a, b, c):
+                pass
+            self.assertRaises(TypeError, objc.Accessor, validateObject_error_)
 
-        def validateObject_error_(self, a, b, c, d=1, e=2):
-            pass
-        self.assertRaises(TypeError, objc.Accessor, validateObject_error_)
+            def validateObject_error_(self, a, b, c, d=1, e=2):
+                pass
+            self.assertRaises(TypeError, objc.Accessor, validateObject_error_)
 
-        @objc.Accessor
-        def validateObject_error_(self, a, b, c=1):
-            pass
+            @objc.Accessor
+            def validateObject_error_(self, a, b, c=1):
+                pass
 
 
 if __name__ == "__main__":

pyobjc-core/PyObjCTest/test_protocolNamed.py

 import objc
+import objc._objc
+from objc._protocols import PROTOCOL_CACHE
 from PyObjCTools.TestSupport import *
 
 class TestProtocols (TestCase):
     def testBasic(self):
+        PROTOCOL_CACHE.clear()
         p = objc.protocolNamed('NSObject')
         self.assertIsInstance(p, objc.formal_protocol)
 
     def testNoProtocol(self):
         self.assertRaises(objc.ProtocolError, objc.protocolNamed, "PyObjCFooBarProtocol")
 
+    def testBasic2(self):
+        orig_protocolsForProcess = objc._objc.protocolsForProcess
+        try:
+            objc._objc.protocolsForProcess = lambda: []
+            PROTOCOL_CACHE.clear()
+
+            p = objc.protocolNamed('NSObject')
+            self.assertIsInstance(p, objc.formal_protocol)
+
+        finally:
+            objc._objc.protocolsForProcess = orig_protocolsForProcess
+
 if __name__ == "__main__":
     main()