Skip to content

Commit 51e12ae

Browse files
committed
RF+TST: add deprecation to ECAT from_filespec
ECAT overriding deprecated (now removed) from_filespec method in SpatialImages. Deprecate pending removal.
1 parent f7b96ac commit 51e12ae

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

nibabel/ecat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from .arraywriters import make_array_writer
5454
from .wrapstruct import WrapStruct
5555
from .fileslice import canonical_slicers, predict_shape, slice2outax
56+
from .deprecated import deprecate_with_version
5657

5758
BLOCK_SIZE = 512
5859

@@ -846,6 +847,10 @@ def get_subheaders(self):
846847
return self._subheader
847848

848849
@classmethod
850+
@deprecate_with_version('from_filespec class method is deprecated.\n'
851+
'Please use the ``from_file_map`` class method '
852+
'instead.',
853+
'2.1', '4.0')
849854
def from_filespec(klass, filespec):
850855
return klass.from_filename(filespec)
851856

nibabel/tests/test_ecat.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import division, print_function, absolute_import
1010

1111
import os
12+
import warnings
1213

1314
import numpy as np
1415

@@ -21,7 +22,7 @@
2122

2223
from numpy.testing import assert_array_equal, assert_array_almost_equal
2324

24-
from ..testing import data_path, suppress_warnings
25+
from ..testing import data_path, suppress_warnings, clear_and_catch_warnings
2526
from ..tmpdirs import InTemporaryDirectory
2627

2728
from .test_wrapstruct import _TestWrapStructBase
@@ -261,7 +262,20 @@ def test_data_regression(self):
261262
assert_equal(data.min(), vals['min'])
262263
assert_array_almost_equal(data.mean(), vals['mean'])
263264

264-
def test_mlist_regreesion(self):
265+
def test_mlist_regression(self):
265266
# Test mlist is as same as for nibabel 1.3.0
266267
assert_array_equal(self.img.get_mlist(),
267268
[[16842758, 3, 3011, 1]])
269+
270+
271+
def test_from_filespec_deprecation():
272+
# Check from_filespec raises Deprecation
273+
with clear_and_catch_warnings() as w:
274+
warnings.simplefilter('always', DeprecationWarning)
275+
# No warning for standard load
276+
img_loaded = EcatImage.load(ecat_file)
277+
assert_equal(len(w), 0)
278+
# Warning for from_filespec
279+
img_speced = EcatImage.from_filespec(ecat_file)
280+
assert_equal(len(w), 1)
281+
assert_array_equal(img_loaded.get_data(), img_speced.get_data())

0 commit comments

Comments
 (0)