def testOverValueKeyPath(self): self.assertEqual( DirectString, STUB.keyValue_forObject_key_( DO_VALUEFORKEYPATH, self.path, "overDirectHead.directString" ), ) self.assertEqual( DirectString, STUB.keyValue_forObject_key_( DO_VALUEFORKEYPATH, self.path, "overIndirectHead.directString" ), ) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_( DO_VALUEFORKEYPATH, self.path, "overDirectHead.indirectString" ), ) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_( DO_VALUEFORKEYPATH, self.path, "overIndirectHead.indirectString" ), )
def testSetValuesForKeysFromDictionary(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) self.assertEqual(o._key4, "4") o.key5 = 1 self.assertNotHasAttr(o, "key9") STUB.setKeyValue_forObject_key_value_( DO_SETVALUESFORKEYSFROMDICT, o, None, { "key3": "drie", "key4": "vier", "key5": "V", "key9": "IX" }, ) self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "viervierviervier") self.assertEqual(o.key5, "VVVVV") self.assertHasAttr(o, "key9") self.assertEqual(o.key9, "IX")
def testStoredTakeValueForKey2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_( DO_TAKESTOREDVALUE_FORKEY, o, "foo", "FOO" ) self.assertEqual(o.foo, "FOO") self.assertRaises( KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, "key9", "IX", ) self.assertRaises( KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, "roprop", "IX", )
def testValueForKeyPath(self): o = KeyValueClass2() o.addMultiple() self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, "multiple"), o.multiple) self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, "multiple.level2"), o.multiple.level2, ) self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, "multiple.level2.level3.keyA"), o.multiple.level2.level3.keyA, ) self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, "multiple.level2.level3.keyB"), o.multiple.level2.level3.keyB, ) self.assertRaises( KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEYPATH, o, "multiple.level2.nokey", )
def testSetValuesForKeysFromDictionary2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_( DO_SETVALUESFORKEYSFROMDICT, o, None, {"foo": "FOO"} ) self.assertEqual(o.foo, "FOO") self.assertRaises( KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, {"key9": "IX"}, ) self.assertRaises( KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, {"roprop": "IX"}, )
def testTakeValueForKey2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "foo", "FOO") self.assertEqual(o.foo, "FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUE_FORKEY, o, "key9", "IX")
def testTakeValueForKey2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'foo', 'FOO') self.assertEqual(o.foo, "FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUE_FORKEY, o, 'key9', 'IX')
def testTakeValueForKey2(self): o = KeyValueClass3() self.assertEquals(o.foo, u"foobar") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'foo', u'FOO') self.assertEquals(o.foo, u"FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUE_FORKEY, o, u'key9', u'IX')
def testTakeValuesFromDictionary2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, { 'foo': 'FOO' }) self.assertEqual(o.foo, "FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { 'key9': 'IX' }) self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { 'roprop': 'IX' })
def testStoredTakeValueForKey2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, 'foo', 'FOO') self.assertEqual(o.foo, "FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, 'key9', 'IX') self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, 'roprop', 'IX')
def testSetValuesForKeysFromDictionary2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, { 'foo': 'FOO' }) self.assertEqual(o.foo, "FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { 'key9': 'IX' }) self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { 'roprop': 'IX' })
def testOverValueKey(self): self.assertEqual( DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "overDirectString")) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "overIndirectString"))
def testStoredTakeValueForKey2(self): o = KeyValueClass3() self.assertEquals(o.foo, u"foobar") STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'foo', u'FOO') self.assertEquals(o.foo, u"FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, u'key9', u'IX') self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, u'roprop', u'IX')
def testTakeValuesFromDictionary2(self): o = KeyValueClass3() self.assertEquals(o.foo, u"foobar") STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, { u'foo': u'FOO' }) self.assertEquals(o.foo, u"FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { u'key9': u'IX' }) self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { u'roprop': u'IX' })
def testSetValuesForKeysFromDictionary2(self): o = KeyValueClass3() self.assertEquals(o.foo, u"foobar") STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, { u'foo': u'FOO' }) self.assertEquals(o.foo, u"FOO") self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { u'key9': u'IX' }) self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { u'roprop': u'IX' })
def testBaseValueForKey(self): self.assertEqual(DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "directString")) self.assertEqual(IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "indirectString")) self.assertEqual(DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "directNumber")) self.assertEqual(IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "indirectNumber"))
def testBaseValueForKey(self): self.assertEquals(DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"directString")) self.assertEquals(IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"indirectString")) self.assertEquals(DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"directNumber")) self.assertEquals(IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"indirectNumber"))
def testOverValueKeyPath(self): self.assertEquals(DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overDirectHead.directString")) self.assertEquals(DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overIndirectHead.directString")) self.assertEquals(IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overDirectHead.indirectString")) self.assertEquals(IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overIndirectHead.indirectString"))
def testValueForKeyPath(self): o = KeyValueClass2() o.addMultiple() self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple"), o.multiple) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple.level2"), o.multiple.level2) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple.level2.level3.keyA"), o.multiple.level2.level3.keyA) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple.level2.level3.keyB"), o.multiple.level2.level3.keyB) self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEYPATH, o, u"multiple.level2.nokey")
def testStoredValueForKey(self): o = KeyValueClass2() o.addMultiple() self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key1"), 1) self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key2"), 2) self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key3"), 3) self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key4"), u"4") self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"multiple"), o.multiple) self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_STOREDVALUEFORKEY, o, u"nokey")
def testStoredValueForKey(self): o = KeyValueClass2() o.addMultiple() self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key1"), 1) self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key2"), 2) self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key3"), 3) self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key4"), "4") self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "multiple"), o.multiple) self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_STOREDVALUEFORKEY, o, "nokey")
def testValueForKey2(self): o = KeyValueClass3() self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "foo"), "foobar") self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "bar"), "foobarfoobar") self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "roprop"), "read-only")
def testPythonConvention(self): o = KeyValueClass2() self.assertEqual(o._pythonConvention, "BAD") self.assertEqual(o.pythonConvention(), "GOOD") self.assertEqual(o._pythonConventionValue, "GOOD") self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), "GOOD") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "pythonConvention", "CHANGED") self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), "CHANGED") self.assertEqual(o._pythonConvention, "BAD") self.assertEqual(o.pythonConvention(), "CHANGED") self.assertEqual(o._pythonConventionValue, "CHANGED")
def testSetValueForKeyPath(self): o = KeyValueClass2() o.addMultiple() self.assertEqual(o.multiple.level2.level3.keyA, "hello") self.assertEqual(o.multiple.level2.level3.keyB, "world") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, "multiple.level2.level3.keyA", "KeyAValue") self.assertEqual(o.multiple.level2.level3.keyA, "KeyAValue") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, "multiple.level2.level3.keyB", 9.999) self.assertEqual(o.multiple.level2.level3.keyB, 9.999)
def testSetValueForKeyPath(self): o = KeyValueClass2() o.addMultiple() self.assertEquals(o.multiple.level2.level3.keyA, u"hello") self.assertEquals(o.multiple.level2.level3.keyB, u"world") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyA", u"KeyAValue") self.assertEquals(o.multiple.level2.level3.keyA, u"KeyAValue") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyB", 9.999) self.assertEquals(o.multiple.level2.level3.keyB, 9.999)
def testTakeValueForKeyPath(self): o = KeyValueClass2() o.addMultiple() self.assertEqual(o.multiple.level2.level3.keyA, "hello") self.assertEqual(o.multiple.level2.level3.keyB, "world") STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, "multiple.level2.level3.keyA", "KeyAValue") self.assertEqual(o.multiple.level2.level3.keyA, "KeyAValue") STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, "multiple.level2.level3.keyB", 9.999) self.assertEqual(o.multiple.level2.level3.keyB, 9.999)
def testTakeValueForKeyPath(self): o = KeyValueClass2() o.addMultiple() self.assertEquals(o.multiple.level2.level3.keyA, u"hello") self.assertEquals(o.multiple.level2.level3.keyB, u"world") STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyA", u"KeyAValue") self.assertEquals(o.multiple.level2.level3.keyA, u"KeyAValue") STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyB", 9.999) self.assertEquals(o.multiple.level2.level3.keyB, 9.999)
def testPythonConvention(self): o = KeyValueClass2() self.assertEquals(o._pythonConvention, u'BAD') self.assertEquals(o.pythonConvention(), u'GOOD') self.assertEquals(o._pythonConventionValue, u'GOOD') self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"pythonConvention"), u'GOOD') STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'pythonConvention', u'CHANGED') self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"pythonConvention"), u'CHANGED') self.assertEquals(o._pythonConvention, u'BAD') self.assertEquals(o.pythonConvention(), u'CHANGED') self.assertEquals(o._pythonConventionValue, u'CHANGED')
def testPythonConvention(self): o = KeyValueClass2() self.assertEqual(o._pythonConvention, 'BAD') self.assertEqual(o.pythonConvention(), 'GOOD') self.assertEqual(o._pythonConventionValue, 'GOOD') self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), 'GOOD') STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'pythonConvention', 'CHANGED') self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), 'CHANGED') self.assertEqual(o._pythonConvention, 'BAD') self.assertEqual(o.pythonConvention(), 'CHANGED') self.assertEqual(o._pythonConventionValue, 'CHANGED')
def testSetValuesForKeysFromDictionary2(self): o = KeyValueClass3() self.assertEqual(o.foo, "foobar") STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, {"foo": "FOO"}) self.assertEqual(o.foo, "FOO") self.assertRaises( KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, {"key9": "IX"} ) self.assertRaises( KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, {"roprop": "IX"} )
def testPathValueForKey(self): self.assertEqual( DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.directString")) self.assertEqual( DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.directString")) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.indirectString")) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.indirectString")) self.assertEqual( DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.directNumber")) self.assertEqual( DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.directNumber")) self.assertEqual( IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.indirectNumber")) self.assertEqual( IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.indirectNumber"))
def testPathValueForKey(self): self.assertEqual( DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.directString") ) self.assertEqual( DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.directString") ) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.indirectString") ) self.assertEqual( IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.indirectString") ) self.assertEqual( DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.directNumber") ) self.assertEqual( DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.directNumber") ) self.assertEqual( IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.indirectNumber") ) self.assertEqual( IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.indirectNumber") )
def testTakeStoredValueForKey(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) STUB.setKeyValue_forObject_key_value_( DO_TAKESTOREDVALUE_FORKEY, o, "key3", "drie" ) self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "4") STUB.setKeyValue_forObject_key_value_( DO_TAKESTOREDVALUE_FORKEY, o, "key4", "vier" ) self.assertEqual(o._key4, "viervierviervier") o.key5 = 1 STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, "key5", "V") self.assertEqual(o.key5, "VVVVV") self.assertNotHasAttr(o, "key9") STUB.setKeyValue_forObject_key_value_( DO_TAKESTOREDVALUE_FORKEY, o, "key9", "IX" ) self.assertHasAttr(o, "key9") self.assertEqual(o.key9, "IX")
def testStrCap(self): class Foo: def callme(self): return u"FOO" # check the result for valueForKey: u"callme" on a Foo instance self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, Foo(), u"callme"), u"FOO")
def testCopy(self): class MyCopyClass(NSObject): def copyWithZone_(self, zone): # NSObject doesn't implement the copying protocol #o = super(MyCopyClass, self).copyWithZone_(zone) o = self.__class__.alloc().init() o.foobar = 2 return o copyWithZone_ = objc.selector( copyWithZone_, signature=NSObject.copyWithZone_.signature, isClassMethod=0) # Make sure the runtime correctly marked our copyWithZone_ # implementation. o = MyCopyClass.alloc().init() self.assertFalse((o.copyWithZone_.__metadata__()['classmethod'])) self.assertTrue( o.copyWithZone_.__metadata__()['retval']['already_retained']) #self.assertTrue(o.copyWithZone_.callable == MyCopyClass.__dict__['copyWithZone_'].callable) o = MyCopyClass.alloc().init() o.foobar = 1 self.assertEquals(o.foobar, 1) # Make a copy from ObjC (see testbundle.m) c = PyObjC_TestClass3.makeACopy_(o) self.assertIsInstance(c, MyCopyClass) self.assertEquals(c.foobar, 2)
def testCopy(self): class MyCopyClass (NSObject): def copyWithZone_(self, zone): # NSObject doesn't implement the copying protocol #o = super(MyCopyClass, self).copyWithZone_(zone) o = self.__class__.alloc().init() o.foobar = 2 return o copyWithZone_ = objc.selector( copyWithZone_, signature=NSObject.copyWithZone_.signature, isClassMethod=0) # Make sure the runtime correctly marked our copyWithZone_ # implementation. o = MyCopyClass.alloc().init() self.assertFalse((o.copyWithZone_.__metadata__()['classmethod'])) self.assertTrue(o.copyWithZone_.__metadata__()['retval']['already_retained']) #self.assertTrue(o.copyWithZone_.callable == MyCopyClass.__dict__['copyWithZone_'].callable) o = MyCopyClass.alloc().init() o.foobar = 1 self.assertEquals(o.foobar, 1) # Make a copy from ObjC (see testbundle.m) c = PyObjC_TestClass3.makeACopy_(o) self.assertIsInstance(c, MyCopyClass) self.assertEquals(c.foobar, 2)
def testStrCap(self): class Foo: def callme(self): return "FOO" # check the result for valueForKey: "callme" on a Foo instance self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, Foo(), "callme"), "FOO")
def testSetValuesForKeysFromDictionary(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) self.assertEqual(o._key4, "4") o.key5 = 1 self.assertNotHasAttr(o, "key9") STUB.setKeyValue_forObject_key_value_( DO_SETVALUESFORKEYSFROMDICT, o, None, {"key3": "drie", "key4": "vier", "key5": "V", "key9": "IX"} ) self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "viervierviervier") self.assertEqual(o.key5, "VVVVV") self.assertHasAttr(o, "key9") self.assertEqual(o.key9, "IX")
def testValuesForKeys(self): o = KeyValueClass2() self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUESFORKEYS, o, ["key1", "key2", "key3", "key4"]), {"key1": 1, "key2": 2, "key3": 3, "key4": "4"}, ) self.assertRaises( KeyError, STUB.keyValue_forObject_key_, DO_VALUESFORKEYS, o, ["key1", "key2", "nokey", "key3"] )
def testPythonConvention(self): o = KeyValueClass2() self.assertEqual(o._pythonConvention, "BAD") self.assertEqual(o.pythonConvention(), "GOOD") self.assertEqual(o._pythonConventionValue, "GOOD") self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), "GOOD", ) STUB.setKeyValue_forObject_key_value_( DO_SETVALUE_FORKEY, o, "pythonConvention", "CHANGED" ) self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), "CHANGED", ) self.assertEqual(o._pythonConvention, "BAD") self.assertEqual(o.pythonConvention(), "CHANGED") self.assertEqual(o._pythonConventionValue, "CHANGED")
def testTakeValuesFromDictionary(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) self.assertEqual(o._key4, "4") o.key5 = 1 self.assertNotHasAttr(o, 'key9') STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, { 'key3': 'drie', 'key4': 'vier', 'key5': 'V', 'key9': 'IX', }) self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "viervierviervier") self.assertEqual(o.key5, "VVVVV") self.assertHasAttr(o, 'key9') self.assertEqual(o.key9, 'IX')
def testSetValuesForKeysFromDictionary(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) self.assertEqual(o._key4, "4") o.key5 = 1 self.assertNotHasAttr(o, 'key9') STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, { 'key3': 'drie', 'key4': 'vier', 'key5': 'V', 'key9': 'IX', }) self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "viervierviervier") self.assertEqual(o.key5, "VVVVV") self.assertHasAttr(o, 'key9') self.assertEqual(o.key9, 'IX')
def testSetValuesForKeysFromDictionary(self): o = KeyValueClass2() self.assertEquals(o.key3, 3) self.assertEquals(o._key4, u"4") o.key5 = 1 self.assert_(not hasattr(o, u'key9')) STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, { u'key3': u'drie', u'key4': u'vier', u'key5': u'V', u'key9': u'IX', }) self.assertEquals(o.key3, u"drie") self.assertEquals(o._key4, u"viervierviervier") self.assertEquals(o.key5, u"VVVVV") self.assert_(hasattr(o, u'key9')) self.assertEquals(o.key9, u'IX')
def testTakeValuesFromDictionary(self): o = KeyValueClass2() self.assertEquals(o.key3, 3) self.assertEquals(o._key4, u"4") o.key5 = 1 self.assertNotHasAttr(o, u'key9') STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, { u'key3': u'drie', u'key4': u'vier', u'key5': u'V', u'key9': u'IX', }) self.assertEquals(o.key3, u"drie") self.assertEquals(o._key4, u"viervierviervier") self.assertEquals(o.key5, u"VVVVV") self.assertHasAttr(o, u'key9') self.assertEquals(o.key9, u'IX')
def testReceiveObserved(self): # Create an object in Objective-C, add an observer and then # pass the object to Python. Unless we take special care the # Python wrapper will have the wrong type (that of the # internal helper class). observer = PyObjCTestObserver.alloc().init() o = STUB.createObservedOfClass_observer_keyPath_( NSObject, observer, u"observationInfo") try: self.assert_(isinstance(o, NSObject)) finally: o.removeObserver_forKeyPath_(observer, u"observationInfo")
def testValuesForKeys(self): o = KeyValueClass2() self.assertEqual( STUB.keyValue_forObject_key_(DO_VALUESFORKEYS, o, ["key1", "key2", "key3", "key4"]), { "key1": 1, "key2": 2, "key3": 3, "key4": "4" }) self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUESFORKEYS, o, ["key1", "key2", "nokey", "key3"])
def testReceiveObserved(self): # Create an object in Objective-C, add an observer and then # pass the object to Python. Unless we take special care the # Python wrapper will have the wrong type (that of the # internal helper class). # # NOTE: This test is known to fail on OSX 10.5 due to the way # KVO is implemented there. observer = PyObjCTestObserver.alloc().init() o = STUB.makeObservedOfClass_observer_keyPath_(NSObject, observer, "observationInfo") try: self.assertIsInstance(o, NSObject) finally: o.removeObserver_forKeyPath_(observer, "observationInfo")
def testReceiveObserved(self): # Create an object in Objective-C, add an observer and then # pass the object to Python. Unless we take special care the # Python wrapper will have the wrong type (that of the # internal helper class). # # NOTE: This test is known to fail on OSX 10.5 due to the way # KVO is implemented there. observer = PyObjCTestObserver.alloc().init() o = STUB.makeObservedOfClass_observer_keyPath_( NSObject, observer, "observationInfo") try: self.assertIsInstance(o, NSObject) finally: o.removeObserver_forKeyPath_(observer, "observationInfo")
def testSetValueForKey(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key3", "drie") self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "4") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key4", "vier") self.assertEqual(o._key4, "viervierviervier") o.key5 = 1 STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key5", "V") self.assertEqual(o.key5, "VVVVV") self.assertNotHasAttr(o, "key9") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key9", "IX") self.assertHasAttr(o, "key9") self.assertEqual(o.key9, "IX")
def testValueForKey(self): o = KeyValueClass2() o.addMultiple() self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key1"), 1) self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key2"), 2) self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key3"), 3) self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key4"), "4") self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "multiple"), o.multiple) self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), 'GOOD') self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEY, o, "nokey")
def testSetValueForKey(self): o = KeyValueClass2() self.assertEqual(o.key3, 3) STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key3', 'drie') self.assertEqual(o.key3, "drie") self.assertEqual(o._key4, "4") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key4', 'vier') self.assertEqual(o._key4, "viervierviervier") o.key5 = 1 STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key5', 'V') self.assertEqual(o.key5, "VVVVV") self.assertNotHasAttr(o, 'key9') STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key9', 'IX') self.assertHasAttr(o, 'key9') self.assertEqual(o.key9, 'IX')
def testSetValueForKey(self): o = KeyValueClass2() self.assertEquals(o.key3, 3) STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key3', u'drie') self.assertEquals(o.key3, u"drie") self.assertEquals(o._key4, u"4") STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key4', u'vier') self.assertEquals(o._key4, u"viervierviervier") o.key5 = 1 STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key5', u'V') self.assertEquals(o.key5, u"VVVVV") self.assert_(not hasattr(o, u'key9')) STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key9', u'IX') self.assert_(hasattr(o, u'key9')) self.assertEquals(o.key9, u'IX')
def testValueForKey(self): o = KeyValueClass2() o.addMultiple() self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key1"), 1) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key2"), 2) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key3"), 3) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key4"), u"4") self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"multiple"), o.multiple) self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"pythonConvention"), u'GOOD') self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEY, o, u"nokey")
def testTakeStoredValueForKey(self): o = KeyValueClass2() self.assertEquals(o.key3, 3) STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key3', u'drie') self.assertEquals(o.key3, u"drie") self.assertEquals(o._key4, u"4") STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key4', u'vier') self.assertEquals(o._key4, u"viervierviervier") o.key5 = 1 STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key5', u'V') self.assertEquals(o.key5, u"VVVVV") self.assertNotHasAttr(o, u'key9') STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key9', u'IX') self.assertHasAttr(o, u'key9') self.assertEquals(o.key9, u'IX')
def testValueForKey2(self): o = KeyValueClass3() self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"foo"), u"foobar") self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"bar"), u"foobarfoobar") self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"roprop"), u"read-only")