Skip to content

Commit b021b2d

Browse files
committed
TEST: Check for failing GIFTI encodings
1 parent f47f80e commit b021b2d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

nibabel/gifti/tests/test_gifti.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from nibabel.testing import clear_and_catch_warnings
2222
from .test_parse_gifti_fast import (DATA_FILE1, DATA_FILE2, DATA_FILE3,
2323
DATA_FILE4, DATA_FILE5, DATA_FILE6)
24+
import itertools
2425

2526

2627
def test_gifti_image():
@@ -400,3 +401,20 @@ def test_data_array_round_trip():
400401
gio = GiftiImage.from_file_map(fmap)
401402
vertices = gio.darrays[0].data
402403
assert_array_equal(vertices, verts)
404+
405+
406+
def test_type_coercion():
407+
dtypes = (np.uint8, np.int32, np.int64, np.float32, np.float64)
408+
encodings = ('ASCII', 'B64BIN', 'B64GZ')
409+
for data_dtype, darray_dtype, encoding in itertools.product(dtypes,
410+
dtypes,
411+
encodings):
412+
da = GiftiDataArray(np.arange(10).astype(data_dtype),
413+
encoding=encoding,
414+
intent='NIFTI_INTENT_NODE_INDEX',
415+
datatype=darray_dtype)
416+
gii = GiftiImage(darrays=[da])
417+
gii_copy = GiftiImage.from_bytes(gii.to_bytes())
418+
da_copy = gii_copy.darrays[0]
419+
assert_equal(np.dtype(da_copy.data.dtype), np.dtype(darray_dtype))
420+
assert_array_equal(da_copy.data, da.data)

0 commit comments

Comments
 (0)