<commit_before># emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os
import tempfile
import shutil

from nipype.testing import (assert_equal, assert_not_equal, assert_true,
                            assert_raises, skipif)
import nipype.interfaces.fsl.model as fsl
from nipype.interfaces.fsl import Info
from nipype.interfaces.fsl import no_fsl
# XXX Write tests for fsl_model

tmp_infile = None
tmp_dir = None
cwd = None

@skipif(no_fsl)
def setup_infile():
    global tmp_infile, tmp_dir, cwd
    cwd = os.getcwd()
    ext = Info.output_type_to_ext(Info.output_type())
    tmp_dir = tempfile.mkdtemp()
    tmp_infile = os.path.join(tmp_dir, 'foo' + ext)
    file(tmp_infile, 'w')
    os.chdir(tmp_dir)
    return tmp_infile, tmp_dir

def teardown_infile(tmp_dir):
    os.chdir(cwd)
    shutil.rmtree(tmp_dir)


@skipif(no_fsl)
def test_contrastmgr():
    input_map = dict(args = dict(argstr='%s',),
                    contrast_num = dict(argstr='-cope',),
                    corrections = dict(copyfile=False,mandatory=True,),
                    dof_file = dict(copyfile=False,mandatory=True,argstr='',),
                    environ = dict(usedefault=True,),
                    fcon_file = dict(argstr='-f %s',),
                    ignore_exception = dict(usedefault=True,),
                    output_type = dict(),
                    param_estimates = dict(copyfile=False,mandatory=True,argstr='',),
                    sigmasquareds = dict(copyfile=False,mandatory=True,argstr='',),
                    suffix = dict(argstr='-suffix %s',),
                    tcon_file = dict(mandatory=True,argstr='%s',),
                    )
    instance = fsl.ContrastMgr()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value


@skipif(no_fsl)
def test_feat():
    input_map = dict(args = dict(argstr='%s',),
                     environ = dict(),
                     fsf_file = dict(mandatory=True,argstr='%s',),
                     output_type = dict(),
                     )
    instance = fsl.FEAT()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

@skipif(no_fsl)
def test_featmodel():
    input_map = dict(args = dict(argstr='%s',),
                     environ = dict(),
                     fsf_file = dict(copyfile=False,mandatory=True,argstr='%s',),
                     output_type = dict(),
                     )
    instance = fsl.FEATModel()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value


def test_featregister():
    input_map = dict(feat_dirs = dict(mandatory=True,),
                     reg_dof = dict(),
                     reg_image = dict(mandatory=True,),
                     )
    instance = fsl.FEATRegister()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

@skipif(no_fsl)
def test_filmgls():
    input_map = dict(args = dict(argstr='%s',),
                     autocorr_estimate_only = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-ac',),
                    autocorr_noestimate = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-noest',),
                    brightness_threshold = dict(argstr='-epith %d',),
                    design_file = dict(argstr='%s',),
                    environ = dict(usedefault=True,),
                    fit_armodel = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-ar',),
                    full_data = dict(argstr='-v',),
                    ignore_exception = dict(usedefault=True,),
                    in_file = dict(mandatory=True,argstr='%s',),
                    mask_size = dict(argstr='-ms %d',),
                    multitaper_product = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-mt %d',),
                    output_pwdata = dict(argstr='-output_pwdata',),
                    output_type = dict(),
                    results_dir = dict(usedefault=True,argstr='-rn %s',),
                    smooth_autocorr = dict(argstr='-sa',),
                    threshold = dict(argstr='%f',),
                    tukey_window = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-tukey %d',),
                    use_pava = dict(argstr='-pava',),
                    )
    instance = fsl.FILMGLS()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

