<commit_before>import time
import numpy as np
import nibabel as nb
from nipype.interfaces import nilearn as nl
from .. import images as im

import pytest
<commit_msg>added tests for the qform sform warning<commit_after>import time
import numpy as np
import nibabel as nb
from nipype.interfaces import nilearn as nl
from .. import images as im
from pathlib import Path

import pytest
qform_code=1
sform_code=1
qform=np.array([[ 1,   0,   0,
          0],
       [  0,   1,  0,
        0],
       [ 0,  0,  1,
        0],
       [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          1.00000000e+00]])
sform=np.array([[ 1,   0,   0,
          0],
       [  0,   1,  0,
        0],
       [ 0,  0,  1,
        0],
       [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          1.00000000e+00]])

@pytest.mark.parametrize('qform_add, sform_add, expectation', [
    (0, 0, "no_warn"),
    (0, 1e-14, "no_warn"),
    (0, 1e-09, "no_warn"),
    (1e-6, 0, "warn"),
    (0, 1e-6, "warn"),
    (1e-5, 0, "warn"),
    (0, 1e-5, "warn"),
    (1e-3, 1e-3, "no_warn")
])
#just a diagonal of ones in both and see that this doesn't warn, then exercise the other possibilities
#only look at the 2 areas of images.py that I added and get code overage of those
def test_qformsform_warning(tmpdir, qform_add, sform_add, expectation):
    tmpdir.chdir()

    # make a random image
    random_data = np.random.random(size=(5, 5, 5) + (5,))
    img = nb.Nifti1Image(random_data, sform+sform_add)
    # set the qform of the image before calling it
    img.set_qform(qform+qform_add)
    img.to_filename('x.nii')
    fname='x.nii'

    interface = im.ValidateImage()
    interface.inputs.in_file = fname
    res = interface.run()
    if expectation == 'warn':
        assert "Note on" in Path(res.outputs.out_report).read_text()
        assert len(Path(res.outputs.out_report).read_text()) > 0
    elif expectation == 'no_warn':
        assert len(Path(res.outputs.out_report).read_text()) == 0
{'fraction_non_alphanumeric': 0.13279678068410464, 'fraction_numerical': 0.0744466800804829, 'mean_word_length': 2.7247191011235956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4544339', 'n_tokens_mistral': 828, 'n_tokens_neox': 747, 'n_words': 207}