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