def get_items(self): keys_to_update = set() for source in self.sources: new_q = dict(self.query) new_q.update(source.lu_filter(self.targets)) keys_to_update |= set(source().distinct(self.key_field, new_q)) for key in keys_to_update: d = {} for source in self.sources: doc = source().find_one({self.key_field: key}) if doc: if self.aggregate_mode is "Overwrite": for k, v in doc.items(): d[k] = v else: recursive_update(d, doc) d.pop(source.lu_field) yield d
def test_recursiveupdate(self): d = {"a": {"b": 3}, "c": [4]} recursive_update(d, {"c": [5]}) self.assertEqual(d["c"], [5]) recursive_update(d, {"a": {"b": 5}}) self.assertEqual(d["a"]["b"], 5) recursive_update(d, {"a": {"b": [6]}}) self.assertEqual(d["a"]["b"], [6]) recursive_update(d, {"a": {"b": [7]}}) self.assertEqual(d["a"]["b"], [7])
def test_recursiveupdate(): d = {"a": {"b": 3}, "c": [4]} recursive_update(d, {"c": [5]}) assert d["c"] == [5] recursive_update(d, {"a": {"b": 5}}) assert d["a"]["b"] == 5 recursive_update(d, {"a": {"b": [6]}}) assert d["a"]["b"] == [6] recursive_update(d, {"a": {"b": [7]}}) assert d["a"]["b"] == [7]