How to use pyobjc - 10 common examples

To help you get started, we’ve selected a few pyobjc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apple-open-source / macos / pyobjc / pyobjc / pyobjc-core / PyObjCTest / test_methodedits.py View on Github external
def testAssignAMethod(self):
        MEClass.doSomethingElse = lambda self: 2*2
        MEClass.doDuplicate_ = lambda self, x: 2*x

        self.assertTrue(MEClass.instancesRespondToSelector_("doSomethingElse"))
        self.assertTrue(MEClass.instancesRespondToSelector_("doDuplicate:"))

        o = MEClass.alloc().init()

        self.assertEquals(4, o.doSomethingElse())
        self.assertEquals(8, o.doDuplicate_(4))
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-core / PyObjCTest / test_methodedits.py View on Github external
def testAssignAMethod(self):
        MEClass.doSomethingElse = lambda self: 2*2
        MEClass.doDuplicate_ = lambda self, x: 2*x

        self.assertTrue(MEClass.instancesRespondToSelector_("doSomethingElse"))
        self.assertTrue(MEClass.instancesRespondToSelector_("doDuplicate:"))

        o = MEClass.alloc().init()

        self.assertEquals(4, o.doSomethingElse())
        self.assertEquals(8, o.doDuplicate_(4))
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-core / PyObjCTest / test_methodedits.py View on Github external
def testAssignAMethod(self):
        MEClass.doSomethingElse = lambda self: 2*2
        MEClass.doDuplicate_ = lambda self, x: 2*x

        self.assertTrue(MEClass.instancesRespondToSelector_("doSomethingElse"))
        self.assertTrue(MEClass.instancesRespondToSelector_("doDuplicate:"))

        o = MEClass.alloc().init()

        self.assertEquals(4, o.doSomethingElse())
        self.assertEquals(8, o.doDuplicate_(4))
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-core / PyObjCTest / test_methodedits.py View on Github external
def testAssignAMethod(self):
        MEClass.doSomethingElse = lambda self: 2*2
        MEClass.doDuplicate_ = lambda self, x: 2*x

        self.assertTrue(MEClass.instancesRespondToSelector_("doSomethingElse"))
        self.assertTrue(MEClass.instancesRespondToSelector_("doDuplicate:"))

        o = MEClass.alloc().init()

        self.assertEquals(4, o.doSomethingElse())
        self.assertEquals(8, o.doDuplicate_(4))
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_keyvalue.py View on Github external
def testStoredValueForKey(self):
        o = KeyValueClass1.alloc().init()
        o.addMultiple()

        self.assertEqual(STUB.keyValue_forObject_key_(2, o, u"key1"), 1)
        self.assertEqual(STUB.keyValue_forObject_key_(2, o, u"key2"), 2)
        self.assertEqual(STUB.keyValue_forObject_key_(2, o, u"key3"), 3)
        self.assertEqual(STUB.keyValue_forObject_key_(2, o, u"key4"), "4")
        self.assertEqual(STUB.keyValue_forObject_key_(2, o, u"multiple"), o.multiple)

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 2, o, u"nokey")
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_keyvalue.py View on Github external
def addMultiple(self):
        self.multiple = KeyValueClass1.alloc().init()
        self.multiple.level2 = KeyValueClass1.alloc().init()
        self.multiple.level2.level3 = KeyValueClass1.alloc().init()
        self.multiple.level2.level3.keyA = u"hello"
        self.multiple.level2.level3.keyB = u"world"
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_keyvalue.py View on Github external
def testValueForKey(self):
        o = KeyValueClass1.alloc().init()
        o.addMultiple()

        self.assertEqual(STUB.keyValue_forObject_key_(0, o, u"key1"), 1)

        self.assertEqual(STUB.keyValue_forObject_key_(0, o, u"key2"), 2)
        self.assertEqual(STUB.keyValue_forObject_key_(0, o, u"key3"), 3)
        self.assertEqual(STUB.keyValue_forObject_key_(0, o, u"key4"), "4")
        self.assertEqual(STUB.keyValue_forObject_key_(0, o, u"multiple"), o.multiple)

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 0, o, u"nokey")

        self.assertRaises(ValueError, STUB.keyValue_forObject_key_, 0, o,
                u"keyRaisingValueError")
        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 0, o,
                u"keyRaisingNSUnknownKeyException")
        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 0, o,
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_keyvalue.py View on Github external
    @max_os_level('10.5')
    def testTakeValueForKey(self):
        o = KeyValueClass1.alloc().init()

        self.assertEqual(o.key3, 3)
        STUB.setKeyValue_forObject_key_value_(0, o, u'key3', u'drie')
        self.assertEqual(o.key3, u"drie")

        self.assertEqual(o._key4, u"4")
        STUB.setKeyValue_forObject_key_value_(0, o, u'key4', u'vier')
        self.assert_(not hasattr(o, u"key4"))
        self.assertEqual(o._key4, u"viervierviervier")

        o.key5 = 1
        STUB.setKeyValue_forObject_key_value_(0, o, u'key5', u'V')
        self.assertEqual(o.key5, u"VVVVV")

        self.assert_(not hasattr(o, u'key9'))
        STUB.setKeyValue_forObject_key_value_(0, o, u'key9', u'IX')
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_keyvalue.py View on Github external
    @max_os_level('10.5')
    def testTakeValueForKeyPath(self):
        o = KeyValueClass1.alloc().init()
        o.addMultiple()

        self.assertEqual(o.multiple.level2.level3.keyA, u"hello")
        self.assertEqual(o.multiple.level2.level3.keyB, u"world")

        STUB.setKeyValue_forObject_key_value_(1, o, u"multiple.level2.level3.keyA", u"KeyAValue")
        self.assertEqual(o.multiple.level2.level3.keyA, u"KeyAValue")

        STUB.setKeyValue_forObject_key_value_(1, o, u"multiple.level2.level3.keyB", 9.999)
        self.assertEqual(o.multiple.level2.level3.keyB, 9.999)
github apple-open-source / macos / pyobjc / pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_keyvalue.py View on Github external
def testNoPrivateVars(self):
        # Private instance variables ('anObject.__value') are not accessible using
        # key-value coding.
        o = KeyValueClass1.alloc().init()
        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 0, o, u"private")

pyobjc

Python<->ObjC Interoperability Module

MIT
Latest version published 5 months ago

Package Health Score

82 / 100
Full package analysis

Popular pyobjc functions

Similar packages