1717from ....interfaces import utility as niu
1818from .... import config
1919from ..utils import (clean_working_directory , write_workflow_prov ,
20- save_resultfile , load_resultfile )
20+ load_resultfile )
2121
2222
2323class 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 )
0 commit comments