File: test_full.py

package info (click to toggle)
python-deepmerge 0.0.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 188 kB
  • sloc: python: 370; makefile: 195
file content (55 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from deepmerge import (
    always_merger,
    conservative_merger,
    merge_or_raise,
)


def test_fill_missing_value():
    base = {
        "foo": 0,
        "baz": 2
    }
    nxt = {
        "bar": 1
    }
    always_merger.merge(base, nxt)
    assert base == {
        "foo": 0, "bar": 1, "baz": 2
    }


def test_merge_or_raise_raises_exception():
    base = {
        "foo": 0,
        "baz": 2
    }
    nxt = {
        "bar": 1,
        "foo": "a string!"
    }
    with pytest.raises(Exception):
        merge_or_raise.merge(base, nxt)


@pytest.mark.parametrize("base, nxt, expected", [
    ("dooby", "fooby", "dooby"),
    (-10, "goo", -10)
])
def test_use_existing(base, nxt, expected):
    assert conservative_merger.merge(base, nxt) == expected

def test_example():
    base = {"foo": "value", "baz": ["a"]}
    next = {"bar": "value2", "baz": ["b"]}

    always_merger.merge(base, next)

    assert base == {
        "foo": "value",
        "bar": "value2",
        "baz": ["a", "b"]
    }