@@ -34,11 +34,51 @@ def test_qformsform_warning(tmp_path, qform_add, sform_add, expectation):
3434 validate = pe .Node (im .ValidateImage (), name = 'validate' , base_dir = str (tmp_path ))
3535 validate .inputs .in_file = fname
3636 res = validate .run ()
37+ out_report = Path (res .outputs .out_report ).read_text ()
3738 if expectation == 'warn' :
38- assert "Note on" in Path (res .outputs .out_report ).read_text ()
39- assert len (Path (res .outputs .out_report ).read_text ()) > 0
39+ assert "Note on" in out_report
4040 elif expectation == 'no_warn' :
41- assert len (Path (res .outputs .out_report ).read_text ()) == 0
41+ assert len (out_report ) == 0
42+
43+
44+ @pytest .mark .parametrize ('qform_code, warning_text' , [
45+ (0 , "Note on orientation" ),
46+ (1 , "WARNING - Invalid qform" ),
47+ ])
48+ def test_bad_qform (tmp_path , qform_code , warning_text ):
49+ fname = str (tmp_path / 'test.nii' )
50+
51+ # make a random image
52+ random_data = np .random .random (size = (5 , 5 , 5 ) + (5 ,))
53+ img = nb .Nifti1Image (random_data , np .eye (4 ))
54+
55+ # Some magic terms from a bad qform in the wild
56+ img .header ['qform_code' ] = qform_code
57+ img .header ['quatern_b' ] = 0
58+ img .header ['quatern_c' ] = 0.998322
59+ img .header ['quatern_d' ] = - 0.0579125
60+ img .to_filename (fname )
61+
62+ validate = pe .Node (im .ValidateImage (), name = 'validate' , base_dir = str (tmp_path ))
63+ validate .inputs .in_file = fname
64+ res = validate .run ()
65+ assert warning_text in Path (res .outputs .out_report ).read_text ()
66+
67+
68+ def test_no_good_affines (tmp_path ):
69+ fname = str (tmp_path / 'test.nii' )
70+
71+ # make a random image
72+ random_data = np .random .random (size = (5 , 5 , 5 ) + (5 ,))
73+ img = nb .Nifti1Image (random_data , None )
74+ img .header ['qform_code' ] = 0
75+ img .header ['sform_code' ] = 0
76+ img .to_filename (fname )
77+
78+ validate = pe .Node (im .ValidateImage (), name = 'validate' , base_dir = str (tmp_path ))
79+ validate .inputs .in_file = fname
80+ res = validate .run ()
81+ assert 'WARNING - Missing orientation information' in Path (res .outputs .out_report ).read_text ()
4282
4383
4484@pytest .mark .parametrize ('nvols, nmasks, ext, factor' , [
0 commit comments