From a09aa6c42bf090b23090e2049f6b5bb784f3263a Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Sun, 9 Dec 2012 09:34:42 -0500 Subject: [PATCH] fix: deprecation warning does not reset trait to Undefined - will set new value --- nipype/interfaces/base.py | 9 +++++++-- nipype/interfaces/tests/test_base.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/nipype/interfaces/base.py b/nipype/interfaces/base.py index 4203255fed..5c1c62f519 100644 --- a/nipype/interfaces/base.py +++ b/nipype/interfaces/base.py @@ -268,6 +268,7 @@ def __init__(self, interface, runtime, inputs=None, outputs=None): def version(self): return self._version + class BaseTraitedSpec(traits.HasTraits): """Provide a few methods necessary to support nipype interface api @@ -374,7 +375,6 @@ def _deprecated_warn(self, obj, name, old, new): self.__class__.__name__.split('InputSpec')[0]) msg2 = ('Will be removed or raise an error as of release %s') % \ trait_spec.deprecated - self.trait_set(trait_change_notify=False, **{'%s' % name: Undefined}) if trait_spec.new_name: if trait_spec.new_name not in self.copyable_trait_names(): raise TraitError(msg1 + ' Replacement trait %s not found' % @@ -387,7 +387,12 @@ def _deprecated_warn(self, obj, name, old, new): raise TraitError(msg) else: warn(msg) - + if trait_spec.new_name: + warn('Unsetting %s and setting %s.' % (name, + trait_spec.new_name)) + self.trait_set(trait_change_notify=False, + **{'%s' % name: Undefined, + '%s' % trait_spec.new_name: new}) def _hash_infile(self, adict, key): """ Inject file hashes into adict[key]""" diff --git a/nipype/interfaces/tests/test_base.py b/nipype/interfaces/tests/test_base.py index d58f37637d..ae9869c24c 100644 --- a/nipype/interfaces/tests/test_base.py +++ b/nipype/interfaces/tests/test_base.py @@ -139,7 +139,7 @@ class DeprecationSpec1(nib.TraitedSpec): set_foo = lambda : setattr(spec_instance, 'foo', 1) yield assert_raises, nib.TraitError, set_foo class DeprecationSpec1numeric(nib.TraitedSpec): - foo = nib.traits.Int(deprecated=0.1) + foo = nib.traits.Int(deprecated='0.1') spec_instance = DeprecationSpec1numeric() set_foo = lambda : setattr(spec_instance, 'foo', 1) yield assert_raises, nib.TraitError, set_foo @@ -158,6 +158,18 @@ class DeprecationSpec3(nib.TraitedSpec): except nib.TraitError: not_raised = False yield assert_true, not_raised + class DeprecationSpec3(nib.TraitedSpec): + foo = nib.traits.Int(deprecated='1000', new_name='bar') + bar = nib.traits.Int() + spec_instance = DeprecationSpec3() + not_raised = True + try: + spec_instance.foo = 1 + except nib.TraitError: + not_raised = False + yield assert_true, not_raised + yield assert_equal, spec_instance.foo, Undefined + yield assert_equal, spec_instance.bar, 1 def checknose(): """check version of nose for known incompatability"""