本文整理匯總了Python中normalize.selector.MultiFieldSelector.patch方法的典型用法代碼示例。如果您正苦於以下問題:Python MultiFieldSelector.patch方法的具體用法?Python MultiFieldSelector.patch怎麽用?Python MultiFieldSelector.patch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類normalize.selector.MultiFieldSelector
的用法示例。
在下文中一共展示了MultiFieldSelector.patch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_mfs_apply_ops
# 需要導入模塊: from normalize.selector import MultiFieldSelector [as 別名]
# 或者: from normalize.selector.MultiFieldSelector import patch [as 別名]
def test_mfs_apply_ops(self):
from copy import deepcopy
from testclasses import wall_one
from normalize.diff import DiffTypes
selectors = (
("owner",),
("posts", 0, "comments", 0, "poster"),
("posts", 0, "comments", 1, "content"),
)
required_fields = (
("id",),
("posts", 0, "edited"),
("posts", 0, "post_id"),
("posts", 0, "wall_id"),
("posts", 0, "comments", 0, "edited"),
("posts", 0, "comments", 0, "id"),
("posts", 0, "comments", 1, "edited"),
("posts", 0, "comments", 1, "id"),
)
deletable_mfs = MultiFieldSelector(*selectors)
skeleton_mfs = MultiFieldSelector(*(required_fields + selectors))
scratch_wall = deepcopy(wall_one)
saved_fields = skeleton_mfs.get(scratch_wall)
deletable_mfs.delete(scratch_wall)
removed = set(
tuple(x.base) for x in wall_one.diff_iter(scratch_wall)
if x.diff_type == DiffTypes.REMOVED
)
self.assertEqual(
removed, set(selectors),
"MultiFieldSelector.delete() can delete named attributes",
)
deletable_mfs.patch(scratch_wall, saved_fields)
self.assertFalse(
scratch_wall.diff(wall_one),
"MultiFieldSelector.patch() can copy named attributes",
)
del saved_fields.owner
deletable_mfs.patch(scratch_wall, saved_fields)
self.assertFalse(
hasattr(scratch_wall, "owner"),
"MultiFieldSelector.patch() can delete missing attributes",
)