48
48
bytesio_filemap ,
49
49
bytesio_round_trip ,
50
50
clear_and_catch_warnings ,
51
+ deprecated_to ,
51
52
expires ,
52
53
nullcontext ,
53
54
)
80
81
from .test_parrec import EXAMPLE_IMAGES as PARREC_EXAMPLE_IMAGES
81
82
82
83
83
- def maybe_deprecated (meth_name ):
84
- return pytest .deprecated_call () if meth_name == 'get_data' else nullcontext ()
85
-
86
-
87
84
class GenericImageAPI (ValidateAPI ):
88
85
"""General image validation API"""
89
86
@@ -194,7 +191,7 @@ def validate_no_slicing(self, imaker, params):
194
191
@expires ('5.0.0' )
195
192
def validate_get_data_deprecated (self , imaker , params ):
196
193
img = imaker ()
197
- with pytest . deprecated_call ( ):
194
+ with deprecated_to ( '5.0.0' ):
198
195
data = img .get_data ()
199
196
assert_array_equal (np .asanyarray (img .dataobj ), data )
200
197
@@ -246,14 +243,12 @@ def validate_data_interface(self, imaker, params):
246
243
self ._check_array_interface (imaker , meth_name )
247
244
method = getattr (img , meth_name )
248
245
# Data shape is same as image shape
249
- with maybe_deprecated (meth_name ):
250
- assert img .shape == method ().shape
246
+ assert img .shape == method ().shape
251
247
# Data ndim is same as image ndim
252
- with maybe_deprecated (meth_name ):
253
- assert img .ndim == method ().ndim
248
+ assert img .ndim == method ().ndim
254
249
# Values to get_data caching parameter must be 'fill' or
255
250
# 'unchanged'
256
- with maybe_deprecated ( meth_name ), pytest .raises (ValueError ):
251
+ with pytest .raises (ValueError ):
257
252
method (caching = 'something' )
258
253
# dataobj is read only
259
254
fake_data = np .zeros (img .shape , dtype = img .get_data_dtype ())
@@ -277,13 +272,11 @@ def _check_proxy_interface(self, imaker, meth_name):
277
272
assert not img .in_memory
278
273
# Load with caching='unchanged'
279
274
method = getattr (img , meth_name )
280
- with maybe_deprecated (meth_name ):
281
- data = method (caching = 'unchanged' )
275
+ data = method (caching = 'unchanged' )
282
276
# Still not cached
283
277
assert not img .in_memory
284
278
# Default load, does caching
285
- with maybe_deprecated (meth_name ):
286
- data = method ()
279
+ data = method ()
287
280
# Data now cached. in_memory is True if either of the get_data
288
281
# or get_fdata caches are not-None
289
282
assert img .in_memory
@@ -295,36 +288,30 @@ def _check_proxy_interface(self, imaker, meth_name):
295
288
# integers, but lets assume that's not true here.
296
289
assert_array_equal (proxy_data , data )
297
290
# Now caching='unchanged' does nothing, returns cached version
298
- with maybe_deprecated (meth_name ):
299
- data_again = method (caching = 'unchanged' )
291
+ data_again = method (caching = 'unchanged' )
300
292
assert data is data_again
301
293
# caching='fill' does nothing because the cache is already full
302
- with maybe_deprecated (meth_name ):
303
- data_yet_again = method (caching = 'fill' )
294
+ data_yet_again = method (caching = 'fill' )
304
295
assert data is data_yet_again
305
296
# changing array data does not change proxy data, or reloaded
306
297
# data
307
298
data [:] = 42
308
299
assert_array_equal (proxy_data , proxy_copy )
309
300
assert_array_equal (np .asarray (img .dataobj ), proxy_copy )
310
- # It does change the result of get_data
311
- with maybe_deprecated (meth_name ):
312
- assert_array_equal (method (), 42 )
301
+ # It does change the result of get_fdata
302
+ assert_array_equal (method (), 42 )
313
303
# until we uncache
314
304
img .uncache ()
315
305
# Which unsets in_memory
316
306
assert not img .in_memory
317
- with maybe_deprecated (meth_name ):
318
- assert_array_equal (method (), proxy_copy )
307
+ assert_array_equal (method (), proxy_copy )
319
308
# Check caching='fill' does cache data
320
309
img = imaker ()
321
310
method = getattr (img , meth_name )
322
311
assert not img .in_memory
323
- with maybe_deprecated (meth_name ):
324
- data = method (caching = 'fill' )
312
+ data = method (caching = 'fill' )
325
313
assert img .in_memory
326
- with maybe_deprecated (meth_name ):
327
- data_again = method ()
314
+ data_again = method ()
328
315
assert data is data_again
329
316
# Check that caching refreshes for new floating point type.
330
317
img .uncache ()
@@ -368,17 +355,15 @@ def _check_array_caching(self, imaker, meth_name, caching):
368
355
get_data_func = method if caching is None else partial (method , caching = caching )
369
356
assert isinstance (img .dataobj , np .ndarray )
370
357
assert img .in_memory
371
- with maybe_deprecated (meth_name ):
372
- data = get_data_func ()
358
+ data = get_data_func ()
373
359
# Returned data same object as underlying dataobj if using
374
360
# old ``get_data`` method, or using newer ``get_fdata``
375
361
# method, where original array was float64.
376
362
arr_dtype = img .dataobj .dtype
377
363
dataobj_is_data = arr_dtype == np .float64 or method == img .get_data
378
364
# Set something to the output array.
379
365
data [:] = 42
380
- with maybe_deprecated (meth_name ):
381
- get_result_changed = np .all (get_data_func () == 42 )
366
+ get_result_changed = np .all (get_data_func () == 42 )
382
367
assert get_result_changed == (dataobj_is_data or caching != 'unchanged' )
383
368
if dataobj_is_data :
384
369
assert data is img .dataobj
@@ -387,15 +372,13 @@ def _check_array_caching(self, imaker, meth_name, caching):
387
372
assert_array_equal (np .asarray (img .dataobj ), 42 )
388
373
# Uncache has no effect
389
374
img .uncache ()
390
- with maybe_deprecated (meth_name ):
391
- assert_array_equal (get_data_func (), 42 )
375
+ assert_array_equal (get_data_func (), 42 )
392
376
else :
393
377
assert not data is img .dataobj
394
378
assert not np .all (np .asarray (img .dataobj ) == 42 )
395
379
# Uncache does have an effect
396
380
img .uncache ()
397
- with maybe_deprecated (meth_name ):
398
- assert not np .all (get_data_func () == 42 )
381
+ assert not np .all (get_data_func () == 42 )
399
382
# in_memory is always true for array images, regardless of
400
383
# cache state.
401
384
img .uncache ()
@@ -408,8 +391,7 @@ def _check_array_caching(self, imaker, meth_name, caching):
408
391
if arr_dtype not in float_types :
409
392
return
410
393
for float_type in float_types :
411
- with maybe_deprecated (meth_name ):
412
- data = get_data_func (dtype = float_type )
394
+ data = get_data_func (dtype = float_type )
413
395
assert (data is img .dataobj ) == (arr_dtype == float_type )
414
396
415
397
def validate_shape (self , imaker , params ):
0 commit comments