@skipif(no_fsl)
def test_flameo():
    input_map = dict(args = dict(argstr='%s',),
                     burnin = dict(argstr='--burnin=%d',),
                     cope_file = dict(mandatory=True,argstr='--copefile=%s',),
                     cov_split_file = dict(mandatory=True,argstr='--covsplitfile=%s',),
                     design_file = dict(mandatory=True,argstr='--designfile=%s',),
                     dof_var_cope_file = dict(argstr='--dofvarcopefile=%s',),
                     environ = dict(),
                     f_con_file = dict(argstr='--fcontrastsfile=%s',),
                     fix_mean = dict(argstr='--fixmean',),
                     infer_outliers = dict(argstr='--inferoutliers',),
                     log_dir = dict(argstr='--ld=%s',),
                     mask_file = dict(mandatory=True,argstr='--maskfile=%s',),
                     n_jumps = dict(argstr='--njumps=%d',),
                     no_pe_outputs = dict(argstr='--nopeoutput',),
                     outlier_iter = dict(argstr='--ioni=%d',),
                     output_type = dict(),
                     run_mode = dict(argstr='--runmode=%s',mandatory=True,),
                     sample_every = dict(argstr='--sampleevery=%d',),
                     sigma_dofs = dict(argstr='--sigma_dofs=%d',),<commit_msg>tst: fix filmgls test<commit_after># emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os
import tempfile
import shutil

from nipype.testing import (assert_equal, assert_not_equal, assert_true,
                            assert_raises, skipif)
import nipype.interfaces.fsl.model as fsl
from nipype.interfaces.fsl import Info
from nipype.interfaces.fsl import no_fsl
# XXX Write tests for fsl_model

tmp_infile = None
tmp_dir = None
cwd = None

@skipif(no_fsl)
def setup_infile():
    global tmp_infile, tmp_dir, cwd
    cwd = os.getcwd()
    ext = Info.output_type_to_ext(Info.output_type())
    tmp_dir = tempfile.mkdtemp()
    tmp_infile = os.path.join(tmp_dir, 'foo' + ext)
    file(tmp_infile, 'w')
    os.chdir(tmp_dir)
    return tmp_infile, tmp_dir

def teardown_infile(tmp_dir):
    os.chdir(cwd)
    shutil.rmtree(tmp_dir)


@skipif(no_fsl)
def test_contrastmgr():
    input_map = dict(args = dict(argstr='%s',),
                    contrast_num = dict(argstr='-cope',),
                    corrections = dict(copyfile=False,mandatory=True,),
                    dof_file = dict(copyfile=False,mandatory=True,argstr='',),
                    environ = dict(usedefault=True,),
                    fcon_file = dict(argstr='-f %s',),
                    ignore_exception = dict(usedefault=True,),
                    output_type = dict(),
                    param_estimates = dict(copyfile=False,mandatory=True,argstr='',),
                    sigmasquareds = dict(copyfile=False,mandatory=True,argstr='',),
                    suffix = dict(argstr='-suffix %s',),
                    tcon_file = dict(mandatory=True,argstr='%s',),
                    )
    instance = fsl.ContrastMgr()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value


@skipif(no_fsl)
def test_feat():
    input_map = dict(args = dict(argstr='%s',),
                     environ = dict(),
                     fsf_file = dict(mandatory=True,argstr='%s',),
                     output_type = dict(),
                     )
    instance = fsl.FEAT()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

@skipif(no_fsl)
def test_featmodel():
    input_map = dict(args = dict(argstr='%s',),
                     environ = dict(),
                     fsf_file = dict(copyfile=False,mandatory=True,argstr='%s',),
                     output_type = dict(),
                     )
    instance = fsl.FEATModel()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value


def test_featregister():
    input_map = dict(feat_dirs = dict(mandatory=True,),
                     reg_dof = dict(),
                     reg_image = dict(mandatory=True,),
                     )
    instance = fsl.FEATRegister()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

@skipif(no_fsl)
def test_filmgls():
    input_map = dict(args = dict(argstr='%s',),
                     autocorr_estimate_only = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-ac',),
                    autocorr_noestimate = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-noest',),
                    brightness_threshold = dict(argstr='-epith %d',),
                    design_file = dict(argstr='%s',),
                    environ = dict(usedefault=True,),
                    fit_armodel = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-ar',),
                    full_data = dict(argstr='-v',),
                    ignore_exception = dict(usedefault=True,),
                    in_file = dict(mandatory=True,argstr='%s',),
                    mask_size = dict(argstr='-ms %d',),
                    multitaper_product = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-mt %d',),
                    output_pwdata = dict(argstr='-output_pwdata',),
                    output_type = dict(),
                    results_dir = dict(usedefault=True,argstr='-rn %s',),
                    smooth_autocorr = dict(argstr='-sa',),
                    threshold = dict(argstr='%f',),
                    tukey_window = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='-tukey %d',),
                    use_pava = dict(argstr='-pava',),
                    )
    input_map2 = dict(args = dict(argstr='%s',),
                     autocorr_estimate_only = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='--ac',),
                     autocorr_noestimate = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='--noest',),
                     brightness_threshold = dict(argstr='--epith=%d',),
                     design_file = dict(argstr='--pd=%s',),
                     environ = dict(usedefault=True,),
                     fit_armodel = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='--ar',),
                     full_data = dict(argstr='-v',),
                     ignore_exception = dict(usedefault=True,),
                     in_file = dict(mandatory=True,argstr='--in=%s',),
                     mask_size = dict(argstr='--ms=%d',),
                     multitaper_product = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='--mt=%d',),
                     output_pwdata = dict(argstr='--outputPWdata',),
                     output_type = dict(),
                     results_dir = dict(argstr='--rn=%s',usedefault=True,),
                     smooth_autocorr = dict(argstr='--sa',),
                     terminal_output = dict(mandatory=True,),
                     threshold = dict(usedefault=True,argstr='--thr=%f',),
    tukey_window = dict(xor=['autocorr_estimate_only', 'fit_armodel', 'tukey_window', 'multitaper_product', 'use_pava', 'autocorr_noestimate'],argstr='--tukey=%d',),
    use_pava = dict(argstr='--pava',),
    )
    instance = fsl.FILMGLS()
    if isinstance(instance.inputs, fsl.FILMGLSInputSpec):
        for key, metadata in input_map.items():
            for metakey, value in metadata.items():
                yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value
    else:
        for key, metadata in input_map2.items():
            for metakey, value in metadata.items():
                yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

