Example #1
0
def test_patch_complex():

    c = ConfigDict({
        "a": 1,
        "b": {
            "x": 3,
            "y": 4
        },
        "c": {
            "x": 5,
            "y": 6
        },
        "d": {
            "x": 7,
            "y": 8
        }
    })
    d = {"a": 2, "b": {"z": 5}, "c": [1, 2], "d": {"y": 9}}
    c.patch(d)
    assert c.a == 2
    assert c.b.x == 3
    assert c.b.y == 4
    assert c.b.z == 5
    assert c.c == [1, 2]
    assert c.d.x == 7
    assert c.d.y == 9
Example #2
0
def test_operator():
    c = ConfigDict({"a": 1, "b": {"c": 3}})
    from operator import attrgetter
    assert attrgetter('b.c')(c) == 3
Example #3
0
def test_patch_simple():
    c = ConfigDict({"a": 1, "b": {"c": 3, "e": 4}})
    d = {"b": {"e": 5}}
    c.patch(d)
    assert c.b.c == 3
    assert c.b.e == 5
Example #4
0
def test_copy():
    c = ConfigDict({"a": 1, "b": {"c": 3}})
    d = c.copy()
    assert c == d
    c.b.c = 4
    assert c != d
Example #5
0
def test_list():
    c = ConfigDict({"a": 1, "b": {"c": 3}})
    c.d = [dict(e=1), dict(f=2)]
    assert c.d[0].e == 1
    assert c.d[1].f == 2
Example #6
0
def test_two_levels_patch():
    c = ConfigDict({"a": 1, "b": {"c": 3}})
    d = {"d": 5}
    c.b.d = d
    assert c.b.c == 3
    assert c.b.d == d
Example #7
0
def test_two_levels_assignment():
    c = ConfigDict({"a": 1, "b": {"c": 3}})
    d = {"d": 5}
    c.b = d
    assert c.b.d == 5
    assert c.b == d
Example #8
0
def test_two_levels():
    c = ConfigDict({"a": 1, "b": {"c": 3}})
    assert c.b.c == 3
Example #9
0
def test_change():
    c = ConfigDict({"a": 1})
    assert c.a == 1
    c.a = 2
    assert c["a"] == 2
Example #10
0
def test_init():
    c = ConfigDict({"a": 1})
    assert c.a == 1
    assert c["a"] == 1