1515from ..gifti import data_tag
1616from ...nifti1 import data_type_codes
1717from ...fileholders import FileHolder
18+ from ...deprecator import ExpiredDeprecationError
1819
1920from numpy .testing import assert_array_almost_equal , assert_array_equal
2021import pytest
21- from ...testing import clear_and_catch_warnings , test_data
22+ from ...testing import test_data
2223from .test_parse_gifti_fast import (DATA_FILE1 , DATA_FILE2 , DATA_FILE3 ,
2324 DATA_FILE4 , DATA_FILE5 , DATA_FILE6 )
2425import itertools
@@ -183,46 +184,29 @@ def test_dataarray_init():
183184
184185
185186def 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 )))
200189
201190
202191def test_to_xml_open_close_deprecations ():
203192 # Smoke test on deprecated functions
204193 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 ()
213198
214199
215200def test_num_dim_deprecation ():
216201 da = GiftiDataArray (np .ones ((2 , 3 , 4 )))
217202 # num_dim is property, set automatically from len(da.dims)
218203 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 ):
222206 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
226210
227211
228212def test_labeltable ():
@@ -235,14 +219,10 @@ def test_labeltable():
235219 assert len (img .labeltable .labels ) == 2
236220
237221 # Test deprecations
238- with clear_and_catch_warnings () as w :
239- warnings .filterwarnings ('always' , category = DeprecationWarning )
222+ with pytest .raises (ExpiredDeprecationError ):
240223 newer_table = GiftiLabelTable ()
241224 newer_table .labels += ['test' , 'me' , 'again' ]
242225 img .set_labeltable (newer_table )
243- assert len (w ) == 1
244- assert len (img .get_labeltable ().labels ) == 3
245- assert len (w ) == 2
246226
247227
248228def test_metadata ():
@@ -261,14 +241,8 @@ def test_metadata():
261241 assert md .data [0 ].value == 'value'
262242 assert len (w ) == 2
263243 # 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 ()
272246
273247
274248def test_gifti_label_rgba ():
@@ -295,10 +269,8 @@ def assign_rgba(gl, val):
295269 pytest .raises (ValueError , assign_rgba , gl3 , rgba .tolist () + rgba .tolist ())
296270
297271 # 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 ()
302274
303275 # Test default value
304276 gl4 = GiftiLabel ()
@@ -325,10 +297,8 @@ def test_gifti_coord():
325297
326298
327299def test_data_tag_deprecated ():
328- with clear_and_catch_warnings () as w :
329- warnings .filterwarnings ('once' , category = DeprecationWarning )
300+ with pytest .raises (ExpiredDeprecationError ):
330301 data_tag (np .array ([]), 'ASCII' , '%i' , 1 )
331- assert len (w ) == 1
332302
333303
334304def test_gifti_round_trip ():
0 commit comments