11# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
22# vi: set ft=python sts=4 ts=4 sw=4 et:
33"""I/O test cases."""
4+ import os
45from subprocess import check_call
56from io import StringIO
67import filecmp
78import shutil
89import numpy as np
910import pytest
11+ from h5py import File as H5File
1012
1113import nibabel as nb
1214from nibabel .eulerangles import euler2mat
@@ -408,7 +410,7 @@ def test_afni_Displacements():
408410 afni .AFNIDisplacementsField .from_image (field )
409411
410412
411- def test_itk_h5 (testdata_path ):
413+ def test_itk_h5 (tmpdir , testdata_path ):
412414 """Test displacements fields."""
413415 assert (
414416 len (
@@ -430,6 +432,21 @@ def test_itk_h5(testdata_path):
430432 )
431433 )
432434
435+ tmpdir .chdir ()
436+ shutil .copy (
437+ testdata_path / "ds-005_sub-01_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5" ,
438+ "test.h5" ,
439+ )
440+ os .chmod ("test.h5" , 0o666 )
441+
442+ with H5File ("test.h5" , "r+" ) as h5file :
443+ h5group = h5file ["TransformGroup" ]
444+ xfm = h5group [list (h5group .keys ())[1 ]]
445+ xfm ["TransformType" ][0 ] = b"InventTransform"
446+
447+ with pytest .raises (TransformIOError ):
448+ itk .ITKCompositeH5 .from_filename ("test.h5" )
449+
433450
434451@pytest .mark .parametrize (
435452 "file_type, test_file" , [(LTA , "from-fsnative_to-scanner_mode-image.lta" )]
0 commit comments