Skip to content

Commit

Permalink
RF: Raise ValueError if stop_on_unknown_version is set
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Aug 16, 2020
1 parent c56a3b1 commit bf24dba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
20 changes: 12 additions & 8 deletions nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
min_ver = LooseVersion(str(trait_object.traits()[name].min_ver))
try:
too_old = min_ver > version
except TypeError:
iflogger.warning(
except TypeError as err:
msg = (
f"Nipype cannot validate the package version {version!r} for "
f"{self.__class__.__name__}. Trait {name} requires version "
f">={min_ver}. Please verify validity."
f"{self.__class__.__name__}. Trait {name} requires version >={min_ver}."
)
iflogger.warning(f"{msg}. Please verify validity.")
if config.getboolean("execution", "stop_on_unknown_version"):
raise ValueError(msg) from err
continue
if too_old:
unavailable_traits.append(name)
Expand All @@ -304,12 +306,14 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
max_ver = LooseVersion(str(trait_object.traits()[name].max_ver))
try:
too_new = max_ver < version
except TypeError:
iflogger.warning(
except TypeError as err:
msg = (
f"Nipype cannot validate the package version {version!r} for "
f"{self.__class__.__name__}. Trait {name} requires version "
f"<={max_ver}. Please verify validity."
f"{self.__class__.__name__}. Trait {name} requires version <={max_ver}."
)
iflogger.warning(f"{msg}. Please verify validity.")
if config.getboolean("execution", "stop_on_unknown_version"):
raise ValueError(msg) from err
continue
if too_new:
unavailable_traits.append(name)
Expand Down
22 changes: 21 additions & 1 deletion nipype/interfaces/base/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class DerivedInterface(nib.BaseInterface):
class input_spec(nib.TraitedSpec):
foo = nib.traits.Int(min_ver="0.9")
bar = nib.traits.Int(max_ver="0.9")

_version = "misparsed-garbage"

obj = DerivedInterface()
Expand All @@ -252,6 +253,25 @@ class input_spec(nib.TraitedSpec):
assert len(caplog.records) == 2


def test_input_version_missing_error():
from nipype import config

class DerivedInterface(nib.BaseInterface):
class input_spec(nib.TraitedSpec):
foo = nib.traits.Int(min_ver="0.9")
bar = nib.traits.Int(max_ver="0.9")

_version = "misparsed-garbage"

with mock.patch.object(config, "getboolean", return_value=True):
obj = DerivedInterface(foo=1)
with pytest.raises(ValueError):
obj._check_version_requirements(obj.inputs)
obj = DerivedInterface(bar=1)
with pytest.raises(ValueError):
obj._check_version_requirements(obj.inputs)


def test_output_version():
class InputSpec(nib.TraitedSpec):
foo = nib.traits.Int(desc="a random int")
Expand Down Expand Up @@ -473,7 +493,7 @@ def test_global_CommandLine_output(tmpdir):
ci = BET()
assert ci.terminal_output == "stream" # default case

with mock.patch.object(nib.CommandLine, '_terminal_output'):
with mock.patch.object(nib.CommandLine, "_terminal_output"):
nib.CommandLine.set_default_terminal_output("allatonce")
ci = nib.CommandLine(command="ls -l")
assert ci.terminal_output == "allatonce"
Expand Down

0 comments on commit bf24dba

Please sign in to comment.