1import objc 2import objc._objc 3from objc._protocols import PROTOCOL_CACHE 4from PyObjCTools.TestSupport import * 5 6class TestProtocols (TestCase): 7 def testBasic(self): 8 PROTOCOL_CACHE.clear() 9 p = objc.protocolNamed('NSObject') 10 self.assertIsInstance(p, objc.formal_protocol) 11 12 def testNoProtocol(self): 13 self.assertRaises(objc.ProtocolError, objc.protocolNamed, "PyObjCFooBarProtocol") 14 15 def testBasic2(self): 16 orig_protocolsForProcess = objc._objc.protocolsForProcess 17 try: 18 objc._objc.protocolsForProcess = lambda: [] 19 PROTOCOL_CACHE.clear() 20 21 p = objc.protocolNamed('NSObject') 22 self.assertIsInstance(p, objc.formal_protocol) 23 24 finally: 25 objc._objc.protocolsForProcess = orig_protocolsForProcess 26 27if __name__ == "__main__": 28 main() 29