File: test_resolve_func.py

package info (click to toggle)
python-dependency-groups 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 132 kB
  • sloc: python: 581; makefile: 3
file content (163 lines) | stat: -rw-r--r-- 3,859 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import pytest

from dependency_groups import resolve


def test_empty_group():
    groups = {"test": []}
    assert resolve(groups, "test") == ()


def test_str_list_group():
    groups = {"test": ["pytest"]}
    assert resolve(groups, "test") == ("pytest",)


def test_single_include_group():
    groups = {
        "test": [
            "pytest",
            {"include-group": "runtime"},
        ],
        "runtime": ["sqlalchemy"],
    }
    assert set(resolve(groups, "test")) == {"pytest", "sqlalchemy"}


def test_sdual_include_group():
    groups = {
        "test": [
            "pytest",
        ],
        "runtime": ["sqlalchemy"],
    }
    assert set(resolve(groups, "test", "runtime")) == {"pytest", "sqlalchemy"}


def test_normalized_group_name():
    groups = {
        "TEST": ["pytest"],
    }
    assert resolve(groups, "test") == ("pytest",)


def test_malformed_group_data():
    groups = [{"test": ["pytest"]}]
    with pytest.raises(TypeError, match="Dependency Groups table is not a mapping"):
        resolve(groups, "test")


def test_malformed_group_query():
    groups = {"test": ["pytest"]}
    with pytest.raises(TypeError, match="Dependency group name is not a str"):
        resolve(groups, 0)


def test_no_such_group_name():
    groups = {
        "test": ["pytest"],
    }
    with pytest.raises(LookupError, match="'testing' not found"):
        resolve(groups, "testing")


def test_duplicate_normalized_name():
    groups = {
        "test": ["pytest"],
        "TEST": ["nose2"],
    }
    with pytest.raises(
        ValueError,
        match=r"Duplicate dependency group names: test \((test, TEST)|(TEST, test)\)",
    ):
        resolve(groups, "test")


def test_cyclic_include():
    groups = {
        "group1": [
            {"include-group": "group2"},
        ],
        "group2": [
            {"include-group": "group1"},
        ],
    }
    with pytest.raises(
        ValueError,
        match=(
            "Cyclic dependency group include while resolving group1: "
            "group1 -> group2, group2 -> group1"
        ),
    ):
        resolve(groups, "group1")


def test_cyclic_include_many_steps():
    groups = {}
    for i in range(100):
        groups[f"group{i}"] = [{"include-group": f"group{i+1}"}]
    groups["group100"] = [{"include-group": "group0"}]
    with pytest.raises(
        ValueError,
        match="Cyclic dependency group include while resolving group0:",
    ):
        resolve(groups, "group0")


def test_cyclic_include_self():
    groups = {
        "group1": [
            {"include-group": "group1"},
        ],
    }
    with pytest.raises(
        ValueError,
        match=(
            "Cyclic dependency group include while resolving group1: "
            "group1 includes itself"
        ),
    ):
        resolve(groups, "group1")


def test_cyclic_include_ring_under_root():
    groups = {
        "root": [
            {"include-group": "group1"},
        ],
        "group1": [
            {"include-group": "group2"},
        ],
        "group2": [
            {"include-group": "group1"},
        ],
    }
    with pytest.raises(
        ValueError,
        match=(
            "Cyclic dependency group include while resolving root: "
            "group1 -> group2, group2 -> group1"
        ),
    ):
        resolve(groups, "root")


def test_non_list_data():
    groups = {"test": "pytest, coverage"}
    with pytest.raises(TypeError, match="Dependency group 'test' is not a list"):
        resolve(groups, "test")


@pytest.mark.parametrize(
    "item",
    (
        {},
        {"foo": "bar"},
        {"include-group": "testing", "foo": "bar"},
        object(),
    ),
)
def test_unknown_object_shape(item):
    groups = {"test": [item]}
    with pytest.raises(ValueError, match="Invalid dependency group item:"):
        resolve(groups, "test")