Skip to content

Commit 6a13f90

Browse files
committed
fix: rebase arg not honored + improved tests (add xfail mark for python 2)
1 parent ff74565 commit 6a13f90

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

nipype/pipeline/engine/tests/test_utils.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ....interfaces import utility as niu
1818
from .... import config
1919
from ..utils import (clean_working_directory, write_workflow_prov,
20-
save_resultfile, load_resultfile)
20+
load_resultfile)
2121

2222

2323
class InputSpec(nib.TraitedSpec):
@@ -286,13 +286,20 @@ def test_modify_paths_bug(tmpdir):
286286
assert outputs.out_list == [out_str] * 2
287287

288288

289-
def test_save_load_resultfile(tmpdir):
289+
@pytest.mark.xfail(sys.version_info < (3, 4),
290+
reason="rebase does not fully work with Python 2.7")
291+
@pytest.mark.parametrize("use_relative", [True, False])
292+
def test_save_load_resultfile(tmpdir, use_relative):
290293
"""Test minimally the save/load functions for result files."""
291-
from shutil import copytree
294+
from shutil import copytree, rmtree
292295
tmpdir.chdir()
293296

297+
old_use_relative = config.getboolean('execution', 'use_relative_paths')
298+
config.set('execution', 'use_relative_paths', use_relative)
299+
294300
spc = pe.Node(StrPathConfuser(in_str='2'), name='spc')
295301
spc.base_dir = tmpdir.mkdir('node').strpath
302+
296303
result = spc.run()
297304

298305
loaded_result = load_resultfile(
@@ -304,14 +311,22 @@ def test_save_load_resultfile(tmpdir):
304311

305312
# Test the mobility of the result file.
306313
copytree(tmpdir.join('node').strpath, tmpdir.join('node2').strpath)
307-
save_resultfile(result, tmpdir.join('node2').strpath, 'spc', rebase=True)
308-
loaded_result2 = load_resultfile(
309-
tmpdir.join('node2').join('spc').join('result_spc.pklz').strpath)
310-
311-
assert result.runtime.dictcopy() == loaded_result2.runtime.dictcopy()
312-
assert result.inputs == loaded_result2.inputs
313-
assert loaded_result2.outputs.get() != result.outputs.get()
314-
newpath = result.outputs.out_path.replace('/node/', '/node2/')
315-
assert loaded_result2.outputs.out_path == newpath
316-
assert loaded_result2.outputs.out_tuple[0] == newpath
317-
assert loaded_result2.outputs.out_dict_path['2'] == newpath
314+
rmtree(tmpdir.join('node').strpath)
315+
316+
if use_relative:
317+
loaded_result2 = load_resultfile(
318+
tmpdir.join('node2').join('spc').join('result_spc.pklz').strpath)
319+
320+
assert result.runtime.dictcopy() == loaded_result2.runtime.dictcopy()
321+
assert result.inputs == loaded_result2.inputs
322+
assert loaded_result2.outputs.get() != result.outputs.get()
323+
newpath = result.outputs.out_path.replace('/node/', '/node2/')
324+
assert loaded_result2.outputs.out_path == newpath
325+
assert loaded_result2.outputs.out_tuple[0] == newpath
326+
assert loaded_result2.outputs.out_dict_path['2'] == newpath
327+
else:
328+
with pytest.raises(nib.TraitError):
329+
load_resultfile(
330+
tmpdir.join('node2').join('spc').join('result_spc.pklz').strpath)
331+
332+
config.set('execution', 'use_relative_paths', old_use_relative)

nipype/pipeline/engine/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ def save_resultfile(result, cwd, name, rebase=None):
250250
savepkl(resultsfile, result)
251251
return
252252

253+
if not rebase:
254+
savepkl(resultsfile, result)
255+
return
256+
253257
backup_traits = {}
254258
try:
255259
with indirectory(cwd):

nipype/utils/filemanip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def loadpkl(infile):
708708
Attempted to open a results file generated by Nipype version %s, \
709709
with an incompatible Nipype version (%s)""", pkl_metadata['version'], version)
710710
raise e
711-
fmlogger.error("""\
711+
fmlogger.warning("""\
712712
No metadata was found in the pkl file. Make sure you are currently using \
713713
the same Nipype version from the generated pkl.""")
714714
raise e

0 commit comments

Comments
 (0)