Skip to content

Commit 82121e1

Browse files
authored
Merge pull request #2692 from effigies/fix/runtime_error
FIX: Add informative error for interfaces that fail to return valid runtime object
2 parents da96356 + c3ee6a4 commit 82121e1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

nipype/interfaces/base/core.py

+5
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ def run(self, cwd=None, ignore_exception=None, **inputs):
500500
platform=platform.platform(),
501501
hostname=platform.node(),
502502
version=self.version)
503+
runtime_attrs = set(runtime.dictcopy())
503504

504505
mon_sp = None
505506
if enable_rm:
@@ -540,6 +541,10 @@ def run(self, cwd=None, ignore_exception=None, **inputs):
540541
if not ignore_exception:
541542
raise
542543
finally:
544+
if runtime is None or runtime_attrs - set(runtime.dictcopy()):
545+
raise RuntimeError("{} interface failed to return valid "
546+
"runtime object".format(
547+
interface.__class__.__name__))
543548
# This needs to be done always
544549
runtime.endTime = dt.isoformat(dt.utcnow())
545550
timediff = parseutc(runtime.endTime) - parseutc(runtime.startTime)

nipype/interfaces/base/tests/test_core.py

+26
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,29 @@ class OOPBadShell(nib.CommandLine):
517517
ci = OOPBadShell(command=script_name)
518518
with pytest.raises(IOError):
519519
ci.run()
520+
521+
522+
def test_runtime_checks():
523+
class TestInterface(nib.BaseInterface):
524+
class input_spec(nib.TraitedSpec):
525+
a = nib.traits.Any()
526+
class output_spec(nib.TraitedSpec):
527+
b = nib.traits.Any()
528+
529+
def _run_interface(self, runtime):
530+
return runtime
531+
532+
class NoRuntime(TestInterface):
533+
def _run_interface(self, runtime):
534+
return None
535+
536+
class BrokenRuntime(TestInterface):
537+
def _run_interface(self, runtime):
538+
del runtime.__dict__['cwd']
539+
return runtime
540+
541+
with pytest.raises(RuntimeError):
542+
NoRuntime().run()
543+
544+
with pytest.raises(RuntimeError):
545+
BrokenRuntime().run()

0 commit comments

Comments
 (0)