File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed
Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+ from atexit import register
3+ from contextlib import ExitStack
4+ from functools import lru_cache
5+
6+
7+ if sys .version_info < (3 , 9 ):
8+ from importlib_resources import as_file , files
9+ else :
10+ from importlib .resources import as_file , files
11+
12+ _stack = ExitStack ()
13+ register (_stack .close )
14+
15+
16+ @lru_cache
17+ def load_resource (anchor , * parts ) -> str :
18+ return str (_stack .enter_context (as_file (files (anchor ).joinpath (* parts ))))
Original file line number Diff line number Diff line change 11import pytest
22import shutil
3- from pkg_resources import resource_filename
3+ from . import load_resource
44
55from nipype .interfaces import fsl
66import nipype .interfaces .utility as nutil
1212def test_isolation (tmp_path ):
1313 in_file = tmp_path / "orig/tpms_msk.nii.gz"
1414 in_file .parent .mkdir ()
15- shutil .copyfile (resource_filename ("nipype" , "testing/data/tpms_msk.nii.gz" ), in_file )
15+ shutil .copyfile (load_resource ("nipype" , "testing/data/tpms_msk.nii.gz" ), in_file )
1616
1717 out_dir = tmp_path / "output"
1818 out_dir .mkdir ()
Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ class Nipype1Task(pydra.engine.task.TaskBase):
2727 in Pydra Task outputs.
2828
2929 >>> import pytest
30- >>> from pkg_resources import resource_filename
30+ >>> from pydra.tasks.nipype1.tests import load_resource
3131 >>> from nipype.interfaces import fsl
3232 >>> if fsl.Info.version() is None:
3333 ... pytest.skip()
34- >>> img = resource_filename ('nipype', 'testing/data/tpms_msk.nii.gz')
34+ >>> img = load_resource ('nipype', 'testing/data/tpms_msk.nii.gz')
3535
3636 >>> from pydra.tasks.nipype1.utils import Nipype1Task
3737 >>> thresh = Nipype1Task(fsl.Threshold())
You can’t perform that action at this time.
0 commit comments