File: test_pyutils.py

package info (click to toggle)
strawberry-graphql-django 0.62.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,968 kB
  • sloc: python: 27,530; sh: 17; makefile: 16
file content (88 lines) | stat: -rw-r--r-- 2,329 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from strawberry_django.utils.pyutils import (
    dicttree_insersection_differs,
    dicttree_merge,
)


def test_dicctree_merge():
    assert dicttree_merge(
        {
            "foo": 1,
            "bar": 2,
            "baz": 7,
            "sub1": {
                "a": "asub1",
                "b": "bsub1",
                "c": "csub1",
            },
            "sub2": {
                "a": "asub2",
                "b": "bsub2",
                "c": "csub2",
            },
        },
        {
            "bar": 3,
            "bin": 4,
            "sub1": {
                "a": "force_asub1",
                "d": "force_dsub1",
            },
            "sub3": {
                "a": "asub3",
                "b": "bsub3",
                "c": "csub3",
            },
        },
    ) == {
        "foo": 1,
        "bar": 3,
        "baz": 7,
        "bin": 4,
        "sub1": {
            "a": "force_asub1",
            "b": "bsub1",
            "c": "csub1",
            "d": "force_dsub1",
        },
        "sub2": {
            "a": "asub2",
            "b": "bsub2",
            "c": "csub2",
        },
        "sub3": {
            "a": "asub3",
            "b": "bsub3",
            "c": "csub3",
        },
    }


def test_dicctree_intersection_differs():
    assert not dicttree_insersection_differs({"a": 1}, {"b": 1})
    assert not dicttree_insersection_differs({"a": 1}, {"b": 2})
    assert not dicttree_insersection_differs({"a": 1}, {"a": 1})
    assert not dicttree_insersection_differs({"a": 1}, {"a": 1, "b": 1})
    assert not dicttree_insersection_differs(
        {"a": 1, "c": {"foobar": 3}},
        {"a": 1, "b": 1},
    )
    assert not dicttree_insersection_differs(
        {"a": 1, "c": {"foobar": 1}},
        {"a": 1, "b": 1, "c": {"yyy": "abc"}},
    )
    assert not dicttree_insersection_differs(
        {"a": 1, "c": {"foobar": 1}},
        {"a": 1, "b": 1, "c": {"foobar": 1}},
    )

    assert dicttree_insersection_differs({"a": 1}, {"a": 2})
    assert dicttree_insersection_differs({"a": 1}, {"a": 2, "b": 1})
    assert dicttree_insersection_differs(
        {"a": 1, "c": {"foobar": 1}},
        {"a": 2, "c": {"foobar": 1}},
    )
    assert dicttree_insersection_differs(
        {"a": 1, "c": {"foobar": 1}},
        {"a": 1, "c": {"foobar": 2}},
    )