1""" 2This is the runner for the tests defined in Modules/objc/unittest.m. Those tests 3check a number lowlevel features of the bridge. 4 5This file provides a nice unittest wrapper around the functions in that file, 6the code in this file defines a class CTests that has the functions in the 7unitest.m file as its methods. 8""" 9import sys, platform 10from PyObjCTools.TestSupport import * 11from PyObjCTest import ctests 12 13names = [ x for x in dir (ctests) if not x.startswith('_') ] 14methods = {} 15 16 17def make_test(name): 18 """ 19 Create a method for use in a unittest, the exec is needed to get the 20 proper function name 21 """ 22 result = { 'meth': getattr(ctests, name) } 23 24 if sys.platform == 'darwin' and name == 'CheckNSInvoke' and platform.machine() == 'Power Macintosh': 25 # There is a bug in Apple's implementation of NSInvocation 26 # surpress the test failure until Apple fixes the class. 27 # Don't change the C-code, the same function is used to disable 28 # parts of the unittests that trigger the bug. 29 def test_CheckNSInvoke(self): 30 try: 31 ctests.CheckNSInvoke() 32 except AssertionError: 33 return 34 35 raise AssertionError, "NSInvocation works!" 36 37 return test_CheckNSInvoke 38 39 exec """\ 40def test_%s(self): 41 meth() 42"""%(name,) in result 43 44 return result['test_%s'%(name,)] 45 46 47for n in names: 48 methods['test_%s'%(n,)] = make_test(n) 49 50CTests = type(TestCase)('CTests', (TestCase,), methods) 51 52if __name__ == "__main__": 53 main() 54