Example #1
0
def test_unarymaths(create_files_in_directory_plus_output_type):
    files, testdir, out_ext = create_files_in_directory_plus_output_type

    # Get the command
    maths = fsl.UnaryMaths(in_file="a.nii", out_file="b.nii")

    # Test the underlying command
    assert maths.cmd == "fslmaths"

    # Test that it fails without an operation
    with pytest.raises(ValueError):
        maths.run()

    # Test the different operations
    ops = [
        "exp", "log", "sin", "cos", "sqr", "sqrt", "recip", "abs", "bin",
        "index"
    ]
    for op in ops:
        maths.inputs.operation = op
        assert maths.cmdline == "fslmaths a.nii -{} b.nii".format(op)

    # Test that we don't need to ask for an out file
    for op in ops:
        maths = fsl.UnaryMaths(in_file="a.nii", operation=op)
        assert maths.cmdline == "fslmaths a.nii -{} {}".format(
            op, os.path.join(testdir, "a_{}{}".format(op, out_ext)))
Example #2
0
def test_unarymaths(fsl_output_type=None):
    prev_type = set_output_type(fsl_output_type)
    files, testdir, origdir, out_ext = create_files_in_directory()

    # Get the command
    maths = fsl.UnaryMaths(in_file="a.nii", out_file="b.nii")

    # Test the underlying command
    yield assert_equal, maths.cmd, "fslmaths"

    # Test that it fails without an operation
    yield assert_raises, ValueError, maths.run

    # Test the different operations
    ops = ["exp", "log", "sin", "cos", "sqr", "sqrt", "recip", "abs", "bin", "index"]
    for op in ops:
        maths.inputs.operation = op
        yield assert_equal, maths.cmdline, "fslmaths a.nii -%s b.nii" % op

    # Test that we don't need to ask for an out file
    for op in ops:
        maths = fsl.UnaryMaths(in_file="a.nii", operation=op)
        yield assert_equal, maths.cmdline, "fslmaths a.nii -%s %s" % (op, os.path.join(testdir, "a_%s%s" % (op, out_ext)))

    # Clean up our mess
    clean_directory(testdir, origdir)
    set_output_type(prev_type)