Skip to content

Commit 0a69fe7

Browse files
committed
TEST: Clean up tests to avoid triggering warnings/exceptions
1 parent d4a6fed commit 0a69fe7

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

nibabel/nifti1.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,17 +910,17 @@ def set_data_dtype(self, datatype):
910910
Traceback (most recent call last):
911911
...
912912
HeaderDataError: data dtype "<type 'numpy.void'>" known but not supported
913-
>>> hdr.set_data_dtype('int')
913+
>>> hdr.set_data_dtype('int') #doctest: +IGNORE_EXCEPTION_DETAIL
914914
Traceback (most recent call last):
915915
...
916916
ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
917-
>>> hdr.set_data_dtype(int)
917+
>>> hdr.set_data_dtype(int) #doctest: +IGNORE_EXCEPTION_DETAIL
918918
Traceback (most recent call last):
919919
...
920920
ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
921921
>>> hdr.set_data_dtype('int64')
922-
>>> hdr.get_data_dtype()
923-
dtype('int64')
922+
>>> hdr.get_data_dtype() == np.dtype('int64')
923+
True
924924
"""
925925
if not isinstance(datatype, np.dtype) and datatype in (int, "int"):
926926
raise ValueError(f"Invalid data type {datatype!r}. Specify a sized integer, "
@@ -1926,7 +1926,7 @@ def set_qform(self, affine, code=None, strip_shears=True, **kwargs):
19261926
19271927
Examples
19281928
--------
1929-
>>> data = np.arange(24).reshape((2,3,4))
1929+
>>> data = np.arange(24, dtype='f4').reshape((2,3,4))
19301930
>>> aff = np.diag([2, 3, 4, 1])
19311931
>>> img = Nifti1Pair(data, aff)
19321932
>>> img.get_qform()
@@ -2009,7 +2009,7 @@ def set_sform(self, affine, code=None, **kwargs):
20092009
20102010
Examples
20112011
--------
2012-
>>> data = np.arange(24).reshape((2,3,4))
2012+
>>> data = np.arange(24, dtype='f4').reshape((2,3,4))
20132013
>>> aff = np.diag([2, 3, 4, 1])
20142014
>>> img = Nifti1Pair(data, aff)
20152015
>>> img.get_sform()

nibabel/tests/test_analyze.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,13 @@ def assert_set_dtype(dt_spec, np_dtype):
290290
# Test aliases to Python types
291291
assert_set_dtype(float, np.float64) # float64 always supported
292292
np_sys_int = np.dtype(int).type # int could be 32 or 64 bit
293-
if np_sys_int in self.supported_np_types: # no int64 for Analyze
293+
if np_sys_int == np.int32: # no int64 for Analyze
294294
assert_set_dtype(int, np_sys_int)
295+
elif issubclass(self.header_class, Nifti1Header):
296+
# We don't allow int aliases in Nifti
297+
with pytest.raises(ValueError):
298+
hdr = self.header_class()
299+
hdr.set_data_dtype(int)
295300
hdr = self.header_class()
296301
for inp in all_unsupported_types:
297302
with pytest.raises(HeaderDataError):

nibabel/tests/test_nifti1.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def test_none_qsform(self):
770770
img_klass = self.image_class
771771
hdr_klass = img_klass.header_class
772772
shape = (2, 3, 4)
773-
data = np.arange(24).reshape(shape)
773+
data = np.arange(24, dtype='f4').reshape((2, 3, 4))
774774
# With specified affine
775775
aff = from_matvec(euler2mat(0.1, 0.2, 0.3), [11, 12, 13])
776776
for hdr in (None, hdr_klass()):
@@ -1040,7 +1040,7 @@ def test_affines_init(self):
10401040
# is some thoughts by Mark Jenkinson:
10411041
# http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/qsform_brief_usage
10421042
IC = self.image_class
1043-
arr = np.arange(24).reshape((2, 3, 4))
1043+
arr = np.arange(24, dtype='f4').reshape((2, 3, 4))
10441044
aff = np.diag([2, 3, 4, 1])
10451045
# Default is sform set, qform not set
10461046
img = IC(arr, aff)
@@ -1073,7 +1073,7 @@ def test_affines_init(self):
10731073

10741074
def test_read_no_extensions(self):
10751075
IC = self.image_class
1076-
arr = np.arange(24).reshape((2, 3, 4))
1076+
arr = np.arange(24, dtype='f4').reshape((2, 3, 4))
10771077
img = IC(arr, np.eye(4))
10781078
assert len(img.header.extensions) == 0
10791079
img_rt = bytesio_round_trip(img)
@@ -1110,7 +1110,7 @@ class TestNifti1Image(TestNifti1Pair):
11101110
def test_offset_errors(self):
11111111
# Test that explicit offset too low raises error
11121112
IC = self.image_class
1113-
arr = np.arange(24).reshape((2, 3, 4))
1113+
arr = np.arange(24, dtype='f4').reshape((2, 3, 4))
11141114
img = IC(arr, np.eye(4))
11151115
assert img.header.get_data_offset() == 0
11161116
# Saving with zero offset is OK
@@ -1365,7 +1365,7 @@ def test_loadsave_cycle(self):
13651365
def test_load(self):
13661366
# test module level load. We try to load a nii and an .img and a .hdr
13671367
# and expect to get a nifti back of single or pair type
1368-
arr = np.arange(24).reshape((2, 3, 4))
1368+
arr = np.arange(24, dtype='f4').reshape((2, 3, 4))
13691369
aff = np.diag([2, 3, 4, 1])
13701370
simg = self.single_class(arr, aff)
13711371
pimg = self.pair_class(arr, aff)
@@ -1439,7 +1439,7 @@ def test_rt_bias(self):
14391439

14401440
def test_reoriented_dim_info(self):
14411441
# Check that dim_info is reoriented correctly
1442-
arr = np.arange(24).reshape((2, 3, 4))
1442+
arr = np.arange(24, dtype='f4').reshape((2, 3, 4))
14431443
# Start as RAS
14441444
aff = np.diag([2, 3, 4, 1])
14451445
simg = self.single_class(arr, aff)

0 commit comments

Comments
 (0)