@@ -107,35 +107,43 @@ def test_handle_str(test, exp) -> None:
107
107
assert parse_str_version (test , proj_name = "foo" , file_path = "" , extras_str = "" ) == f"foo { exp } "
108
108
109
109
110
+ def assert_equal_requirements (actual : str | None , expected : str ) -> None :
111
+ assert actual is not None
112
+ assert PipRequirement .parse (expected ) == PipRequirement .parse (actual )
113
+
114
+
110
115
def test_add_markers () -> None :
111
116
attr_mark = PyprojectAttr ({"markers" : "platform_python_implementation == 'CPython'" })
112
- assert (
113
- add_markers ("foo==1.0.0" , attr_mark , "somepath" )
114
- == "foo==1.0.0;(platform_python_implementation == 'CPython')"
117
+ assert_equal_requirements (
118
+ add_markers ("foo==1.0.0" , attr_mark , "somepath" ),
119
+ "foo==1.0.0;(platform_python_implementation == 'CPython')" ,
115
120
)
116
121
117
122
attr_mark_adv = PyprojectAttr (
118
123
{"markers" : "platform_python_implementation == 'CPython' or sys_platform == 'win32'" }
119
124
)
120
- assert (
121
- add_markers ("foo==1.0.0" , attr_mark_adv , "somepath" )
122
- == "foo==1.0.0;(platform_python_implementation == 'CPython' or sys_platform == 'win32')"
125
+ assert_equal_requirements (
126
+ add_markers ("foo==1.0.0" , attr_mark_adv , "somepath" ),
127
+ "foo==1.0.0;(platform_python_implementation == 'CPython' or sys_platform == 'win32')" ,
123
128
)
124
129
attr_basic_both = PyprojectAttr ({"python" : "3.6" })
125
130
attr_basic_both .update (attr_mark )
126
131
127
- assert (
128
- add_markers ("foo==1.0.0" , attr_basic_both , "somepath" )
129
- == "foo==1.0.0;(platform_python_implementation == 'CPython') and (python_version == '3.6')"
132
+ assert_equal_requirements (
133
+ add_markers ("foo==1.0.0" , attr_basic_both , "somepath" ),
134
+ "foo==1.0.0;(platform_python_implementation == 'CPython') and (python_version == '3.6')" ,
130
135
)
131
136
attr_adv_py_both = PyprojectAttr (
132
137
{"python" : "^3.6" , "markers" : "platform_python_implementation == 'CPython'" }
133
138
)
134
- assert add_markers ("foo==1.0.0" , attr_adv_py_both , "somepath" ) == softwrap (
135
- """
136
- foo==1.0.0;(platform_python_implementation == 'CPython') and
137
- (python_version >= '3.6' and python_version< '4.0')
138
- """
139
+ assert_equal_requirements (
140
+ add_markers ("foo==1.0.0" , attr_adv_py_both , "somepath" ),
141
+ softwrap (
142
+ """
143
+ foo==1.0.0;(platform_python_implementation == 'CPython') and
144
+ (python_version >= '3.6' and python_version< '4.0')
145
+ """
146
+ ),
139
147
)
140
148
141
149
attr_adv_both = PyprojectAttr (
@@ -144,11 +152,14 @@ def test_add_markers() -> None:
144
152
"markers" : "platform_python_implementation == 'CPython' or sys_platform == 'win32'" ,
145
153
}
146
154
)
147
- assert add_markers ("foo==1.0.0" , attr_adv_both , "somepath" ) == softwrap (
148
- """
149
- foo==1.0.0;(platform_python_implementation == 'CPython' or
150
- sys_platform == 'win32') and (python_version >= '3.6' and python_version< '4.0')
151
- """
155
+ assert_equal_requirements (
156
+ add_markers ("foo==1.0.0" , attr_adv_both , "somepath" ),
157
+ softwrap (
158
+ """
159
+ foo==1.0.0;(platform_python_implementation == 'CPython' or
160
+ sys_platform == 'win32') and (python_version >= '3.6' and python_version< '4.0')
161
+ """
162
+ ),
152
163
)
153
164
154
165
@@ -195,9 +206,9 @@ def test_handle_git(empty_pyproject_toml: PyProjectToml) -> None:
195
206
def assert_git (extra_opts : PyprojectAttr , suffix : str ) -> None :
196
207
attr = PyprojectAttr ({"git" : "https://github.com/requests/requests.git" })
197
208
attr .update (extra_opts )
198
- assert (
199
- handle_dict_attr ("requests" , attr , empty_pyproject_toml )
200
- == f"requests @ git+https://github.com/requests/requests.git{ suffix } "
209
+ assert_equal_requirements (
210
+ handle_dict_attr ("requests" , attr , empty_pyproject_toml ),
211
+ f"requests @ git+https://github.com/requests/requests.git{ suffix } " ,
201
212
)
202
213
203
214
assert_git ({}, "" )
@@ -212,7 +223,7 @@ def assert_git(extra_opts: PyprojectAttr, suffix: str) -> None:
212
223
"python" : "3.6" ,
213
224
}
214
225
),
215
- "@main;(platform_python_implementation == 'CPython') and (python_version == '3.6')" ,
226
+ "@main ;(platform_python_implementation == 'CPython') and (python_version == '3.6')" ,
216
227
)
217
228
218
229
@@ -256,53 +267,53 @@ def test_handle_path_arg(tmp_path: Path) -> None:
256
267
file_attr_extras = PyprojectAttr ({"path" : "../../my_py_proj.whl" , "extras" : ["extra1" ]})
257
268
dir_attr = PyprojectAttr ({"path" : "../../my_py_proj" })
258
269
259
- assert (
260
- handle_dict_attr ("my_py_proj" , file_attr , one_pyproject_toml )
261
- == f"my_py_proj @ file://{ external_file } "
270
+ assert_equal_requirements (
271
+ handle_dict_attr ("my_py_proj" , file_attr , one_pyproject_toml ),
272
+ f"my_py_proj @ file://{ external_file } " ,
262
273
)
263
274
264
- assert (
265
- handle_dict_attr ("my_py_proj" , file_attr_extras , one_pyproject_toml )
266
- == f"my_py_proj[extra1] @ file://{ external_file } "
275
+ assert_equal_requirements (
276
+ handle_dict_attr ("my_py_proj" , file_attr_extras , one_pyproject_toml ),
277
+ f"my_py_proj[extra1] @ file://{ external_file } " ,
267
278
)
268
279
269
- assert (
270
- handle_dict_attr ("my_py_proj" , file_attr_mark , one_pyproject_toml )
271
- == f"my_py_proj @ file://{ external_file } ;(os_name=='darwin')"
280
+ assert_equal_requirements (
281
+ handle_dict_attr ("my_py_proj" , file_attr_mark , one_pyproject_toml ),
282
+ f"my_py_proj @ file://{ external_file } ;(os_name=='darwin')" ,
272
283
)
273
284
274
- assert (
275
- handle_dict_attr ("my_py_proj" , file_attr , two_pyproject_toml )
276
- == f"my_py_proj @ file://{ internal_file } "
285
+ assert_equal_requirements (
286
+ handle_dict_attr ("my_py_proj" , file_attr , two_pyproject_toml ),
287
+ f"my_py_proj @ file://{ internal_file } " ,
277
288
)
278
289
279
- assert (
280
- handle_dict_attr ("my_py_proj" , dir_attr , one_pyproject_toml )
281
- == f"my_py_proj @ file://{ external_project } "
290
+ assert_equal_requirements (
291
+ handle_dict_attr ("my_py_proj" , dir_attr , one_pyproject_toml ),
292
+ f"my_py_proj @ file://{ external_project } " ,
282
293
)
283
294
284
295
assert handle_dict_attr ("my_py_proj" , dir_attr , two_pyproject_toml ) is None
285
296
286
297
287
298
def test_handle_url_arg (empty_pyproject_toml : PyProjectToml ) -> None :
288
299
attr = PyprojectAttr ({"url" : "https://my-site.com/mydep.whl" })
289
- assert (
290
- handle_dict_attr ("my_py_proj" , attr , empty_pyproject_toml )
291
- == "my_py_proj @ https://my-site.com/mydep.whl"
300
+ assert_equal_requirements (
301
+ handle_dict_attr ("my_py_proj" , attr , empty_pyproject_toml ),
302
+ "my_py_proj @ https://my-site.com/mydep.whl" ,
292
303
)
293
304
294
305
attr_with_extra = PyprojectAttr ({"extras" : ["extra1" ]})
295
306
attr_with_extra .update (attr )
296
- assert (
297
- handle_dict_attr ("my_py_proj" , attr_with_extra , empty_pyproject_toml )
298
- == "my_py_proj[extra1] @ https://my-site.com/mydep.whl"
307
+ assert_equal_requirements (
308
+ handle_dict_attr ("my_py_proj" , attr_with_extra , empty_pyproject_toml ),
309
+ "my_py_proj[extra1] @ https://my-site.com/mydep.whl" ,
299
310
)
300
311
301
312
attr_with_mark = PyprojectAttr ({"markers" : "os_name=='darwin'" })
302
313
attr_with_mark .update (attr )
303
- assert (
304
- handle_dict_attr ("my_py_proj" , attr_with_mark , empty_pyproject_toml )
305
- == "my_py_proj @ https://my-site.com/mydep.whl;(os_name=='darwin')"
314
+ assert_equal_requirements (
315
+ handle_dict_attr ("my_py_proj" , attr_with_mark , empty_pyproject_toml ),
316
+ "my_py_proj @ https://my-site.com/mydep.whl ;(os_name=='darwin')" ,
306
317
)
307
318
308
319
@@ -314,7 +325,9 @@ def test_version_only(empty_pyproject_toml: PyProjectToml) -> None:
314
325
def test_py_constraints (empty_pyproject_toml : PyProjectToml ) -> None :
315
326
def assert_py_constraints (py_req : str , suffix : str ) -> None :
316
327
attr = PyprojectAttr ({"version" : "1.2.3" , "python" : py_req })
317
- assert handle_dict_attr ("foo" , attr , empty_pyproject_toml ) == f"foo ==1.2.3;{ suffix } "
328
+ assert_equal_requirements (
329
+ handle_dict_attr ("foo" , attr , empty_pyproject_toml ), f"foo ==1.2.3;{ suffix } "
330
+ )
318
331
319
332
assert_py_constraints ("3.6" , "(python_version == '3.6')" )
320
333
assert_py_constraints ("3.6 || 3.7" , "((python_version == '3.6') or (python_version == '3.7'))" )
0 commit comments