Skip to content

Commit b2c6696

Browse files
committed
fix: version check and tests
1 parent aa03d04 commit b2c6696

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

nipype/interfaces/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ..utils.filemanip import (md5, hash_infile, FileNotFoundError,
2929
hash_timestamp)
3030
from ..utils.misc import is_container, trim, str2bool
31-
from .. import config, logging
31+
from .. import config, logging, LooseVersion
3232

3333
iflogger = logging.getLogger('interface')
3434

@@ -795,23 +795,23 @@ def _check_mandatory_inputs(self):
795795
def _check_input_version_requirements(self):
796796
""" Raises an exception on version mismatch
797797
"""
798-
version = str(self.version)
798+
version = LooseVersion(str(self.version))
799799
if not version:
800800
return
801801
# check minimum version
802802
names = self.inputs.trait_names(**dict(min_ver=lambda t: t is not None))
803803
for name in names:
804804
if not isdefined(getattr(self.inputs, name)):
805805
continue
806-
min_ver = str(self.inputs.traits()[name].min_ver)
806+
min_ver = LooseVersion(str(self.inputs.traits()[name].min_ver))
807807
if min_ver > version:
808808
raise Exception('Input %s (%s) (version %s < required %s)' %
809809
(name, self.__class__.__name__, version, min_ver))
810810
names = self.inputs.trait_names(**dict(max_ver=lambda t: t is not None))
811811
for name in names:
812812
if not isdefined(getattr(self.inputs, name)):
813813
continue
814-
max_ver = str(self.inputs.traits()[name].max_ver)
814+
max_ver = LooseVersion(str(self.inputs.traits()[name].max_ver))
815815
if max_ver < version:
816816
raise Exception('Input %s (%s) (version %s > required %s)' %
817817
(name, self.__class__.__name__, version, max_ver))

nipype/interfaces/tests/test_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,27 @@ class DerivedInterface1(nib.BaseInterface):
254254
input_spec = InputSpec
255255
_version = 0.8
256256
obj = DerivedInterface1()
257+
obj.inputs.foo = 1
257258
yield assert_raises, Exception, obj._check_input_version_requirements
259+
class InputSpec(nib.TraitedSpec):
260+
foo = nib.traits.Int(desc='a random int', min_ver=0.9)
261+
class DerivedInterface1(nib.BaseInterface):
262+
input_spec = InputSpec
263+
_version = 0.10
264+
obj = DerivedInterface1()
265+
not_raised = True
266+
try:
267+
obj._check_input_version_requirements()
268+
except:
269+
not_raised = False
270+
yield assert_true, not_raised
258271
class InputSpec(nib.TraitedSpec):
259272
foo = nib.traits.Int(desc='a random int', min_ver=0.9)
260273
class DerivedInterface1(nib.BaseInterface):
261274
input_spec = InputSpec
262275
_version = 0.9
263276
obj = DerivedInterface1()
277+
obj.inputs.foo = 1
264278
not_raised = True
265279
try:
266280
obj._check_input_version_requirements()
@@ -273,13 +287,15 @@ class DerivedInterface2(nib.BaseInterface):
273287
input_spec = InputSpec
274288
_version = 0.8
275289
obj = DerivedInterface2()
290+
obj.inputs.foo = 1
276291
yield assert_raises, Exception, obj._check_input_version_requirements
277292
class InputSpec(nib.TraitedSpec):
278293
foo = nib.traits.Int(desc='a random int', max_ver=0.9)
279294
class DerivedInterface1(nib.BaseInterface):
280295
input_spec = InputSpec
281296
_version = 0.9
282297
obj = DerivedInterface1()
298+
obj.inputs.foo = 1
283299
not_raised = True
284300
try:
285301
obj._check_input_version_requirements()

0 commit comments

Comments
 (0)