|
7 | 7 | import os
|
8 | 8 | import tempfile
|
9 | 9 | import shutil
|
| 10 | +import warnings |
10 | 11 |
|
11 | 12 | from nipype.testing import (assert_equal, assert_not_equal, assert_raises,
|
12 | 13 | assert_true, assert_false, with_setup, package_check,
|
|
16 | 17 | from nipype.interfaces.base import Undefined, config
|
17 | 18 | from traits.testing.nose_tools import skip
|
18 | 19 | import traits.api as traits
|
19 |
| -#test Bunch |
| 20 | + |
| 21 | + |
20 | 22 | def test_bunch():
|
21 | 23 | b = nib.Bunch()
|
22 | 24 | yield assert_equal, b.__dict__,{}
|
@@ -138,43 +140,67 @@ class MyInterface(nib.BaseInterface):
|
138 | 140 | yield assert_equal, myif.inputs.kung, 2.0
|
139 | 141 |
|
140 | 142 | def test_deprecation():
|
141 |
| - class DeprecationSpec1(nib.TraitedSpec): |
142 |
| - foo = nib.traits.Int(deprecated='0.1') |
143 |
| - spec_instance = DeprecationSpec1() |
144 |
| - set_foo = lambda : setattr(spec_instance, 'foo', 1) |
145 |
| - yield assert_raises, nib.TraitError, set_foo |
146 |
| - class DeprecationSpec1numeric(nib.TraitedSpec): |
147 |
| - foo = nib.traits.Int(deprecated='0.1') |
148 |
| - spec_instance = DeprecationSpec1numeric() |
149 |
| - set_foo = lambda : setattr(spec_instance, 'foo', 1) |
150 |
| - yield assert_raises, nib.TraitError, set_foo |
151 |
| - class DeprecationSpec2(nib.TraitedSpec): |
152 |
| - foo = nib.traits.Int(deprecated='100', new_name='bar') |
153 |
| - spec_instance = DeprecationSpec2() |
154 |
| - set_foo = lambda : setattr(spec_instance, 'foo', 1) |
155 |
| - yield assert_raises, nib.TraitError, set_foo |
156 |
| - class DeprecationSpec3(nib.TraitedSpec): |
157 |
| - foo = nib.traits.Int(deprecated='1000', new_name='bar') |
158 |
| - bar = nib.traits.Int() |
159 |
| - spec_instance = DeprecationSpec3() |
160 |
| - not_raised = True |
161 |
| - try: |
162 |
| - spec_instance.foo = 1 |
163 |
| - except nib.TraitError: |
164 |
| - not_raised = False |
165 |
| - yield assert_true, not_raised |
166 |
| - class DeprecationSpec3(nib.TraitedSpec): |
167 |
| - foo = nib.traits.Int(deprecated='1000', new_name='bar') |
168 |
| - bar = nib.traits.Int() |
169 |
| - spec_instance = DeprecationSpec3() |
170 |
| - not_raised = True |
171 |
| - try: |
172 |
| - spec_instance.foo = 1 |
173 |
| - except nib.TraitError: |
174 |
| - not_raised = False |
175 |
| - yield assert_true, not_raised |
176 |
| - yield assert_equal, spec_instance.foo, Undefined |
177 |
| - yield assert_equal, spec_instance.bar, 1 |
| 143 | + with warnings.catch_warnings(record=True) as w: |
| 144 | + warnings.filterwarnings('always', '', UserWarning) |
| 145 | + |
| 146 | + class DeprecationSpec1(nib.TraitedSpec): |
| 147 | + foo = nib.traits.Int(deprecated='0.1') |
| 148 | + spec_instance = DeprecationSpec1() |
| 149 | + set_foo = lambda : setattr(spec_instance, 'foo', 1) |
| 150 | + yield assert_raises, nib.TraitError, set_foo |
| 151 | + yield assert_equal, len(w), 0, 'no warnings, just errors' |
| 152 | + |
| 153 | + with warnings.catch_warnings(record=True) as w: |
| 154 | + warnings.filterwarnings('always', '', UserWarning) |
| 155 | + |
| 156 | + class DeprecationSpec1numeric(nib.TraitedSpec): |
| 157 | + foo = nib.traits.Int(deprecated='0.1') |
| 158 | + spec_instance = DeprecationSpec1numeric() |
| 159 | + set_foo = lambda : setattr(spec_instance, 'foo', 1) |
| 160 | + yield assert_raises, nib.TraitError, set_foo |
| 161 | + yield assert_equal, len(w), 0, 'no warnings, just errors' |
| 162 | + |
| 163 | + with warnings.catch_warnings(record=True) as w: |
| 164 | + warnings.filterwarnings('always', '', UserWarning) |
| 165 | + |
| 166 | + class DeprecationSpec2(nib.TraitedSpec): |
| 167 | + foo = nib.traits.Int(deprecated='100', new_name='bar') |
| 168 | + spec_instance = DeprecationSpec2() |
| 169 | + set_foo = lambda : setattr(spec_instance, 'foo', 1) |
| 170 | + yield assert_raises, nib.TraitError, set_foo |
| 171 | + yield assert_equal, len(w), 0, 'no warnings, just errors' |
| 172 | + |
| 173 | + with warnings.catch_warnings(record=True) as w: |
| 174 | + warnings.filterwarnings('always', '', UserWarning) |
| 175 | + |
| 176 | + class DeprecationSpec3(nib.TraitedSpec): |
| 177 | + foo = nib.traits.Int(deprecated='1000', new_name='bar') |
| 178 | + bar = nib.traits.Int() |
| 179 | + spec_instance = DeprecationSpec3() |
| 180 | + not_raised = True |
| 181 | + try: |
| 182 | + spec_instance.foo = 1 |
| 183 | + except nib.TraitError: |
| 184 | + not_raised = False |
| 185 | + yield assert_true, not_raised |
| 186 | + yield assert_equal, len(w), 1, 'deprecated warning 1 %s' % [w1.message for w1 in w] |
| 187 | + |
| 188 | + with warnings.catch_warnings(record=True) as w: |
| 189 | + warnings.filterwarnings('always', '', UserWarning) |
| 190 | + |
| 191 | + class DeprecationSpec3(nib.TraitedSpec): |
| 192 | + foo = nib.traits.Int(deprecated='1000', new_name='bar') |
| 193 | + bar = nib.traits.Int() |
| 194 | + spec_instance = DeprecationSpec3() |
| 195 | + not_raised = True |
| 196 | + try: |
| 197 | + spec_instance.foo = 1 |
| 198 | + except nib.TraitError: |
| 199 | + not_raised = False |
| 200 | + yield assert_true, not_raised |
| 201 | + yield assert_equal, spec_instance.foo, Undefined |
| 202 | + yield assert_equal, spec_instance.bar, 1 |
| 203 | + yield assert_equal, len(w), 1, 'deprecated warning 2 %s' % [w1.message for w1 in w] |
178 | 204 |
|
179 | 205 |
|
180 | 206 | def test_namesource():
|
|
0 commit comments