1
1
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
2
# vi: set ft=python sts=4 ts=4 sw=4 et:
3
3
"""I/O test cases."""
4
+ import os
4
5
from subprocess import check_call
5
6
from io import StringIO
6
7
import filecmp
7
8
import shutil
8
9
import numpy as np
9
10
import pytest
11
+ from h5py import File as H5File
10
12
11
13
import nibabel as nb
12
14
from nibabel .eulerangles import euler2mat
@@ -408,7 +410,7 @@ def test_afni_Displacements():
408
410
afni .AFNIDisplacementsField .from_image (field )
409
411
410
412
411
- def test_itk_h5 (testdata_path ):
413
+ def test_itk_h5 (tmpdir , testdata_path ):
412
414
"""Test displacements fields."""
413
415
assert (
414
416
len (
@@ -430,6 +432,21 @@ def test_itk_h5(testdata_path):
430
432
)
431
433
)
432
434
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
+
433
450
434
451
@pytest .mark .parametrize (
435
452
"file_type, test_file" , [(LTA , "from-fsnative_to-scanner_mode-image.lta" )]
0 commit comments