Skip to content

Commit bf24dba

Browse files
committed
RF: Raise ValueError if stop_on_unknown_version is set
1 parent c56a3b1 commit bf24dba

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

Diff for: nipype/interfaces/base/core.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,14 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
278278
min_ver = LooseVersion(str(trait_object.traits()[name].min_ver))
279279
try:
280280
too_old = min_ver > version
281-
except TypeError:
282-
iflogger.warning(
281+
except TypeError as err:
282+
msg = (
283283
f"Nipype cannot validate the package version {version!r} for "
284-
f"{self.__class__.__name__}. Trait {name} requires version "
285-
f">={min_ver}. Please verify validity."
284+
f"{self.__class__.__name__}. Trait {name} requires version >={min_ver}."
286285
)
286+
iflogger.warning(f"{msg}. Please verify validity.")
287+
if config.getboolean("execution", "stop_on_unknown_version"):
288+
raise ValueError(msg) from err
287289
continue
288290
if too_old:
289291
unavailable_traits.append(name)
@@ -304,12 +306,14 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
304306
max_ver = LooseVersion(str(trait_object.traits()[name].max_ver))
305307
try:
306308
too_new = max_ver < version
307-
except TypeError:
308-
iflogger.warning(
309+
except TypeError as err:
310+
msg = (
309311
f"Nipype cannot validate the package version {version!r} for "
310-
f"{self.__class__.__name__}. Trait {name} requires version "
311-
f"<={max_ver}. Please verify validity."
312+
f"{self.__class__.__name__}. Trait {name} requires version <={max_ver}."
312313
)
314+
iflogger.warning(f"{msg}. Please verify validity.")
315+
if config.getboolean("execution", "stop_on_unknown_version"):
316+
raise ValueError(msg) from err
313317
continue
314318
if too_new:
315319
unavailable_traits.append(name)

Diff for: nipype/interfaces/base/tests/test_core.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class DerivedInterface(nib.BaseInterface):
242242
class input_spec(nib.TraitedSpec):
243243
foo = nib.traits.Int(min_ver="0.9")
244244
bar = nib.traits.Int(max_ver="0.9")
245+
245246
_version = "misparsed-garbage"
246247

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

254255

256+
def test_input_version_missing_error():
257+
from nipype import config
258+
259+
class DerivedInterface(nib.BaseInterface):
260+
class input_spec(nib.TraitedSpec):
261+
foo = nib.traits.Int(min_ver="0.9")
262+
bar = nib.traits.Int(max_ver="0.9")
263+
264+
_version = "misparsed-garbage"
265+
266+
with mock.patch.object(config, "getboolean", return_value=True):
267+
obj = DerivedInterface(foo=1)
268+
with pytest.raises(ValueError):
269+
obj._check_version_requirements(obj.inputs)
270+
obj = DerivedInterface(bar=1)
271+
with pytest.raises(ValueError):
272+
obj._check_version_requirements(obj.inputs)
273+
274+
255275
def test_output_version():
256276
class InputSpec(nib.TraitedSpec):
257277
foo = nib.traits.Int(desc="a random int")
@@ -473,7 +493,7 @@ def test_global_CommandLine_output(tmpdir):
473493
ci = BET()
474494
assert ci.terminal_output == "stream" # default case
475495

476-
with mock.patch.object(nib.CommandLine, '_terminal_output'):
496+
with mock.patch.object(nib.CommandLine, "_terminal_output"):
477497
nib.CommandLine.set_default_terminal_output("allatonce")
478498
ci = nib.CommandLine(command="ls -l")
479499
assert ci.terminal_output == "allatonce"

0 commit comments

Comments
 (0)