Пример #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']
Пример #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']
Пример #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)
Пример #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
Пример #5
0
def mergeAll(array):
    merged = {}
    for x in array:
        merged = merge(merged, x)
    return merged
Пример #6
0
def test_overlapping_different():
    # expect an exception
    with pytest.raises(KeyConflictError):
        merge(BASE, OVERLAPPING_DIFFERENT)
Пример #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
Пример #8
0
def test_non_overlapping():
    # expect a straightforward merge
    assert merge(BASE, NON_OVERLAPPING) == BASE_NON_OVERLAPPING
Пример #9
0
def test_no_resolver():
    '''expect a KeyConflictError'''
    with pytest.raises(KeyConflictError):
        merge(BASE, OVERLAPPING_SAME, None)