-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathtest_families.py
More file actions
166 lines (146 loc) · 4.48 KB
/
test_families.py
File metadata and controls
166 lines (146 loc) · 4.48 KB
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
164
165
166
from sp_repo_review.families import get_families
def test_backend():
pyproject = {
"build-system": {
"requires": ["setuptools"],
"build-backend": "setuptools.build_meta",
},
}
families = get_families(pyproject, {})
assert families["general"].get("description") == (
"- Detected build backend: `setuptools.build_meta`"
)
def test_spdx_license():
pyproject = {
"project": {
"license": "MIT",
"classifiers": [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: BSD License",
],
},
}
families = get_families(pyproject, {})
assert families["general"].get("description") == (
"- Detected build backend: `MISSING`\n- SPDX license expression: `MIT`"
)
def test_classic_license():
pyproject = {
"project": {
"license": {"text": "Free-form"},
"classifiers": [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: BSD License",
],
},
}
families = get_families(pyproject, {})
assert families["general"].get("description") == (
"- Detected build backend: `MISSING`\n"
"- Detected license(s): MIT License, BSD License"
)
def test_ruff_all_rules_selected():
"""Test when all recommended rules are selected."""
ruff = {
"lint": {
"select": [
"ARG",
"B",
"C4",
"DTZ",
"EM",
"EXE",
"FA",
"FURB",
"G",
"I",
"ICN",
"NPY",
"PD",
"PERF",
"PGH",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"RET",
"RUF",
"SIM",
"SLOT",
"T20",
"TC",
"UP",
"YTT",
]
}
}
families = get_families({}, ruff)
assert families["ruff"].get("description") == "All mentioned rules selected"
def test_ruff_all_keyword():
"""Test when 'ALL' keyword is used."""
ruff = {"lint": {"select": ["ALL"]}}
families = get_families({}, ruff)
assert families["ruff"].get("description") == "All mentioned rules selected"
def test_ruff_missing_rules():
"""Test when some recommended rules are missing."""
ruff = {"lint": {"select": ["B", "I", "UP"]}}
families = get_families({}, ruff)
description = families["ruff"].get("description", "")
assert description.startswith("Rules mentioned in guide but not here:")
# Check that some missing rules are mentioned
assert "ARG" in description or "C4" in description or "DTZ" in description
def test_ruff_extend_select():
"""Test with extend-select instead of select."""
ruff = {"lint": {"extend-select": ["B", "I", "UP", "RUF"]}}
families = get_families({}, ruff)
description = families["ruff"].get("description", "")
assert description.startswith("Rules mentioned in guide but not here:")
# Verify that some rules are listed as missing
assert "ARG" in description or "C4" in description
def test_ruff_root_level_select():
"""Test with select at root level (not under lint)."""
ruff = {
"select": [
"ARG",
"B",
"C4",
"DTZ",
"EM",
"EXE",
"FA",
"FURB",
"G",
"I",
"ICN",
"NPY",
"PD",
"PERF",
"PGH",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"RET",
"RUF",
"SIM",
"SLOT",
"T20",
"TC",
"UP",
"YTT",
]
}
families = get_families({}, ruff)
assert families["ruff"].get("description") == "All mentioned rules selected"
def test_ruff_empty_config():
"""Test with empty ruff config."""
ruff: dict[str, object] = {}
families = get_families({}, ruff)
assert families["ruff"].get("description") == ""
def test_ruff_no_select():
"""Test ruff config without select or extend-select."""
ruff = {"lint": {"ignore": ["E501"]}}
families = get_families({}, ruff)
assert families["ruff"].get("description") == ""