本文整理汇总了Python中mongo_connector.oplog_manager.OplogThread._find_update_fields方法的典型用法代码示例。如果您正苦于以下问题:Python OplogThread._find_update_fields方法的具体用法?Python OplogThread._find_update_fields怎么用?Python OplogThread._find_update_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_connector.oplog_manager.OplogThread
的用法示例。
在下文中一共展示了OplogThread._find_update_fields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_update_fields
# 需要导入模块: from mongo_connector.oplog_manager import OplogThread [as 别名]
# 或者: from mongo_connector.oplog_manager.OplogThread import _find_update_fields [as 别名]
def test_find_update_fields(self):
doc = {'a': {'b': {'c': 1}}, 'e.f': 1, 'g.h': {'i': {'j': 1}}}
self.assertEqual(OplogThread._find_update_fields('a', doc),
[(['a'], doc['a'])])
self.assertEqual(OplogThread._find_update_fields('a.b', doc),
[(['a', 'b'], doc['a']['b'])])
self.assertEqual(OplogThread._find_update_fields('a.b.c', doc),
[(['a', 'b', 'c'], doc['a']['b']['c'])])
self.assertEqual(OplogThread._find_update_fields('x', doc),
[])
self.assertEqual(OplogThread._find_update_fields('a.b.x', doc),
[])
self.assertEqual(OplogThread._find_update_fields('e.f', doc),
[(['e.f'], doc['e.f'])])
self.assertEqual(OplogThread._find_update_fields('e', doc),
[(['e.f'], doc['e.f'])])
self.assertEqual(OplogThread._find_update_fields('g.h.i.j', doc),
[(['g.h', 'i', 'j'], doc['g.h']['i']['j'])])
# Test multiple matches
doc = {'a.b': 1, 'a.c': 2, 'e.f.h': 3, 'e.f.i': 4}
matches = OplogThread._find_update_fields('a', doc)
self.assertEqual(len(matches), 2)
self.assertIn((['a.b'], doc['a.b']), matches)
self.assertIn((['a.c'], doc['a.c']), matches)
matches = OplogThread._find_update_fields('e.f', doc)
self.assertEqual(len(matches), 2)
self.assertIn((['e.f.h'], doc['e.f.h']), matches)
self.assertIn((['e.f.i'], doc['e.f.i']), matches)
# Test updates to array fields
doc = {'a.b.1': 9, 'a.b.3': 10, 'a.b.4.c': 11}
matches = OplogThread._find_update_fields('a.b', doc)
self.assertEqual(len(matches), 3)
self.assertIn((['a.b.1'], doc['a.b.1']), matches)
self.assertIn((['a.b.3'], doc['a.b.3']), matches)
self.assertIn((['a.b.4.c'], doc['a.b.4.c']), matches)
示例2: test_find_update_fields
# 需要导入模块: from mongo_connector.oplog_manager import OplogThread [as 别名]
# 或者: from mongo_connector.oplog_manager.OplogThread import _find_update_fields [as 别名]
def test_find_update_fields(self):
doc = {"a": {"b": {"c": 1}}, "e.f": 1, "g.h": {"i": {"j": 1}}}
self.assertEqual(OplogThread._find_update_fields("a", doc), [(["a"], doc["a"])])
self.assertEqual(
OplogThread._find_update_fields("a.b", doc), [(["a", "b"], doc["a"]["b"])]
)
self.assertEqual(
OplogThread._find_update_fields("a.b.c", doc),
[(["a", "b", "c"], doc["a"]["b"]["c"])],
)
self.assertEqual(OplogThread._find_update_fields("x", doc), [])
self.assertEqual(OplogThread._find_update_fields("a.b.x", doc), [])
self.assertEqual(
OplogThread._find_update_fields("e.f", doc), [(["e.f"], doc["e.f"])]
)
self.assertEqual(
OplogThread._find_update_fields("e", doc), [(["e.f"], doc["e.f"])]
)
self.assertEqual(
OplogThread._find_update_fields("g.h.i.j", doc),
[(["g.h", "i", "j"], doc["g.h"]["i"]["j"])],
)
# Test multiple matches
doc = {"a.b": 1, "a.c": 2, "e.f.h": 3, "e.f.i": 4}
matches = OplogThread._find_update_fields("a", doc)
self.assertEqual(len(matches), 2)
self.assertIn((["a.b"], doc["a.b"]), matches)
self.assertIn((["a.c"], doc["a.c"]), matches)
matches = OplogThread._find_update_fields("e.f", doc)
self.assertEqual(len(matches), 2)
self.assertIn((["e.f.h"], doc["e.f.h"]), matches)
self.assertIn((["e.f.i"], doc["e.f.i"]), matches)
# Test updates to array fields
doc = {"a.b.1": 9, "a.b.3": 10, "a.b.4.c": 11}
matches = OplogThread._find_update_fields("a.b", doc)
self.assertEqual(len(matches), 3)
self.assertIn((["a.b.1"], doc["a.b.1"]), matches)
self.assertIn((["a.b.3"], doc["a.b.3"]), matches)
self.assertIn((["a.b.4.c"], doc["a.b.4.c"]), matches)