pyobjc / pyobjc-core / PyObjCTest / test_varargs.py

import objc
from PyObjCTools.TestSupport import *

NSObject = objc.lookUpClass("NSObject")

if 0:
    class VarargsMethod (TestCase):
        def testVariableArgumentCount(self):
            class VarArgsClass1 (NSObject):
                def instanceMethod1_(self, arg1, *args):
                    arg1.append(args)

                def classMethod1_(cls, arg1, *args):
                    arg1.append(args)
                classMethod1_ = classmethod(classMethod1_)

                def instanceMethod2_(self, *args):
                    args[0].append(args[1:])

                def classMethod2_(cls, *args):
                    args[0].append(args[1:])
                classMethod2_ = classmethod(classMethod2_)

            o = VarArgsClass1.alloc().init()
            l = []
            o.instanceMethod1_(l, 1, 2, 3)
            self.assertEqual(l, [(1,2,3)])

            l = []
            VarArgsClass1.classMethod1_(l, 3, 4, 5)
            self.assertEqual(l, [(3,4,5)])

            l = []
            o.instanceMethod2_(l, 1, 2, 3)
            self.assertEqual(l, [(1,2,3)])

            l = []
            VarArgsClass1.classMethod2_(l, 3, 4, 5)
            self.assertEqual(l, [(3,4,5)])

        def testKeywordArguments(self):
            class VarArgsClass2 (NSObject):
                def instanceMethod1_(self, arg1, **kwds):
                    arg1.append(kwds)

                def classMethod1_(cls, arg1, **kwds):
                    arg1.append(kwds)
                classMethod1_ = classmethod(classMethod1_)


            o = VarArgsClass2.alloc().init()
            l = []
            o.instanceMethod1_(l, a=1, c=2)
            self.assertEqual(l, [{'a':1 ,'c':2}])

            l = []
            VarArgsClass2.classMethod1_(l, foo='bar', baz='foo')
            self.assertEqual(l, [{'foo':'bar', 'baz':'foo'}])

if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.