@@ -44,10 +44,22 @@ def test_linear_typeerrors1(matrix):
4444
4545def test_linear_typeerrors2 (data_path ):
4646 """Exercise errors in Affine creation."""
47- with pytest .raises (TypeError ):
47+ with pytest .raises (io . TransformFileError ):
4848 nitl .Affine .from_filename (data_path / "itktflist.tfm" , fmt = "itk" )
4949
5050
51+ def test_linear_filenotfound (data_path ):
52+ """Exercise errors in Affine creation."""
53+ with pytest .raises (FileNotFoundError ):
54+ nitl .Affine .from_filename ("doesnotexist.tfm" , fmt = "itk" )
55+
56+ with pytest .raises (FileNotFoundError ):
57+ nitl .LinearTransformsMapping .from_filename ("doesnotexist.tfm" , fmt = "itk" )
58+
59+ with pytest .raises (FileNotFoundError ):
60+ nitl .LinearTransformsMapping .from_filename ("doesnotexist.mat" , fmt = "fsl" )
61+
62+
5163def test_linear_valueerror ():
5264 """Exercise errors in Affine creation."""
5365 with pytest .raises (ValueError ):
@@ -85,6 +97,38 @@ def test_loadsave_itk(tmp_path, data_path, testdata_path):
8597 )
8698
8799
100+ @pytest .mark .parametrize (
101+ "image_orientation" ,
102+ [
103+ "RAS" ,
104+ "LAS" ,
105+ "LPS" ,
106+ "oblique" ,
107+ ],
108+ )
109+ def test_itkmat_loadsave (tmpdir , data_path , image_orientation ):
110+ tmpdir .chdir ()
111+
112+ io .itk .ITKLinearTransform .from_filename (
113+ data_path / f"affine-{ image_orientation } .itk.tfm"
114+ ).to_filename (f"affine-{ image_orientation } .itk.mat" )
115+
116+ xfm = nitl .load (data_path / f"affine-{ image_orientation } .itk.tfm" , fmt = "itk" )
117+ mat1 = nitl .load (f"affine-{ image_orientation } .itk.mat" , fmt = "itk" )
118+
119+ assert xfm == mat1
120+
121+ mat2 = nitl .Affine .from_filename (f"affine-{ image_orientation } .itk.mat" , fmt = "itk" )
122+
123+ assert xfm == mat2
124+
125+ mat3 = nitl .LinearTransformsMapping .from_filename (
126+ f"affine-{ image_orientation } .itk.mat" , fmt = "itk"
127+ )
128+
129+ assert xfm == mat3
130+
131+
88132@pytest .mark .parametrize ("autofmt" , (False , True ))
89133@pytest .mark .parametrize ("fmt" , ["itk" , "fsl" , "afni" , "lta" ])
90134def test_loadsave (tmp_path , data_path , testdata_path , autofmt , fmt ):
0 commit comments