7
7
scratch.
8
8
"""
9
9
import numpy as np
10
-
11
10
import nibabel as nib
12
11
from nibabel import cifti2 as ci
13
12
from nibabel .tmpdirs import InTemporaryDirectory
14
-
15
13
import pytest
14
+
16
15
from ...testing import (
17
16
clear_and_catch_warnings , error_warnings , suppress_warnings , assert_array_equal )
18
17
@@ -515,17 +514,13 @@ def test_cifti_validation():
515
514
geometry_map = create_geometry_map ((0 , ))
516
515
label_map = create_label_map ((1 , ))
517
516
matrix = ci .Cifti2Matrix ()
518
- matrix .append (label_map )
519
517
matrix .append (geometry_map )
518
+ matrix .append (label_map )
520
519
hdr = ci .Cifti2Header (matrix )
521
520
data = np .random .randn (10 , 2 )
522
521
img = ci .Cifti2Image (data , hdr )
523
-
524
- # attempt to save and validate with an invalid extension
525
- with pytest .raises (KeyError ):
526
- ci .save (img , 'test.dlabelz.nii' )
527
- # even with a proper extension, flipped index maps will fail
528
- with pytest .raises (ci .Cifti2HeaderError ):
522
+ # flipped index maps will warn
523
+ with InTemporaryDirectory (), pytest .warns (UserWarning ):
529
524
ci .save (img , 'test.dlabel.nii' )
530
525
531
526
label_map = create_label_map ((0 , ))
@@ -538,16 +533,16 @@ def test_cifti_validation():
538
533
img = ci .Cifti2Image (data , hdr )
539
534
540
535
with InTemporaryDirectory ():
541
- # still fail with invalid extension and validation
542
- with pytest .raises (KeyError ):
543
- ci .save (img , 'test.dlabelz.nii' )
544
- # but removing validation should work (though intent code will be unknown)
545
- ci .save (img , 'test.dlabelz.nii' , validate = False )
546
-
547
- img2 = nib .load ('test.dlabelz.nii' )
548
- assert img2 .nifti_header .get_intent ()[0 ] == 'ConnUnknown'
536
+ ci .save (img , 'test.validate.nii' , validate = False )
537
+ ci .save (img , 'test.dlabel.nii' )
538
+
539
+ img2 = nib .load ('test.dlabel.nii' )
540
+ img3 = nib .load ('test.validate.nii' )
541
+ assert img2 .nifti_header .get_intent ()[0 ] == 'ConnDenseLabel'
542
+ assert img3 .nifti_header .get_intent ()[0 ] == 'ConnUnknown'
549
543
assert isinstance (img2 , ci .Cifti2Image )
544
+ assert isinstance (img3 , ci .Cifti2Image )
550
545
assert_array_equal (img2 .get_fdata (), data )
551
546
check_label_map (img2 .header .matrix .get_index_map (0 ))
552
547
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
553
- del img2
548
+ del img2 , img3
0 commit comments