Skip to content

FIX: Add informative error for interfaces that fail to return valid runtime object #2692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def run(self, cwd=None, ignore_exception=None, **inputs):
platform=platform.platform(),
hostname=platform.node(),
version=self.version)
runtime_attrs = set(runtime.dictcopy())

mon_sp = None
if enable_rm:
Expand Down Expand Up @@ -540,6 +541,10 @@ def run(self, cwd=None, ignore_exception=None, **inputs):
if not ignore_exception:
raise
finally:
if runtime is None or runtime_attrs - set(runtime.dictcopy()):
raise RuntimeError("{} interface failed to return valid "
"runtime object".format(
interface.__class__.__name__))
# This needs to be done always
runtime.endTime = dt.isoformat(dt.utcnow())
timediff = parseutc(runtime.endTime) - parseutc(runtime.startTime)
Expand Down
26 changes: 26 additions & 0 deletions nipype/interfaces/base/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,29 @@ class OOPBadShell(nib.CommandLine):
ci = OOPBadShell(command=script_name)
with pytest.raises(IOError):
ci.run()


def test_runtime_checks():
class TestInterface(nib.BaseInterface):
class input_spec(nib.TraitedSpec):
a = nib.traits.Any()
class output_spec(nib.TraitedSpec):
b = nib.traits.Any()

def _run_interface(self, runtime):
return runtime

class NoRuntime(TestInterface):
def _run_interface(self, runtime):
return None

class BrokenRuntime(TestInterface):
def _run_interface(self, runtime):
del runtime.__dict__['cwd']
return runtime

with pytest.raises(RuntimeError):
NoRuntime().run()

with pytest.raises(RuntimeError):
BrokenRuntime().run()