Skip to content

Commit 5c75b6d

Browse files
committed
tst: adding first test
1 parent e8c408a commit 5c75b6d

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

nipype/pipeline/engine/tests/test_utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ....interfaces import base as nib
1717
from ....interfaces import utility as niu
1818
from .... import config
19-
from ..utils import clean_working_directory, write_workflow_prov
19+
from ..utils import clean_working_directory, write_workflow_prov, load_resultfile
2020

2121

2222
class InputSpec(nib.TraitedSpec):
@@ -283,3 +283,17 @@ def test_modify_paths_bug(tmpdir):
283283
assert outputs.out_dict_path == {out_str: out_path}
284284
assert outputs.out_dict_str == {out_str: out_str}
285285
assert outputs.out_list == [out_str] * 2
286+
287+
288+
def test_save_load_resultfile(tmpdir):
289+
tmpdir.chdir()
290+
291+
spc = pe.Node(StrPathConfuser(in_str='2'), name='spc')
292+
spc.base_dir = tmpdir.mkdir('node').strpath
293+
result = spc.run()
294+
295+
loaded_result = load_resultfile(tmpdir.join('node').join('spc').join('result_spc.pklz'))
296+
297+
assert result.runtime.dictcopy() == loaded_result.runtime.dictcopy()
298+
assert result.inputs == loaded_result.inputs
299+
assert result.outputs.get() == loaded_result.outputs.get()

nipype/pipeline/engine/utils.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -274,40 +274,43 @@ def load_resultfile(results_file, resolve=True):
274274
"""
275275
Load InterfaceResult file from path.
276276
277-
Parameter
278-
---------
279-
path : base_dir of node
280-
name : name of node
277+
Parameters
278+
----------
279+
results_file : pathlike
280+
Path to an existing pickle (``result_<interface name>.pklz``) created with
281+
``save_resultfile``.
282+
Raises ``FileNotFoundError`` if ``results_file`` does not exist.
283+
resolve : bool
284+
Determines whether relative paths will be resolved to absolute (default is ``True``).
281285
282286
Returns
283287
-------
284-
result : InterfaceResult structure
288+
result : InterfaceResult
289+
A Nipype object containing the runtime, inputs, outputs and other interface information
290+
such as a traceback in the case of errors.
285291
286292
"""
287293
results_file = Path(results_file)
288-
289294
if not results_file.exists():
290295
raise FileNotFoundError(results_file)
291296

292-
with indirectory(str(results_file.parent)):
293-
result = loadpkl(results_file)
294-
295-
if resolve and result.outputs:
296-
try:
297-
outputs = result.outputs.get()
298-
except TypeError: # This is a Bunch
299-
logger.debug('Outputs object of loaded result %s is a Bunch.', results_file)
300-
return result
301-
302-
logger.debug('Resolving paths in outputs loaded from results file.')
303-
for trait_name, old in list(outputs.items()):
304-
if isdefined(old):
305-
if result.outputs.trait(trait_name).is_trait_type(OutputMultiPath):
306-
old = result.outputs.trait(trait_name).handler.get_value(
307-
result.outputs, trait_name)
308-
value = resolve_path_traits(result.outputs.trait(trait_name), old,
309-
results_file.parent)
310-
setattr(result.outputs, trait_name, value)
297+
result = loadpkl(results_file)
298+
if resolve and result.outputs:
299+
try:
300+
outputs = result.outputs.get()
301+
except TypeError: # This is a Bunch
302+
logger.debug('Outputs object of loaded result %s is a Bunch.', results_file)
303+
return result
304+
305+
logger.debug('Resolving paths in outputs loaded from results file.')
306+
for trait_name, old in list(outputs.items()):
307+
if isdefined(old):
308+
if result.outputs.trait(trait_name).is_trait_type(OutputMultiPath):
309+
old = result.outputs.trait(trait_name).handler.get_value(
310+
result.outputs, trait_name)
311+
value = resolve_path_traits(result.outputs.trait(trait_name), old,
312+
results_file.parent)
313+
setattr(result.outputs, trait_name, value)
311314
return result
312315

313316

0 commit comments

Comments
 (0)