def test_function(self):
        dct = {}
        objc.loadBundleFunctions(
            None,
            dct,
            [
                ("NSTemporaryDirectory", objc._C_ID),
                (
                    "NSSearchPathForDirectoriesInDomains",
                    objc._C_ID
                    + objc._C_NSUInteger
                    + objc._C_NSUInteger
                    + objc._C_NSBOOL,
                ),
            ],
        )
        NSTemporaryDirectory = dct["NSTemporaryDirectory"]
        NSSearchPathForDirectoriesInDomains = dct["NSSearchPathForDirectoriesInDomains"]

        self.assertEqual(
            NSTemporaryDirectory.__signature__,
            mod.callable_signature(NSTemporaryDirectory),
        )
        self.assertEqual(
            NSSearchPathForDirectoriesInDomains.__signature__,
            mod.callable_signature(NSSearchPathForDirectoriesInDomains),
        )

        sig = NSTemporaryDirectory.__signature__
        self.assertIsInstance(sig, inspect.Signature)
        self.assertEqual(len(sig.parameters), 0)

        sig = NSSearchPathForDirectoriesInDomains.__signature__
        self.assertIsInstance(sig, inspect.Signature)
        self.assertEqual(len(sig.parameters), 3)
        self.assertEqual(
            sig.parameters["arg0"],
            inspect.Parameter("arg0", inspect.Parameter.POSITIONAL_ONLY),
        )
        self.assertEqual(
            sig.parameters["arg1"],
            inspect.Parameter("arg1", inspect.Parameter.POSITIONAL_ONLY),
        )
        self.assertEqual(
            sig.parameters["arg2"],
            inspect.Parameter("arg2", inspect.Parameter.POSITIONAL_ONLY),
        )
        self.assertEqual(list(sig.parameters), ["arg0", "arg1", "arg2"])
示例#2
0
    def test_selector(self):
        m = NSArray.array
        self.assertEqual(m.__signature__, mod.callable_signature(m))

        sig = m.__signature__
        self.assertIsInstance(sig, inspect.Signature)
        self.assertEqual(len(sig.parameters), 0)

        m = NSArray.arrayWithObjects_
        sig = m.__signature__
        self.assertIsInstance(sig, inspect.Signature)
        self.assertEqual(len(sig.parameters), 1)
        self.assertEqual(
            sig.parameters["arg0"],
            inspect.Parameter("arg0", inspect.Parameter.POSITIONAL_ONLY),
        )

        m = NSArray.indexOfObject_inRange_
        sig = m.__signature__
        self.assertIsInstance(sig, inspect.Signature)
        self.assertEqual(len(sig.parameters), 2)
        self.assertEqual(
            sig.parameters["arg0"],
            inspect.Parameter("arg0", inspect.Parameter.POSITIONAL_ONLY),
        )
        self.assertEqual(
            sig.parameters["arg1"],
            inspect.Parameter("arg1", inspect.Parameter.POSITIONAL_ONLY),
        )
        self.assertEqual(list(sig.parameters), ["arg0", "arg1"])
        def test_function(self):
            dct = {}
            func = objc.loadBundleFunctions(None, dct, [
                ('NSTemporaryDirectory', objc._C_ID),
                ('NSSearchPathForDirectoriesInDomains', objc._C_ID + objc._C_NSUInteger + objc._C_NSUInteger + objc._C_NSBOOL),
            ])
            NSTemporaryDirectory = dct['NSTemporaryDirectory']
            NSSearchPathForDirectoriesInDomains = dct['NSSearchPathForDirectoriesInDomains']

            self.assertEqual(NSTemporaryDirectory.__signature__, mod.callable_signature(NSTemporaryDirectory))
            self.assertEqual(NSSearchPathForDirectoriesInDomains.__signature__, mod.callable_signature(NSSearchPathForDirectoriesInDomains))

            sig = NSTemporaryDirectory.__signature__
            self.assertIsInstance(sig, inspect.Signature)
            self.assertEqual(len(sig.parameters), 0)

            sig = NSSearchPathForDirectoriesInDomains.__signature__
            self.assertIsInstance(sig, inspect.Signature)
            self.assertEqual(len(sig.parameters), 3)
            self.assertEqual(sig.parameters['arg0'], inspect.Parameter('arg0', inspect.Parameter.POSITIONAL_ONLY))
            self.assertEqual(sig.parameters['arg1'], inspect.Parameter('arg1', inspect.Parameter.POSITIONAL_ONLY))
            self.assertEqual(sig.parameters['arg2'], inspect.Parameter('arg2', inspect.Parameter.POSITIONAL_ONLY))
            self.assertEqual(list(sig.parameters), ['arg0', 'arg1', 'arg2'])
        def test_selector(self):
            m = NSArray.array
            self.assertEqual(m.__signature__, mod.callable_signature(m))

            sig = m.__signature__
            self.assertIsInstance(sig, inspect.Signature)
            self.assertEqual(len(sig.parameters), 0)

            m = NSArray.arrayWithObjects_
            sig = m.__signature__
            self.assertIsInstance(sig, inspect.Signature)
            self.assertEqual(len(sig.parameters), 1)
            self.assertEqual(sig.parameters['arg0'], inspect.Parameter('arg0', inspect.Parameter.POSITIONAL_ONLY))

            m = NSArray.indexOfObject_inRange_
            sig = m.__signature__
            self.assertIsInstance(sig, inspect.Signature)
            self.assertEqual(len(sig.parameters), 2)
            self.assertEqual(sig.parameters['arg0'], inspect.Parameter('arg0', inspect.Parameter.POSITIONAL_ONLY))
            self.assertEqual(sig.parameters['arg1'], inspect.Parameter('arg1', inspect.Parameter.POSITIONAL_ONLY))
            self.assertEqual(list(sig.parameters), ['arg0', 'arg1'])