本文整理匯總了Python中normalize.FieldSelector.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python FieldSelector.delete方法的具體用法?Python FieldSelector.delete怎麽用?Python FieldSelector.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類normalize.FieldSelector
的用法示例。
在下文中一共展示了FieldSelector.delete方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_delete
# 需要導入模塊: from normalize import FieldSelector [as 別名]
# 或者: from normalize.FieldSelector import delete [as 別名]
def test_delete(self):
class MyObj(Record):
foo = Property()
bar = Property()
class OtherObj(Record):
objs = ListProperty(of=MyObj)
mo = MyObj(foo="bar")
fs1 = FieldSelector(["foo"])
self.assertEqual(fs1.get(mo), "bar")
fs1.delete(mo)
self.assertRaises(AttributeError, fs1.get, mo)
oo = OtherObj(objs=[{"foo": "bar"}, {"foo": "frop"}])
fs2 = FieldSelector(["objs", 0, "foo"])
self.assertEqual(fs2.get(oo), "bar")
fs2.delete(oo)
self.assertRaises(AttributeError, fs2.get, mo)
fs2.put(oo,"hey")
fs3 = FieldSelector(["objs", None, "foo"])
self.assertEqual(fs3.get(oo), ["hey", "frop"])
fs3.delete(oo)
self.assertEqual(oo, OtherObj(objs=[{}, {}]))
oo = OtherObj(objs=[{"foo": "baz"}, {"bar": "quux"}])
self.assertEqual(fs3.get(oo), ["baz", None])
fs3.delete(oo)
self.assertEqual(oo, OtherObj(objs=[{}, {"bar": "quux"}]))
fs4 = FieldSelector(["objs", None, "bar", "foo"])
self.assertRaises(FieldSelectorException, fs4.get, oo)
oo = OtherObj(objs=[{"foo": "baz"}, {"bar": MyObj(foo="bob")}])
self.assertEqual(fs4.get(oo), [None, "bob"])
fs4.delete(oo)
self.assertRaises(FieldSelectorException, fs4.get, oo)