Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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")
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"
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,
@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')
@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)
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")
def testTakeStoredValueForKey(self):
o = KeyValueClass1.alloc().init()
self.assertEqual(o.key3, 3)
STUB.setKeyValue_forObject_key_value_(2, o, u'key3', u'drie')
self.assertEqual(o.key3, u"drie")
self.assertEqual(o._key4, u"4")
STUB.setKeyValue_forObject_key_value_(2, o, u'key4', u'vier')
self.assertEqual(o._key4, u"viervierviervier")
o.key5 = 1
STUB.setKeyValue_forObject_key_value_(2, o, u'key5', u'V')
self.assertEqual(o.key5, u"VVVVV")
self.assert_(not hasattr(o, u'key9'))
STUB.setKeyValue_forObject_key_value_(2, o, u'key9', u'IX')
self.assert_(hasattr(o, u'key9'))
@max_os_level('10.5')
def testValuesForKeys(self):
o = KeyValueClass1.alloc().init()
self.assertEqual(STUB.keyValue_forObject_key_(3, 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_, 3, o, [u"key1", u"key3", u"nosuchkey"])
def testValueForKeyPath(self):
o = KeyValueClass1.alloc().init()
o.addMultiple()
self.assertEqual(STUB.keyValue_forObject_key_(1, o, u"multiple"), o.multiple)
self.assertEqual(STUB.keyValue_forObject_key_(1, o, u"multiple.level2"), o.multiple.level2)
self.assertEqual(STUB.keyValue_forObject_key_(1, o, u"multiple.level2.level3.keyA"),
o.multiple.level2.level3.keyA)
self.assertEqual(STUB.keyValue_forObject_key_(1, o, u"multiple.level2.level3.keyB"),
o.multiple.level2.level3.keyB)
self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 1, o, u"multiple.level2.nokey")