Ejemplo n.º 1
0
def test_get_custom_strategies():
    patches = [
        Dictdiffer_Conflict(('change', 'p.foo', ('baa', 'bab')),
                            ('change', 'p.foo', ('baa', 'bac'))),
        Dictdiffer_Conflict(('change', 'p.spam', ('eg', 'egg')),
                            ('change', 'p.spam', ('eg', 'eggs'))),
        Dictdiffer_Conflict(('change', 'r.foo', ('baa', 'bab')),
                            ('change', 'r.foo', ('baa', 'bac'))),
        Dictdiffer_Conflict(('change', 'r.spam', ('eg', 'egg')),
                            ('change', 'r.spam', ('eg', 'eggs')))
    ]

    custom_ops = {
        'r': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'p': DictMergerOps.FALLBACK_KEEP_UPDATE
    }

    expected_strategies = ['s', 's', 's', 's']

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategies = m._get_custom_strategies(patches)

    assert expected_strategies == strategies
Ejemplo n.º 2
0
def test_get_custom_strategy_mixed_patches_with_nesting_after_list():
    patches = [
        Dictdiffer_Conflict(
            ('add', ['a', 'c', 0], [('d', '3')]),
            ('add', ['a', 'c', 0], [('d', '4')])
        ),
        Dictdiffer_Conflict(
            ('add', ['a', 'c', 0, 'b'], [('z', '5')]),
            ('add', ['a', 'c', 0, 'b'], [('z', '6')])
        )
    ]

    custom_ops = {
        'a': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'a.c.b': DictMergerOps.FALLBACK_KEEP_HEAD
    }

    expected_strategies = ['s', 'f']

    m = SkipListsMerger(
        {}, {}, {},
        DictMergerOps.FALLBACK_KEEP_HEAD,
        custom_ops=custom_ops
    )

    strategies = [m._get_custom_strategy(patch) for patch in patches]

    assert expected_strategies == strategies
Ejemplo n.º 3
0
def test_get_custom_strategies_change_remove_add_patches_multiple_changes():
    patches = [
        Dictdiffer_Conflict(('change', 'a.c', ('2', '4')),
                            ('remove', '', [('a', {
                                'c': '2',
                                'b': '1'
                            })])),
        Dictdiffer_Conflict(('change', 'a.b', ('1', '3')),
                            ('remove', '', [('a', {
                                'c': '2',
                                'b': '1'
                            })])),
        Dictdiffer_Conflict(('add', 'a', [('d', '5')]),
                            ('remove', '', [('a', {
                                'c': '2',
                                'b': '1'
                            })])),
        Dictdiffer_Conflict(('add', 'a', [('z', '7')]),
                            ('remove', '', [('a', {
                                'c': '2',
                                'b': '1'
                            })]))
    ]

    custom_ops = {'a': DictMergerOps.FALLBACK_KEEP_UPDATE}

    expected_strategies = ['s', 's', 's', 's']

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategies = m._get_custom_strategies(patches)

    assert expected_strategies == strategies
Ejemplo n.º 4
0
def test_get_custom_strategy_mixed_patches():
    patches = [
        Dictdiffer_Conflict(
            ('change', 'b', ('1', '2')),
            ('remove', '', [('b', '1')])
        ),
        Dictdiffer_Conflict(
            ('add', '', [('a', '1')]),
            ('add', '', [('a', 'd')])
        )
    ]

    custom_ops = {
        'b': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'a': DictMergerOps.FALLBACK_KEEP_UPDATE
    }

    expected_strategies = ['s', 's']

    m = SkipListsMerger(
        {}, {}, {},
        DictMergerOps.FALLBACK_KEEP_HEAD,
        custom_ops=custom_ops
    )

    strategies = [m._get_custom_strategy(patch) for patch in patches]

    assert expected_strategies == strategies
