Exemplo n.º 1
0
    def test_add_for_selector(self):
        methods = [
            ('add', lambda self, x: self.testMethod_(x))
        ]

        with filterWarnings("error", DeprecationWarning):
            self.assertRaises(DeprecationWarning, objc.addConvenienceForSelector, b'testMethod:', methods)
            if b'testMethod' in convenience._CONVENIENCE_METHODS:
                del convenience._CONVENIENCE_METHODS[b'testMethods:']

        with filterWarnings("ignore", DeprecationWarning):
            self.assertNotIn(b'testMethod:', convenience._CONVENIENCE_METHODS)
            try:
                objc.addConvenienceForSelector(b'testMethod:', methods)

                self.assertEqual(convenience._CONVENIENCE_METHODS[b'testMethod:'], methods)

            finally:
                if b'testMethod' in convenience._CONVENIENCE_METHODS:
                    del convenience._CONVENIENCE_METHODS[b'testMethods:']
Exemplo n.º 2
0
    def test_add_for_selector(self):
        methods = [('add', lambda self, x: self.testMethod_(x))]

        with filterWarnings("error", DeprecationWarning):
            self.assertRaises(DeprecationWarning,
                              objc.addConvenienceForSelector, b'testMethod:',
                              methods)
            if b'testMethod' in convenience._CONVENIENCE_METHODS:
                del convenience._CONVENIENCE_METHODS[b'testMethods:']

        with filterWarnings("ignore", DeprecationWarning):
            self.assertNotIn(b'testMethod:', convenience._CONVENIENCE_METHODS)
            try:
                objc.addConvenienceForSelector(b'testMethod:', methods)

                self.assertEqual(
                    convenience._CONVENIENCE_METHODS[b'testMethod:'], methods)

            finally:
                if b'testMethod' in convenience._CONVENIENCE_METHODS:
                    del convenience._CONVENIENCE_METHODS[b'testMethods:']
Exemplo n.º 3
0
import objc


def __len__(self):
    return self.length()

def __getitem__(self, idx):
    if isinstance(idx, slice):
        raise ValueError(idx)
    return self.indexAtPosition_(idx)

def __add__(self, value):
    return self.indexPathByAddingIndex_(value)


objc.addConvenienceForSelector('length', [
    ('__len__', __len__),
])
objc.addConvenienceForSelector('indexAtPosition:', [
    ('__getitem__', __getitem__),
])
objc.addConvenienceForSelector('indexPathByAddingIndex:', [
    ('__add__', __add__),
])