File: test_merge_config.py

package info (click to toggle)
python-briefcase 0.3.22-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,296 kB
  • sloc: python: 59,405; makefile: 57
file content (141 lines) | stat: -rw-r--r-- 3,565 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from briefcase.config import merge_config


def test_merge_no_options_no_data():
    """If there are no initial options or new additional options, nothing changes."""
    config = {"other": 1234}

    merge_config(config, {})

    assert config == {"other": 1234}


def test_merge_no_data():
    """If there are no new options, nothing changes."""
    config = {
        "requires": ["first", "second"],
        "permission": {"up": True, "down": False},
        "other": 1234,
    }

    merge_config(config, {})

    assert config == {
        "requires": ["first", "second"],
        "permission": {"up": True, "down": False},
        "other": 1234,
    }


def test_merge_no_option():
    """If there are no existing options, the new option become the entire value."""
    config = {"other": 1234}

    merge_config(
        config,
        {
            "requires": ["third", "fourth"],
            "permission": {"left": True, "right": False},
        },
    )

    assert config == {
        "requires": ["third", "fourth"],
        "permission": {"left": True, "right": False},
        "other": 1234,
    }


def test_merge():
    """If there are existing options and new options, merge."""
    config = {
        "requires": ["first", "second"],
        "permission": {"up": True, "down": False},
        "other": 1234,
    }

    merge_config(
        config,
        {
            "requires": ["third", "fourth"],
            "permission": {"left": True, "right": False},
            "other": 5678,
        },
    )

    assert config == {
        "requires": ["first", "second", "third", "fourth"],
        "permission": {"up": True, "down": False, "left": True, "right": False},
        "other": 5678,
    }


def test_merge_collision():
    """If there are repeated options, lists are appended, dictionaries are updated and
    new options, merge."""
    config = {
        "requires": ["first", "second"],
        "permission": {"up": True, "down": False},
        "other": 1234,
    }

    merge_config(
        config,
        {
            "requires": ["second", "fourth"],
            "permission": {"down": True, "right": False},
            "other": 5678,
        },
    )

    assert config == {
        "requires": ["first", "second", "second", "fourth"],
        "permission": {"up": True, "down": True, "right": False},
        "other": 5678,
    }


def test_convert_base_definition():
    """The merge operation succeeds when called on itself."""
    config = {
        "requires": ["first", "second"],
        "permission": {"up": True, "down": False},
        "other": 1234,
    }

    merge_config(config, config)

    assert config == {
        "requires": ["first", "second"],
        "permission": {"up": True, "down": False},
        "other": 1234,
    }


def test_merged_keys():
    """There are multiple mergeable keys."""
    config = {
        "requires": ["first", "second"],
        "sources": ["a", "b"],
        "permission": {"up": True, "down": False},
        "non-merge": ["1", "2"],
        "other": 1234,
    }

    merge_config(
        config,
        {
            "requires": ["third", "fourth"],
            "permission": {"left": True, "right": False},
            "sources": ["c", "d"],
            "non-merge": ["3", "4"],
        },
    )

    assert config == {
        "requires": ["first", "second", "third", "fourth"],
        "sources": ["a", "b", "c", "d"],
        "permission": {"up": True, "down": False, "left": True, "right": False},
        "non-merge": ["3", "4"],
        "other": 1234,
    }