本文整理汇总了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))