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
16def do_exec(value, locals, globals):
17
18    exec(value, locals, globals)
19
20def make_test(name):
21    """
22    Create a method for use in a unittest, the exec is needed to get the
23    proper function name
24    """
25    result = { 'meth': getattr(ctests, name) }
26
27    if sys.platform == 'darwin' and name == 'CheckNSInvoke' and platform.machine() == 'Power Macintosh' and map(int, platform.mac_ver()[0].split('.')) < [10, 6]:
28        # There is a bug in Apple's implementation of NSInvocation
29        # surpress the test failure until Apple fixes the class.
30        # Don't change the C-code, the same function is used to disable
31        # parts of the unittests that trigger the bug.
32        def test_CheckNSInvoke(self):
33            try:
34                ctests.CheckNSInvoke()
35            except AssertionError:
36                return
37
38            self.fail("NSInvocation works!")
39
40        return test_CheckNSInvoke
41
42    do_exec("""\
43def test_%s(self):
44    meth()
45"""%(name,), result, result)
46
47    return result['test_%s'%(name,)]
48
49
50for n in names:
51    methods['test_%s'%(n,)] = make_test(n)
52
53CTests = type(TestCase)('CTests', (TestCase,), methods)
54
55if __name__ == "__main__":
56    main()
57