def test_get_rule_for_field_looks_at_correct_path(): def keep_spam(head, update, down_path): return 's' if update == 'spam' else 'f' custom_ops = {'a.b': keep_spam} head = { 'a': { 'b': [ 'egg', 'bacon', ], 'c': 'egg', }, } update = { 'a': { 'b': [ 'spam', 'bread', ], }, } m = SkipListsMerger({}, head, update, DictMergerOps.FALLBACK_KEEP_HEAD, custom_ops=custom_ops, data_lists='a.b') expected = 's' output = m._get_rule_for_field(['a', 'b', 0]) assert expected == output
def test_get_rule_for_field_no_match(): custom_ops = {'a.b': DictMergerOps.FALLBACK_KEEP_UPDATE} m = SkipListsMerger({}, {}, {}, DictMergerOps.FALLBACK_KEEP_HEAD, custom_ops=custom_ops) expected = 'f' output = m._get_rule_for_field(['a', 'l', 'c', 'd']) assert expected == output
def test_get_rule_for_field_uses_key_path(): custom_ops = { 'a.b.c': DictMergerOps.FALLBACK_KEEP_UPDATE, } m = SkipListsMerger({}, {}, {}, DictMergerOps.FALLBACK_KEEP_HEAD, custom_ops=custom_ops, key_path=['a', 0]) expected = 's' output = m._get_rule_for_field(['b', 'c']) assert expected == output
def test_get_rule_for_field_uses_key_path(): custom_ops = { 'a.b.c': DictMergerOps.FALLBACK_KEEP_UPDATE, } m = SkipListsMerger( {}, {}, {}, DictMergerOps.FALLBACK_KEEP_HEAD, custom_ops=custom_ops, key_path=['a', 0] ) expected = 's' output = m._get_rule_for_field(['b', 'c']) assert expected == output
def test_get_rule_for_field_no_match(): custom_ops = { 'a.b': DictMergerOps.FALLBACK_KEEP_UPDATE } m = SkipListsMerger( {}, {}, {}, DictMergerOps.FALLBACK_KEEP_HEAD, custom_ops=custom_ops ) expected = 'f' output = m._get_rule_for_field(['a', 'l', 'c', 'd']) assert expected == output
def test_get_rule_for_field_looks_at_correct_path(): def keep_spam(head, update, down_path): return 's' if update == 'spam' else 'f' custom_ops = { 'a.b': keep_spam } head = { 'a': { 'b': [ 'egg', 'bacon', ], 'c': 'egg', }, } update = { 'a': { 'b': [ 'spam', 'bread', ], }, } m = SkipListsMerger( {}, head, update, DictMergerOps.FALLBACK_KEEP_HEAD, custom_ops=custom_ops, data_lists='a.b' ) expected = 's' output = m._get_rule_for_field(['a', 'b', 0]) assert expected == output