Ejemplo n.º 1
0
def test_overlapping_with_cascading_resolver():
    # expect resolver to be called with the overlapping pairs
    non_local = { 'resolver called': False }
    def resolver(key, a_value, b_value):
        non_local['resolver called'] = True
        return {'foo': a_value + b_value}
    cascade_overlapping = merge(BASE, OVERLAPPING_SAME, resolver)
    assert non_local['resolver called']
    assert 'FOO' in cascade_overlapping['foo']
    assert 'BARBAR' in cascade_overlapping['foo']
Ejemplo n.º 2
0
def test_overlapping_with_del_resolver():
    # expect resolver to be called with the overlapping pairs
    non_local = { 'resolver called': False }
    def resolver(key, a_value, b_value):
        non_local['resolver called'] = True
        assert key == 'bar'
        assert a_value == 'BAR'
        assert b_value == 'BAR'
        return {}
    assert merge(BASE, OVERLAPPING_SAME, resolver) == DEL_OVERLAPPING
    assert non_local['resolver called']
Ejemplo n.º 3
0
def test_wrong_types():
    '''expect actionable error messages'''
    with pytest.raises(TypeError):
        merge(1, dict())
    with pytest.raises(TypeError):
        merge(dict(), 2)
    with pytest.raises(TypeError):
        merge(dict(), dict(), 1)
Ejemplo n.º 4
0
def test_recursive():
    # expect dictionaries to be combined recursively
    first = {
        'a': {'all': 'azure'},
        'b': {'boss': 'balance', 2: 22}
    }
    second = {
        'a': {1: 1},
        'b': {2:22},
        'c': {'carp': 'careen', 3:333, 'III': 'aye aye aye'}
    }
    combined = {
        'a': {'all': 'azure', 1: 1},
        'b': {'boss': 'balance', 2: 22},
        'c': {'carp': 'careen', 3:333, 'III': 'aye aye aye'}
    }
    assert merge(first, second) == combined
Ejemplo n.º 5
0
def mergeAll(array):
    merged = {}
    for x in array:
        merged = merge(merged, x)
    return merged
Ejemplo n.º 6
0
def test_overlapping_different():
    # expect an exception
    with pytest.raises(KeyConflictError):
        merge(BASE, OVERLAPPING_DIFFERENT)
Ejemplo n.º 7
0
def test_overlapping_same():
    # expect the overlap to resolve to a single copy of the overlapping key/value
    assert merge(BASE, OVERLAPPING_SAME) == BASE_NON_OVERLAPPING
Ejemplo n.º 8
0
def test_non_overlapping():
    # expect a straightforward merge
    assert merge(BASE, NON_OVERLAPPING) == BASE_NON_OVERLAPPING
Ejemplo n.º 9
0
def test_no_resolver():
    '''expect a KeyConflictError'''
    with pytest.raises(KeyConflictError):
        merge(BASE, OVERLAPPING_SAME, None)