Ejemplo n.º 1
0
def test_array_extend():
    src_dict = {
        "src": [11, 12, 13],
        "merge": [100, 101, 102],
        'nested_dict': {
            'src': [111, 112, 113],
            'merge': [1000, 1001, 1002]
        }
    }

    other_dict = {
        "other": [22, 22, 23],
        "merge": [200, 202, 202],
        'nested_dict': {
            'other': [222, 222, 223],
            'merge': [2000, 2002, 2002]
        }
    }

    src = Configuration.from_dict(src_dict)
    print_yaml("Src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("Other", other)

    merged = deepcopy(src).merge(other)
    print_yaml("merged", merged)

    print_yaml("Src after merge", src)
    print_yaml("Other after merge", other)

    assert verify_key_val(src, src_dict, 'merge')
    assert verify_key_val(src, src_dict, 'src')
    assert verify_key_val(src, src_dict, 'nested_dict.merge')
    assert verify_key_val(src, src_dict, 'nested_dict.src')

    with pytest.raises(KeyError):
        verify_key_val(src, src_dict, 'other')

    assert verify_key_val(merged, src_dict, 'src')
    assert verify_key_val(merged, other_dict, 'other')
    assert merged['merge'] == src_dict['merge'] + other_dict['merge']
    assert verify_key_val(merged, src_dict, 'nested_dict.src')
    assert verify_key_val(merged, other_dict, 'nested_dict.other')
Ejemplo n.º 2
0
def test_array_extend():
    src_dict = {
        "src": [11, 12, 13],
        "merge": [100, 101, 102],
        'nested_dict': {
            'src': [111, 112, 113],
            'merge': [1000, 1001, 1002]
        }
    }

    other_dict = {
        "other": [22, 22, 23],
        "merge": [200, 202, 202],
        'nested_dict': {
            'other': [222, 222, 223],
            'merge': [2000, 2002, 2002]
        }
    }

    src = Configuration.from_dict(src_dict)
    print_yaml("Src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("Other", other)

    merged = deepcopy(src).merge(other)
    print_yaml("merged", merged)

    print_yaml("Src after merge", src)
    print_yaml("Other after merge", other)

    assert verify_key_val(src, src_dict, 'merge')
    assert verify_key_val(src, src_dict, 'src')
    assert verify_key_val(src, src_dict, 'nested_dict.merge')
    assert verify_key_val(src, src_dict, 'nested_dict.src')

    with pytest.raises(KeyError):
        verify_key_val(src, src_dict, 'other')

    assert verify_key_val(merged, src_dict, 'src')
    assert verify_key_val(merged, other_dict, 'other')
    assert merged['merge'] == src_dict['merge'] + other_dict['merge']
    assert verify_key_val(merged, src_dict, 'nested_dict.src')
    assert verify_key_val(merged, other_dict, 'nested_dict.other')
Ejemplo n.º 3
0
def test_simple_merge():
    src_dict = {
        "merge": "src merge",
        "src": 'src only',
        'nested_dict': {
            'merge': 'nested src merge',
            'src': 'nested src only'
        }
    }

    other_dict = {
        "merge": "other merge",
        "other": 'other only',
        'nested_dict': {
            'merge': 'nested other merge',
            'other': 'nested other only'
        }
    }

    src = Configuration.from_dict(src_dict)
    print_yaml("Src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("Other", other)

    merged = deepcopy(src).merge(other)
    print_yaml("merged", merged)

    print_yaml("Src after merge", src)
    print_yaml("Other after merge", other)

    assert verify_key_val(src, src_dict, 'merge')
    assert verify_key_val(src, src_dict, 'src')
    assert verify_key_val(src, src_dict, 'nested_dict.merge')
    assert verify_key_val(src, src_dict, 'nested_dict.src')

    with pytest.raises(KeyError):
        verify_key_val(src, src_dict, 'other')

    assert verify_key_val(merged, other_dict, 'merge')
    assert verify_key_val(merged, src_dict, 'src')
    assert verify_key_val(merged, other_dict, 'other')
    return
Ejemplo n.º 4
0
def test_simple_merge():
    src_dict = {
        "merge": "src merge",
        "src": 'src only',
        'nested_dict': {
            'merge': 'nested src merge',
            'src': 'nested src only'
        }
    }

    other_dict = {
        "merge": "other merge",
        "other": 'other only',
        'nested_dict': {
            'merge': 'nested other merge',
            'other': 'nested other only'
        }
    }

    src = Configuration.from_dict(src_dict)
    print_yaml("Src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("Other", other)

    merged = deepcopy(src).merge(other)
    print_yaml("merged", merged)

    print_yaml("Src after merge", src)
    print_yaml("Other after merge", other)

    assert verify_key_val(src, src_dict, 'merge')
    assert verify_key_val(src, src_dict, 'src')
    assert verify_key_val(src, src_dict, 'nested_dict.merge')
    assert verify_key_val(src, src_dict, 'nested_dict.src')

    with pytest.raises(KeyError):
        verify_key_val(src, src_dict, 'other')

    assert verify_key_val(merged, other_dict, 'merge')
    assert verify_key_val(merged, src_dict, 'src')
    assert verify_key_val(merged, other_dict, 'other')
    return