1from PyObjCTools.TestSupport import * 2import objc 3 4class TestPython3Types (TestCase): 5 # Add tests here for all metadata and function arguments (when py3k and py2 6 # behaviour is different) 7 8 def testSelectorArguments(self): 9 self.assertRaises(TypeError, objc.selector, "hello", signature=b"v@:") 10 self.assertRaises(TypeError, objc.selector, b"hello", signature="v@:") 11 12 def testSelectorAttributes(self): 13 o = objc.lookUpClass('NSObject').alloc().init() 14 15 m = o.description 16 self.assertIsInstance(m.selector, bytes) 17 self.assertIsInstance(m.signature, bytes) 18 19 meta = m.__metadata__() 20 self.assertIsInstance(meta['retval']['type'], bytes) 21 for a in meta['arguments']: 22 self.assertIsInstance(a['type'], bytes) 23 24 def testFunctionLookup(self): 25 NSBundle = objc.lookUpClass('NSBundle') 26 bundle = NSBundle.bundleForClass_(NSBundle) 27 28 tab = [ 29 ( 'NSHomeDirectory', b'@'), 30 ] 31 d = {} 32 objc.loadBundleFunctions(bundle, d, tab) 33 self.assertIn('NSHomeDirectory', d) 34 35 36 tab = [ 37 ( 'NSHomeDirectory', '@'), 38 ] 39 self.assertRaises(TypeError, objc.loadBundleFunctions, bundle, d, tab) 40 41 tab = [ 42 ( b'NSHomeDirectory', b'@'), 43 ] 44 self.assertRaises(TypeError, objc.loadBundleFunctions, bundle, d, tab) 45 46 def testVariableLookup(self): 47 NSBundle = objc.lookUpClass('NSBundle') 48 bundle = NSBundle.bundleForClass_(NSBundle) 49 50 tab = [ 51 ('NSAppleScriptErrorMessage', b'@'), 52 ] 53 54 d = {} 55 objc.loadBundleVariables(bundle, d, tab) 56 self.assertIn('NSAppleScriptErrorMessage', d) 57 58 59 60 tab = [ 61 ('NSAppleScriptErrorMessage', '@'), 62 ] 63 64 self.assertRaises(TypeError, objc.loadBundleVariables, bundle, d, tab) 65 66 tab = [ 67 (b'NSAppleScriptErrorMessage', b'@'), 68 ] 69 70 self.assertRaises(TypeError, objc.loadBundleVariables, bundle, d, tab) 71 72 73 74if __name__ == "__main__": 75 main() 76