77scratch.
88"""
99import numpy as np
10-
1110import nibabel as nib
1211from nibabel import cifti2 as ci
1312from nibabel .tmpdirs import InTemporaryDirectory
14-
1513import pytest
14+
1615from ...testing import (
1716 clear_and_catch_warnings , error_warnings , suppress_warnings , assert_array_equal )
1817
@@ -515,17 +514,13 @@ def test_cifti_validation():
515514 geometry_map = create_geometry_map ((0 , ))
516515 label_map = create_label_map ((1 , ))
517516 matrix = ci .Cifti2Matrix ()
518- matrix .append (label_map )
519517 matrix .append (geometry_map )
518+ matrix .append (label_map )
520519 hdr = ci .Cifti2Header (matrix )
521520 data = np .random .randn (10 , 2 )
522521 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 ):
529524 ci .save (img , 'test.dlabel.nii' )
530525
531526 label_map = create_label_map ((0 , ))
@@ -538,16 +533,16 @@ def test_cifti_validation():
538533 img = ci .Cifti2Image (data , hdr )
539534
540535 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'
549543 assert isinstance (img2 , ci .Cifti2Image )
544+ assert isinstance (img3 , ci .Cifti2Image )
550545 assert_array_equal (img2 .get_fdata (), data )
551546 check_label_map (img2 .header .matrix .get_index_map (0 ))
552547 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
553- del img2
548+ del img2 , img3
0 commit comments