12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
import logging
15
- import textwrap
16
15
17
- import build
18
16
import pretend
19
17
import pytest
20
18
@@ -50,45 +48,30 @@ def test_fails_no_distributions(caplog):
50
48
]
51
49
52
50
53
- def build_package (src_path , project_files , distribution = "sdist" ):
54
- """
55
- Build a source distribution similar to `python3 -m build --sdist`.
56
-
57
- Returns the absolute path of the built distribution.
58
- """
59
- project_files = {
60
- "pyproject.toml" : (
61
- """
62
- [build-system]
63
- requires = ["setuptools"]
64
- build-backend = "setuptools.build_meta"
65
- """
66
- ),
67
- ** project_files ,
68
- }
69
-
70
- for filename , content in project_files .items ():
71
- (src_path / filename ).write_text (textwrap .dedent (content ))
72
-
73
- builder = build .ProjectBuilder (src_path )
74
- return builder .build (distribution , str (src_path / "dist" ))
51
+ def build_sdist_with_metadata (path , metadata ):
52
+ name = "test"
53
+ version = "1.2.3"
54
+ sdist = helpers .build_archive (
55
+ path ,
56
+ f"{ name } -{ version } " ,
57
+ "tar.gz" ,
58
+ {
59
+ f"{ name } -{ version } /README" : "README" ,
60
+ f"{ name } -{ version } /PKG-INFO" : metadata ,
61
+ },
62
+ )
63
+ return str (sdist )
75
64
76
65
77
- @pytest .mark .parametrize ("distribution" , ["sdist" , "wheel" ])
78
66
@pytest .mark .parametrize ("strict" , [False , True ])
79
- def test_warns_missing_description (distribution , strict , tmp_path , capsys , caplog ):
80
- sdist = build_package (
67
+ def test_warns_missing_description (strict , tmp_path , capsys , caplog ):
68
+ sdist = build_sdist_with_metadata (
81
69
tmp_path ,
82
- {
83
- "setup.cfg" : (
84
- """
85
- [metadata]
86
- name = test-package
87
- version = 0.0.1
88
- """
89
- ),
90
- },
91
- distribution = distribution ,
70
+ """\
71
+ Metadata-Version: 2.1
72
+ Name: test
73
+ Version: 1.2.3
74
+ """ ,
92
75
)
93
76
94
77
assert check .check ([sdist ], strict = strict ) is strict
@@ -111,54 +94,19 @@ def test_warns_missing_description(distribution, strict, tmp_path, capsys, caplo
111
94
]
112
95
113
96
114
- def test_warns_missing_file (tmp_path , capsys , caplog ):
115
- sdist = build_package (
97
+ def test_fails_rst_syntax_error (tmp_path , capsys , caplog ):
98
+ sdist = build_sdist_with_metadata (
116
99
tmp_path ,
117
- {
118
- "setup.cfg" : (
119
- """
120
- [metadata]
121
- name = test-package
122
- version = 0.0.1
123
- long_description = file:README.rst
124
- long_description_content_type = text/x-rst
125
- """
126
- ),
127
- },
128
- )
100
+ """\
101
+ Metadata-Version: 2.1
102
+ Name: test-package
103
+ Version: 1.2.3
104
+ Description-Content-Type: text/x-rst
129
105
130
- assert not check .check ([sdist ])
131
106
132
- assert capsys . readouterr (). out == f"Checking { sdist } : PASSED with warnings \n "
107
+ ============
133
108
134
- assert caplog .record_tuples == [
135
- (
136
- "twine.commands.check" ,
137
- logging .WARNING ,
138
- "`long_description` missing." ,
139
- ),
140
- ]
141
-
142
-
143
- def test_fails_rst_syntax_error (tmp_path , capsys , caplog ):
144
- sdist = build_package (
145
- tmp_path ,
146
- {
147
- "setup.cfg" : (
148
- """
149
- [metadata]
150
- name = test-package
151
- version = 0.0.1
152
- long_description = file:README.rst
153
- long_description_content_type = text/x-rst
154
- """
155
- ),
156
- "README.rst" : (
157
- """
158
- ============
159
- """
160
- ),
161
- },
109
+ """ ,
162
110
)
163
111
164
112
assert check .check ([sdist ])
@@ -177,25 +125,17 @@ def test_fails_rst_syntax_error(tmp_path, capsys, caplog):
177
125
178
126
179
127
def test_fails_rst_no_content (tmp_path , capsys , caplog ):
180
- sdist = build_package (
128
+ sdist = build_sdist_with_metadata (
181
129
tmp_path ,
182
- {
183
- "setup.cfg" : (
184
- """
185
- [metadata]
186
- name = test-package
187
- version = 0.0.1
188
- long_description = file:README.rst
189
- long_description_content_type = text/x-rst
190
- """
191
- ),
192
- "README.rst" : (
193
- """
194
- test-package
195
- ============
196
- """
197
- ),
198
- },
130
+ """\
131
+ Metadata-Version: 2.1
132
+ Name: test-package
133
+ Version: 1.2.3
134
+ Description-Content-Type: text/x-rst
135
+
136
+ test-package
137
+ ============
138
+ """ ,
199
139
)
200
140
201
141
assert check .check ([sdist ])
@@ -214,27 +154,19 @@ def test_fails_rst_no_content(tmp_path, capsys, caplog):
214
154
215
155
216
156
def test_passes_rst_description (tmp_path , capsys , caplog ):
217
- sdist = build_package (
157
+ sdist = build_sdist_with_metadata (
218
158
tmp_path ,
219
- {
220
- "setup.cfg" : (
221
- """
222
- [metadata]
223
- name = test-package
224
- version = 0.0.1
225
- long_description = file:README.rst
226
- long_description_content_type = text/x-rst
227
- """
228
- ),
229
- "README.rst" : (
230
- """
231
- test-package
232
- ============
233
-
234
- A test package.
235
- """
236
- ),
237
- },
159
+ """\
160
+ Metadata-Version: 2.1
161
+ Name: test-package
162
+ Version: 1.2.3
163
+ Description-Content-Type: text/x-rst
164
+
165
+ test-package
166
+ ============
167
+
168
+ A test package.
169
+ """ ,
238
170
)
239
171
240
172
assert not check .check ([sdist ])
@@ -246,26 +178,18 @@ def test_passes_rst_description(tmp_path, capsys, caplog):
246
178
247
179
@pytest .mark .parametrize ("content_type" , ["text/markdown" , "text/plain" ])
248
180
def test_passes_markdown_description (content_type , tmp_path , capsys , caplog ):
249
- sdist = build_package (
181
+ sdist = build_sdist_with_metadata (
250
182
tmp_path ,
251
- {
252
- "setup.cfg" : (
253
- f"""
254
- [metadata]
255
- name = test-package
256
- version = 0.0.1
257
- long_description = file:README.md
258
- long_description_content_type = { content_type }
259
- """
260
- ),
261
- "README.md" : (
262
- """
263
- # test-package
264
-
265
- A test package.
266
- """
267
- ),
268
- },
183
+ f"""\
184
+ Metadata-Version: 2.1
185
+ Name: test-package
186
+ Version: 1.2.3
187
+ Description-Content-Type: { content_type }
188
+
189
+ # test-package
190
+
191
+ A test package.
192
+ """ ,
269
193
)
270
194
271
195
assert not check .check ([sdist ])
0 commit comments