Skip to content

Commit 203dd89

Browse files
committed
TST: Add test
1 parent 171c487 commit 203dd89

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

nipype/pipeline/engine/tests/test_nodes.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .... import config
99
from ....interfaces import utility as niu
10+
from ....interfaces import base as nib
1011
from ... import engine as pe
1112
from ..utils import merge_dict
1213
from .test_base import EngineTestInterface
@@ -334,3 +335,44 @@ def _producer(num=1, deadly_num=7):
334335
wf.base_dir = os.path.abspath("./test_output")
335336
with pytest.raises(RuntimeError):
336337
wf.run(plugin="MultiProc")
338+
339+
340+
class FailCommandLine(nib.CommandLine):
341+
input_spec = nib.CommandLineInputSpec
342+
output_spec = nib.TraitedSpec
343+
_cmd = 'nipype-node-execution-fail'
344+
345+
346+
def test_NodeExecutionError(tmp_path, monkeypatch):
347+
import stat
348+
349+
monkeypatch.chdir('.')
350+
351+
# create basic executable and add to PATH
352+
exebin = tmp_path / 'bin'
353+
exebin.mkdir()
354+
exe = exebin / 'nipype-node-execution-fail'
355+
exe.write_text('#!/bin/bash\necho "Running"\necho "This should fail" >&2\nexit 1')
356+
exe.chmod(exe.stat().st_mode | stat.S_IEXEC)
357+
monkeypatch.setenv("PATH", str(exe.parent.absolute()), prepend=os.pathsep)
358+
359+
# Test with cmdline interface
360+
cmd = pe.Node(FailCommandLine(), name="cmd-fail", base_dir='cmd')
361+
with pytest.raises(pe.nodes.NodeExecutionError) as exc:
362+
cmd.run()
363+
error_msg = str(exc.value)
364+
365+
for attr in ("Cmdline:", "Stdout:", "Stderr:", "Traceback:"):
366+
assert attr in error_msg
367+
assert "This should fail" in error_msg
368+
369+
# Test with function interface
370+
def fail():
371+
raise Exception("Functions can fail too")
372+
func = pe.Node(niu.Function(function=fail), name='func-fail', base_dir='func')
373+
with pytest.raises(pe.nodes.NodeExecutionError) as exc:
374+
func.run()
375+
error_msg = str(exc.value)
376+
assert "Traceback:" in error_msg
377+
assert "Cmdline:" not in error_msg
378+
assert "Functions can fail too" in error_msg

0 commit comments

Comments
 (0)