@skipif(no_fsl)
def test_flameo():
    input_map = dict(args = dict(argstr='%s',),
                     burnin = dict(argstr='--burnin=%d',),
                     cope_file = dict(mandatory=True,argstr='--copefile=%s',),
                     cov_split_file = dict(mandatory=True,argstr='--covsplitfile=%s',),
                     design_file = dict(mandatory=True,argstr='--designfile=%s',),
                     dof_var_cope_file = dict(argstr='--dofvarcopefile=%s',),
                     environ = dict(),
                     f_con_file = dict(argstr='--fcontrastsfile=%s',),
                     fix_mean = dict(argstr='--fixmean',),
                     infer_outliers = dict(argstr='--inferoutliers',),
                     log_dir = dict(argstr='--ld=%s',),
                     mask_file = dict(mandatory=True,argstr='--maskfile=%s',),
                     n_jumps = dict(argstr='--njumps=%d',),
                     no_pe_outputs = dict(argstr='--nopeoutput',),
                     outlier_iter = dict(argstr='--ioni=%d',),
                     output_type = dict(),
                     run_mode = dict(argstr='--runmode=%s',mandatory=True,),
                     sample_every = dict(argstr='--sampleevery=%d',),
                     sigma_dofs = dict(argstr='--sigma_dofs=%d',),
{'fraction_non_alphanumeric': 0.14559412112066136, 'fraction_numerical': 0.0006561249261859458, 'mean_word_length': 2.330128905396548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '5757432', 'n_tokens_mistral': 4945, 'n_tokens_neox': 4777, 'n_words': 769}