Skip to content

Commit bb8bf32

Browse files
committed
enh: add itk i/o test
1 parent 1fa7eeb commit bb8bf32

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

nitransforms/tests/test_io.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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
45
from subprocess import check_call
56
from io import StringIO
67
import filecmp
78
import shutil
89
import numpy as np
910
import pytest
11+
from h5py import File as H5File
1012

1113
import nibabel as nb
1214
from 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

Comments
 (0)