Skip to content

Commit a7343e9

Browse files
authored
fix(rr): pytest takes ints and floats (#398)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 3b166e3 commit a7343e9

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

src/sp_repo_review/checks/pyproject.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def check(pyproject: dict[str, Any]) -> bool:
8989
```
9090
"""
9191
options = pyproject["tool"]["pytest"]["ini_options"]
92-
return "minversion" in options and int(options["minversion"].split(".")[0]) >= 6
92+
return (
93+
"minversion" in options
94+
and int(str(options["minversion"]).split(".")[0]) >= 6
95+
)
9396

9497

9598
class PP303(PyProject):

tests/test_checks.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from sp_repo_review._compat import tomllib
2+
from sp_repo_review.checks import pyproject
3+
4+
5+
def test_PP002_okay():
6+
toml = tomllib.loads("""
7+
[build-system]
8+
requires = ["setuptools"]
9+
build-backend = "setuptools.build_meta"
10+
""")
11+
assert pyproject.PP002.check(toml)
12+
13+
14+
def test_PP002_not_list():
15+
toml = tomllib.loads("""
16+
[build-system]
17+
requires = "setuptools"
18+
build-backend = "setuptools.build_meta"
19+
""")
20+
assert not pyproject.PP002.check(toml)
21+
22+
23+
def test_PP002_missing():
24+
toml = tomllib.loads("""
25+
[project]
26+
name = "hi"
27+
version = "1.0.0"
28+
""")
29+
assert not pyproject.PP002.check(toml)
30+
31+
32+
def test_PP003_no_wheel():
33+
toml = tomllib.loads("""
34+
[build-system]
35+
requires = ["setuptools"]
36+
build-backend = "setuptools.build_meta"
37+
""")
38+
assert pyproject.PP003.check(toml)
39+
40+
41+
def test_PP003_has_wheel():
42+
toml = tomllib.loads("""
43+
[build-system]
44+
requires = ["setuptools", "wheel"]
45+
build-backend = "setuptools.build_meta"
46+
""")
47+
assert not pyproject.PP003.check(toml)
48+
49+
50+
def test_PP302_okay_intstr():
51+
toml = tomllib.loads("""
52+
[tool.pytest.ini_options]
53+
minversion = "7"
54+
""")
55+
assert pyproject.PP302.check(toml)
56+
57+
58+
def test_PP302_okay_verstr():
59+
toml = tomllib.loads("""
60+
[tool.pytest.ini_options]
61+
minversion = "7.0.2"
62+
""")
63+
assert pyproject.PP302.check(toml)
64+
65+
66+
def test_PP302_okay_rawint():
67+
toml = tomllib.loads("""
68+
[tool.pytest.ini_options]
69+
minversion = 7
70+
""")
71+
assert pyproject.PP302.check(toml)
72+
73+
74+
def test_PP302_okay_rawfloat():
75+
toml = tomllib.loads("""
76+
[tool.pytest.ini_options]
77+
minversion = 7.0
78+
""")
79+
assert pyproject.PP302.check(toml)
80+
81+
82+
def test_PP302_missing():
83+
toml = tomllib.loads("""
84+
[tool.pytest]
85+
ini_options = {}
86+
""")
87+
assert not pyproject.PP302.check(toml)
88+
89+
90+
def test_PP302_too_low():
91+
toml = tomllib.loads("""
92+
[tool.pytest.ini_options]
93+
minversion = "5"
94+
""")
95+
assert not pyproject.PP302.check(toml)

0 commit comments

Comments
 (0)