def test_multimaths(create_files_in_directory_plus_output_type): files, testdir, out_ext = create_files_in_directory_plus_output_type # Get the command maths = fsl.MultiImageMaths(in_file="a.nii", out_file="c.nii") # Test the underlying command assert maths.cmd == "fslmaths" # Test that it fails without an operation an with pytest.raises(ValueError): maths.run() # Test a few operations maths.inputs.operand_files = ["a.nii", "b.nii"] opstrings = [ "-add %s -div %s", "-max 1 -sub %s -min %s", "-mas %s -add %s" ] for ostr in opstrings: maths.inputs.op_string = ostr assert maths.cmdline == "fslmaths a.nii %s c.nii" % ostr % ("a.nii", "b.nii") # Test that we don't need to ask for an out file maths = fsl.MultiImageMaths(in_file="a.nii", op_string="-add %s -mul 5", operand_files=["b.nii"]) assert maths.cmdline == "fslmaths a.nii -add b.nii -mul 5 %s" % os.path.join( testdir, "a_maths%s" % out_ext)
def test_multimaths(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.MultiImageMaths(in_file="a.nii", out_file="c.nii") # Test the underlying command yield assert_equal, maths.cmd, "fslmaths" # Test that it fails without an operation an yield assert_raises, ValueError, maths.run # Test a few operations maths.inputs.operand_files = ["a.nii", "b.nii"] opstrings = ["-add %s -div %s", "-max 1 -sub %s -min %s", "-mas %s -add %s"] for ostr in opstrings: maths.inputs.op_string = ostr yield assert_equal, maths.cmdline, "fslmaths a.nii %s c.nii" % ostr % ("a.nii", "b.nii") # Test that we don't need to ask for an out file maths = fsl.MultiImageMaths(in_file="a.nii", op_string="-add %s -mul 5", operand_files=["b.nii"]) yield assert_equal, maths.cmdline, \ "fslmaths a.nii -add b.nii -mul 5 %s" % os.path.join(testdir, "a_maths%s" % out_ext) # Clean up our mess clean_directory(testdir, origdir) set_output_type(prev_type)