本文整理匯總了Python中PyObjCTools.KeyValueCoding.kvc方法的典型用法代碼示例。如果您正苦於以下問題:Python KeyValueCoding.kvc方法的具體用法?Python KeyValueCoding.kvc怎麽用?Python KeyValueCoding.kvc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyObjCTools.KeyValueCoding
的用法示例。
在下文中一共展示了KeyValueCoding.kvc方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_attribute_access
# 需要導入模塊: from PyObjCTools import KeyValueCoding [as 別名]
# 或者: from PyObjCTools.KeyValueCoding import kvc [as 別名]
def test_attribute_access(self):
v = object()
o = KeyValueCoding.kvc(v)
o.key
o.key2
getattr(o, "key3.key4")
self.assertEqual(self._trace, [
('get', v, 'key'),
('get', v, 'key2'),
('get', v, 'key3.key4'),
])
self._trace[:] = []
o.key = 42
setattr(o, "key3.key4", 99)
self.assertEqual(self._trace, [
('set', v, 'key', 42),
('set', v, 'key3.key4', 99),
])
self._trace[:] = []
class Object (object):
pass
v = Object()
o = KeyValueCoding.kvc(v)
o.key = 42
o._key = 99
self.assertEqual(self._trace, [
('set', v, 'key', 42),
])
self.assertEqual(o._key, 99)
self.assertIn('_key', o.__dict__)
self.assertNotIn('key', o.__dict__)
示例2: test_item_access
# 需要導入模塊: from PyObjCTools import KeyValueCoding [as 別名]
# 或者: from PyObjCTools.KeyValueCoding import kvc [as 別名]
def test_item_access(self):
v = object()
o = KeyValueCoding.kvc(v)
o['key']
o['key2']
o['key3.key4']
self.assertEqual(self._trace, [
('get-path', v, 'key'),
('get-path', v, 'key2'),
('get-path', v, 'key3.key4'),
])
self._trace[:] = []
o["key"] = 42
o["key3.key4"] = 99
self.assertEqual(self._trace, [
('set-path', v, 'key', 42),
('set-path', v, 'key3.key4', 99),
])
self._trace[:] = []
self.assertRaises(TypeError, operator.getitem, o, 42)
self.assertRaises(TypeError, operator.setitem, o, 42, 99)
示例3: test_repr
# 需要導入模塊: from PyObjCTools import KeyValueCoding [as 別名]
# 或者: from PyObjCTools.KeyValueCoding import kvc [as 別名]
def test_repr(self):
for o in [
object(), 42, "42", b"42", b"42".decode('latin1')
]:
self.assertEqual(repr(KeyValueCoding.kvc(o)), repr(o))