forked from pypa/cibuildwheel
/
projectfiles_test.py
181 lines (143 loc) · 4.6 KB
/
projectfiles_test.py
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from textwrap import dedent
from cibuildwheel.projectfiles import get_requires_python_str, setup_py_python_requires
def test_read_setup_py_simple(tmp_path):
with open(tmp_path / "setup.py", "w") as f:
f.write(
dedent(
"""
from setuptools import setup
setup(
name = "hello",
other = 23,
example = ["item", "other"],
python_requires = "1.23",
)
"""
)
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) == "1.23"
assert get_requires_python_str(tmp_path) == "1.23"
def test_read_setup_py_full(tmp_path):
with open(tmp_path / "setup.py", "w", encoding="utf8") as f:
f.write(
dedent(
"""
import setuptools
setuptools.randomfunc()
setuptools.setup(
name = "hello",
description = "≥“”ü",
other = 23,
example = ["item", "other"],
python_requires = "1.24",
)
"""
)
)
assert (
setup_py_python_requires(tmp_path.joinpath("setup.py").read_text(encoding="utf8")) == "1.24"
)
assert get_requires_python_str(tmp_path) == "1.24"
def test_read_setup_py_assign(tmp_path):
with open(tmp_path / "setup.py", "w") as f:
f.write(
dedent(
"""
from setuptools import setup
REQUIRES = "3.21"
setuptools.setup(
name = "hello",
other = 23,
example = ["item", "other"],
python_requires = REQUIRES,
)
"""
)
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) is None
assert get_requires_python_str(tmp_path) is None
def test_read_setup_py_None(tmp_path):
with open(tmp_path / "setup.py", "w") as f:
f.write(
dedent(
"""
from setuptools import setup
REQUIRES = None
setuptools.setup(
name = "hello",
other = 23,
example = ["item", "other"],
python_requires = None,
)
"""
)
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) is None
assert get_requires_python_str(tmp_path) is None
def test_read_setup_py_empty(tmp_path):
with open(tmp_path / "setup.py", "w") as f:
f.write(
dedent(
"""
from setuptools import setup
REQUIRES = "3.21"
setuptools.setup(
name = "hello",
other = 23,
example = ["item", "other"],
)
"""
)
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) is None
assert get_requires_python_str(tmp_path) is None
def test_read_setup_cfg(tmp_path):
with open(tmp_path / "setup.cfg", "w") as f:
f.write(
dedent(
"""
[options]
python_requires = 1.234
[metadata]
something = other
"""
)
)
assert get_requires_python_str(tmp_path) == "1.234"
def test_read_setup_cfg_empty(tmp_path):
with open(tmp_path / "setup.cfg", "w") as f:
f.write(
dedent(
"""
[options]
other = 1.234
[metadata]
something = other
"""
)
)
assert get_requires_python_str(tmp_path) is None
def test_read_pyproject_toml(tmp_path):
with open(tmp_path / "pyproject.toml", "w") as f:
f.write(
dedent(
"""
[project]
requires-python = "1.654"
[tool.cibuildwheel]
something = "other"
"""
)
)
assert get_requires_python_str(tmp_path) == "1.654"
def test_read_pyproject_toml_empty(tmp_path):
with open(tmp_path / "pyproject.toml", "w") as f:
f.write(
dedent(
"""
[project]
other = 1.234
"""
)
)
assert get_requires_python_str(tmp_path) is None