15
15
from ..gifti import data_tag
16
16
from ...nifti1 import data_type_codes
17
17
from ...fileholders import FileHolder
18
+ from ...deprecator import ExpiredDeprecationError
18
19
19
20
from numpy .testing import assert_array_almost_equal , assert_array_equal
20
21
import pytest
21
- from ...testing import clear_and_catch_warnings , test_data
22
+ from ...testing import test_data
22
23
from .test_parse_gifti_fast import (DATA_FILE1 , DATA_FILE2 , DATA_FILE3 ,
23
24
DATA_FILE4 , DATA_FILE5 , DATA_FILE6 )
24
25
import itertools
@@ -183,46 +184,29 @@ def test_dataarray_init():
183
184
184
185
185
186
def test_dataarray_from_array ():
186
- with clear_and_catch_warnings () as w :
187
- warnings .filterwarnings ('always' , category = DeprecationWarning )
188
- da = GiftiDataArray .from_array (np .ones ((3 , 4 )))
189
- assert len (w ) == 1
190
- for dt_code in data_type_codes .value_set ():
191
- data_type = data_type_codes .type [dt_code ]
192
- if data_type is np .void : # not supported
193
- continue
194
- arr = np .zeros ((10 , 3 ), dtype = data_type )
195
- da = GiftiDataArray .from_array (arr , 'triangle' )
196
- assert da .datatype == data_type_codes [arr .dtype ]
197
- bs_arr = arr .byteswap ().newbyteorder ()
198
- da = GiftiDataArray .from_array (bs_arr , 'triangle' )
199
- assert da .datatype == data_type_codes [arr .dtype ]
187
+ with pytest .raises (ExpiredDeprecationError ):
188
+ GiftiDataArray .from_array (np .ones ((3 , 4 )))
200
189
201
190
202
191
def test_to_xml_open_close_deprecations ():
203
192
# Smoke test on deprecated functions
204
193
da = GiftiDataArray (np .ones ((1 ,)), 'triangle' )
205
- with clear_and_catch_warnings () as w :
206
- warnings .filterwarnings ('always' , category = DeprecationWarning )
207
- assert isinstance (da .to_xml_open (), str )
208
- assert len (w ) == 1
209
- with clear_and_catch_warnings () as w :
210
- warnings .filterwarnings ('once' , category = DeprecationWarning )
211
- assert isinstance (da .to_xml_close (), str )
212
- assert len (w ) == 1
194
+ with pytest .raises (ExpiredDeprecationError ):
195
+ da .to_xml_open ()
196
+ with pytest .raises (ExpiredDeprecationError ):
197
+ da .to_xml_close ()
213
198
214
199
215
200
def test_num_dim_deprecation ():
216
201
da = GiftiDataArray (np .ones ((2 , 3 , 4 )))
217
202
# num_dim is property, set automatically from len(da.dims)
218
203
assert da .num_dim == 3
219
- with clear_and_catch_warnings () as w :
220
- warnings .filterwarnings ('always' , category = DeprecationWarning )
221
- # OK setting num_dim to correct value, but raises DeprecationWarning
204
+ # setting num_dim to correct value is deprecated
205
+ with pytest .raises (ExpiredDeprecationError ):
222
206
da .num_dim = 3
223
- assert len ( w ) == 1
224
- # Any other value gives a ValueError
225
- pytest . raises ( ValueError , setattr , da , ' num_dim' , 4 )
207
+ # setting num_dim to incorrect value is also deprecated
208
+ with pytest . raises ( ExpiredDeprecationError ):
209
+ da . num_dim = 4
226
210
227
211
228
212
def test_labeltable ():
@@ -235,14 +219,10 @@ def test_labeltable():
235
219
assert len (img .labeltable .labels ) == 2
236
220
237
221
# Test deprecations
238
- with clear_and_catch_warnings () as w :
239
- warnings .filterwarnings ('always' , category = DeprecationWarning )
222
+ with pytest .raises (ExpiredDeprecationError ):
240
223
newer_table = GiftiLabelTable ()
241
224
newer_table .labels += ['test' , 'me' , 'again' ]
242
225
img .set_labeltable (newer_table )
243
- assert len (w ) == 1
244
- assert len (img .get_labeltable ().labels ) == 3
245
- assert len (w ) == 2
246
226
247
227
248
228
def test_metadata ():
@@ -261,14 +241,8 @@ def test_metadata():
261
241
assert md .data [0 ].value == 'value'
262
242
assert len (w ) == 2
263
243
# Test deprecation
264
- with clear_and_catch_warnings () as w :
265
- warnings .filterwarnings ('always' , category = DeprecationWarning )
266
- assert md .get_metadata () == dict (key = 'value' )
267
- assert len (w ) == 1
268
- assert md .metadata == dict (key = 'value' )
269
- assert len (w ) == 2
270
- assert len (GiftiDataArray ().get_metadata ()) == 0
271
- assert len (w ) == 3
244
+ with pytest .raises (ExpiredDeprecationError ):
245
+ md .get_metadata ()
272
246
273
247
274
248
def test_gifti_label_rgba ():
@@ -295,10 +269,8 @@ def assign_rgba(gl, val):
295
269
pytest .raises (ValueError , assign_rgba , gl3 , rgba .tolist () + rgba .tolist ())
296
270
297
271
# Test deprecation
298
- with clear_and_catch_warnings () as w :
299
- warnings .filterwarnings ('once' , category = DeprecationWarning )
300
- assert kwargs ['red' ] == gl3 .get_rgba ()[0 ]
301
- assert len (w ) == 1
272
+ with pytest .raises (ExpiredDeprecationError ):
273
+ gl3 .get_rgba ()
302
274
303
275
# Test default value
304
276
gl4 = GiftiLabel ()
@@ -325,10 +297,8 @@ def test_gifti_coord():
325
297
326
298
327
299
def test_data_tag_deprecated ():
328
- with clear_and_catch_warnings () as w :
329
- warnings .filterwarnings ('once' , category = DeprecationWarning )
300
+ with pytest .raises (ExpiredDeprecationError ):
330
301
data_tag (np .array ([]), 'ASCII' , '%i' , 1 )
331
- assert len (w ) == 1
332
302
333
303
334
304
def test_gifti_round_trip ():
0 commit comments