Ejemplo n.º 5
0
def test_get_custom_strategy_add_change_patches_very_nested():
    patches = [
        Dictdiffer_Conflict(
            ('change', 'a.b.c.d', ('1', '4')),
            ('change', 'a.b.c.d', ('1', '5'))
        ),
        Dictdiffer_Conflict(
            ('add', 'a.b.c', [('e', '2')]),
            ('add', 'a.b.c', [('e', '3')])
        )
    ]

    custom_ops = {
        'b': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'a': DictMergerOps.FALLBACK_KEEP_UPDATE
    }

    expected_strategies = ['s', 's']

    m = SkipListsMerger(
        {}, {}, {},
        DictMergerOps.FALLBACK_KEEP_HEAD,
        custom_ops=custom_ops
    )

    strategies = [m._get_custom_strategy(patch) for patch in patches]

    assert expected_strategies == strategies
Ejemplo n.º 6
0
def test_get_custom_strategies_mixed_patches_multiple_changes_with_list():
    patches = [
        Dictdiffer_Conflict(('add', ['a', 'c', 0], [('b', '1')]),
                            ('add', ['a', 'c', 0], [('b', '2')])),
        Dictdiffer_Conflict(('add', ['a', 'c', 0], [('d', '3')]),
                            ('add', ['a', 'c', 0], [('d', '4')]))
    ]

    custom_ops = {
        'a': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'a.c.b': DictMergerOps.FALLBACK_KEEP_HEAD
    }

    expected_strategies = ['f', 's']

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategies = m._get_custom_strategies(patches)

    assert expected_strategies == strategies
Ejemplo n.º 7
0
def test_get_custom_strategy_add_patch_in_the_root():
    patch = Dictdiffer_Conflict(('add', '', [('a', '1')]),
                                ('add', '', [('a', '2')]))

    custom_ops = {'a': DictMergerOps.FALLBACK_KEEP_UPDATE}

    expected_strategy = 's'

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategy = m._get_custom_strategy(patch)

    assert expected_strategy == strategy
Ejemplo n.º 8
0
def test_get_custom_strategies_add_patches_in_the_root():
    patches = [
        Dictdiffer_Conflict(('add', '', [('a', '1')]),
                            ('add', '', [('a', '2')]))
    ]

    custom_ops = {'a': DictMergerOps.FALLBACK_KEEP_UPDATE}

    expected_strategies = ['s']

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategies = m._get_custom_strategies(patches)

    assert expected_strategies == strategies
Ejemplo n.º 9
0
def test_get_custom_strategy_change_remove_patch():
    patch = Dictdiffer_Conflict(('change', 'a.b', ('1', '2')),
                                ('remove', '', [('a', {
                                    'b': '1'
                                })]))

    custom_ops = {'a.b': DictMergerOps.FALLBACK_KEEP_UPDATE}

    expected_strategy = 's'

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategy = m._get_custom_strategy(patch)

    assert expected_strategy == strategy
Ejemplo n.º 10
0
def test_get_custom_strategy_mixed_patches_with_nested_changes():
    patch = Dictdiffer_Conflict(('change', 'a.b', ('1', '2')),
                                ('change', 'a.b', ('1', '3')))

    custom_ops = {
        'a.b': DictMergerOps.FALLBACK_KEEP_UPDATE,
    }

    expected_strategy = 's'

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategy = m._get_custom_strategy(patch)

    assert expected_strategy == strategy
Ejemplo n.º 11
0
def test_get_custom_strategy_mixed_patch_with_list():
    patch = Dictdiffer_Conflict(('add', ['a', 'c', 0], [('b', '1')]),
                                ('add', ['a', 'c', 0], [('b', '2')]))

    custom_ops = {
        'a': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'a.c.b': DictMergerOps.FALLBACK_KEEP_HEAD
    }

    expected_strategy = 'f'

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategy = m._get_custom_strategy(patch)

    assert expected_strategy == strategy
Ejemplo n.º 12
0
def test_get_custom_strategy_add_patch_very_nested():
    patch = Dictdiffer_Conflict(('add', 'a.b.c', [('e', '2')]),
                                ('add', 'a.b.c', [('e', '3')]))

    custom_ops = {
        'b': DictMergerOps.FALLBACK_KEEP_UPDATE,
        'a': DictMergerOps.FALLBACK_KEEP_UPDATE
    }

    expected_strategy = 's'

    m = SkipListsMerger({}, {}, {},
                        DictMergerOps.FALLBACK_KEEP_HEAD,
                        custom_ops=custom_ops)

    strategy = m._get_custom_strategy(patch)

    assert expected_strategy == strategy