1# This is not a real test, but more documentation of a strange feature of 2# the Cocoa runtime. 3# 4# A number of classes in Cocoa grow new methods if you instantiate them. We 5# work around this feature by rescanning the method table after calling a 6# class-method. 7# 8# We need to do this to reliably detect calls to the superclass implementation 9# of a method. Without the workaround, calls to NSButtonCell.isEnabled_ (one 10# of the magical classes) would be interpreted as calls to 11# NSActionCell.isEnabled_, which is wrong. 12# 13 14import sys 15from PyObjCTools.TestSupport import * 16 17import objc 18 19if sys.platform == 'darwin': 20 import AppKit 21 22 class TestWeirdness(TestCase): 23 24 def doWeirdness(self, className, methodToTest): 25 c = objc.lookUpClass(className) 26 before = getattr(c, methodToTest) 27 b = c.alloc().init() 28 after = getattr(c, methodToTest) 29 30 self.assert_(before != after, "No weirdness present on %s.%s"%( 31 className, methodToTest)) 32 33 34 def testWeirdness1(self): 35 self.doWeirdness("NSButtonCell", "setEnabled_") 36 37 def testWeirdness2(self): 38 self.doWeirdness("NSTextView", "setEditable_") 39 40 41if __name__ == '__main__': 42 main() 43