Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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 addMultiple(self):
self.multiple = KeyValueClass2()
self.multiple.level2 = KeyValueClass2()
self.multiple.level2.level3 = KeyValueClass2()
self.multiple.level2.level3.keyA = u"hello"
self.multiple.level2.level3.keyB = u"world"
def addMultiple(self):
self.multiple = KeyValueClass2()
self.multiple.level2 = KeyValueClass2()
self.multiple.level2.level3 = KeyValueClass2()
self.multiple.level2.level3.keyA = u"hello"
self.multiple.level2.level3.keyB = u"world"
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 testNoPrivateVars(self):
# Private instance variables ('anObject.__value') are not accessible using
# key-value coding.
o = KeyValueClass2()
self.assertRaises(KeyError,
STUB.keyValue_forObject_key_, DO_VALUEFORKEY, o, u"private")
def testSetValuesForKeysFromDictionary(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_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")
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.assertNotHasAttr(o, u'key9')
STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key9', u'IX')
self.assertHasAttr(o, u'key9')
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 testValuesForKeys(self):
o = KeyValueClass2()
self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUESFORKEYS, o, [u"key1", u"key2", u"key3", u"key4"]), { u"key1":1, u"key2": 2, u"key3": 3, u"key4": u"4"} )
self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUESFORKEYS, o, [ u"key1", u"key2", u"nokey", u"key3" ])