1
+ import platform
1
2
import sys
2
3
import textwrap
3
4
from pathlib import Path
@@ -206,6 +207,10 @@ def _setup_package_for_editable_layout_tests(
206
207
("editable" , "editable_mode" ), [(False , "" ), (True , "redirect" ), (True , "inplace" )]
207
208
)
208
209
def test_direct_import (monkeypatch , tmp_path , editable , editable_mode , isolated ):
210
+ # TODO: Investigate these failures
211
+ if platform .system () == "Windows" and editable_mode == "inplace" :
212
+ pytest .xfail ("Windows fails to import the top-level extension module" )
213
+
209
214
_setup_package_for_editable_layout_tests ( # type: ignore[no-untyped-call]
210
215
monkeypatch , tmp_path , editable , editable_mode , isolated
211
216
)
@@ -218,114 +223,62 @@ def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated)
218
223
@pytest .mark .configure
219
224
@pytest .mark .integration
220
225
@pytest .mark .parametrize (
221
- ("editable" , "editable_mode" , "check" ),
226
+ ("editable" , "editable_mode" ),
222
227
[
223
- # Without editable
224
- (False , "" , "isinstance(files(pkg), pathlib.Path)" ),
225
- (False , "" , "any(str(x).endswith('.so') for x in files(pkg).iterdir())" ),
226
- (False , "" , "isinstance(files(pkg.sub_a), pathlib.Path)" ),
227
- (
228
- False ,
229
- "" ,
230
- "any(str(x).endswith('.so') for x in files(pkg.sub_a).iterdir())" ,
231
- ),
232
- (False , "" , "isinstance(files(pkg.sub_b), pathlib.Path)" ),
233
- (
234
- False ,
235
- "" ,
236
- "any(str(x).endswith('.so') for x in files(pkg.sub_b).iterdir())" ,
237
- ),
238
- (False , "" , "isinstance(files(pkg.sub_b.sub_c), pathlib.Path)" ),
239
- (
240
- False ,
241
- "" ,
242
- "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_c).iterdir())" ,
243
- ),
244
- (False , "" , "isinstance(files(pkg.sub_b.sub_d), pathlib.Path)" ),
245
- (
246
- False ,
247
- "" ,
248
- "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_d).iterdir())" ,
249
- ),
250
- # Editable redirect
251
- (True , "redirect" , "isinstance(files(pkg), pathlib.Path)" ),
252
- pytest .param (
253
- True ,
254
- "redirect" ,
255
- "any(str(x).endswith('.so') for x in files(pkg).iterdir())" ,
256
- marks = pytest .mark .xfail ,
257
- ),
258
- (True , "redirect" , "isinstance(files(pkg.sub_a), pathlib.Path)" ),
259
- pytest .param (
260
- True ,
261
- "redirect" ,
262
- "any(str(x).endswith('.so') for x in files(pkg.sub_a).iterdir())" ,
263
- marks = pytest .mark .xfail ,
264
- ),
265
- (True , "redirect" , "isinstance(files(pkg.sub_b), pathlib.Path)" ),
266
- pytest .param (
267
- True ,
268
- "redirect" ,
269
- "any(str(x).endswith('.so') for x in files(pkg.sub_b).iterdir())" ,
270
- marks = pytest .mark .xfail ,
271
- ),
272
- (True , "redirect" , "isinstance(files(pkg.sub_b.sub_c), pathlib.Path)" ),
228
+ (False , "" ),
273
229
pytest .param (
274
230
True ,
275
231
"redirect" ,
276
- "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_c).iterdir())" ,
277
232
marks = pytest .mark .xfail ,
278
233
),
279
- (True , "redirect" , "isinstance(files(pkg.sub_b.sub_d), pathlib.Path)" ),
280
- pytest .param (
281
- True ,
282
- "redirect" ,
283
- "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_d).iterdir())" ,
284
- marks = pytest .mark .xfail ,
285
- ),
286
- # Editable inplace
287
- (True , "inplace" , "isinstance(files(pkg), pathlib.Path)" ),
288
- (True , "inplace" , "any(str(x).endswith('.so') for x in files(pkg).iterdir())" ),
289
- (True , "inplace" , "isinstance(files(pkg.sub_a), pathlib.Path)" ),
290
- (
291
- True ,
292
- "inplace" ,
293
- "any(str(x).endswith('.so') for x in files(pkg.sub_a).iterdir())" ,
294
- ),
295
- (True , "inplace" , "isinstance(files(pkg.sub_b), pathlib.Path)" ),
296
- (
297
- True ,
298
- "inplace" ,
299
- "any(str(x).endswith('.so') for x in files(pkg.sub_b).iterdir())" ,
300
- ),
301
- (True , "inplace" , "isinstance(files(pkg.sub_b.sub_c), pathlib.Path)" ),
302
- (
303
- True ,
304
- "inplace" ,
305
- "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_c).iterdir())" ,
306
- ),
307
- (True , "inplace" , "isinstance(files(pkg.sub_b.sub_d), pathlib.Path)" ),
308
- (
309
- True ,
310
- "inplace" ,
311
- "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_d).iterdir())" ,
312
- ),
234
+ (True , "inplace" ),
313
235
],
314
236
)
315
- def test_importlib_resources (
316
- monkeypatch , tmp_path , editable , editable_mode , isolated , check
317
- ):
318
- _setup_package_for_editable_layout_tests ( # type: ignore[no-untyped-call]
237
+ def test_importlib_resources (monkeypatch , tmp_path , editable , editable_mode , isolated ):
238
+ if sys .version_info < (3 , 9 ):
239
+ pytest .skip ("importlib.resources.files is introduced in Python 3.9" )
240
+
241
+ # TODO: Investigate these failures
242
+ if editable_mode == "redirect" :
243
+ pytest .xfail ("Redirect mode is at navigating importlib.resources.files" )
244
+ if platform .system () == "Windows" and editable_mode == "inplace" :
245
+ pytest .xfail ("Windows fails to import the top-level extension module" )
246
+
247
+ _setup_package_for_editable_layout_tests (
319
248
monkeypatch , tmp_path , editable , editable_mode , isolated
320
249
)
250
+
321
251
isolated .execute (
322
252
textwrap .dedent (
323
- f"""
253
+ """
254
+ from importlib import import_module
324
255
from importlib.resources import files
325
- from importlib.readers import MultiplexedPath
326
- import pkg
327
- import pathlib
328
- assert { check }
256
+ from pathlib import Path
257
+
258
+ def is_extension(path):
259
+ for ext in (".so", ".pyd"):
260
+ if ext in path.suffixes:
261
+ return True
262
+ return False
263
+
264
+ def check_pkg(pkg_name):
265
+ try:
266
+ pkg = import_module(pkg_name)
267
+ pkg_root = files(pkg)
268
+ print(f"pkg_root: [{type(pkg_root)}] {pkg_root}")
269
+ pkg_files = list(pkg_root.iterdir())
270
+ for path in pkg_files:
271
+ print(f"path: [{type(path)}] {path}")
272
+ assert any(is_extension(path) for path in pkg_files if isinstance(path, Path))
273
+ except Exception as err:
274
+ msg = f"Failed in {str(pkg)}"
275
+ raise RuntimeError(msg) from err
276
+
277
+ check_pkg("pkg")
278
+ check_pkg("pkg.sub_a")
279
+ check_pkg("pkg.sub_b")
280
+ check_pkg("pkg.sub_b.sub_c")
281
+ check_pkg("pkg.sub_b.sub_d")
329
282
"""
330
283
)
331
284
)
0 commit comments