@@ -3062,7 +3062,7 @@ def no_fsl():
30623062
30633063
30643064@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
3065- def test_fsl (data_tests_dir ):
3065+ def test_fsl (data_tests_dir , tmp_path ):
30663066 """mandatory field added to fields, value provided"""
30673067
30683068 _xor_inputs = [
@@ -3232,7 +3232,7 @@ class Shelly(ShellDef["Shelly.Outputs"]):
32323232 input : File = shell .arg (argstr = "" , help = "input file" )
32333233
32343234 class Outputs (ShellOutputs ):
3235- output : File = shell .outarg (
3235+ output : File | None = shell .outarg (
32363236 argstr = "" ,
32373237 path_template = "out.txt" ,
32383238 help = "dummy output" ,
@@ -3252,7 +3252,7 @@ class Outputs(ShellOutputs):
32523252
32533253def test_shell_cmd_non_existing_outputs_1 (tmp_path ):
32543254 """Checking that non existing output files do not return a phantom path,
3255- but return NOTHING instead"""
3255+ but return None instead"""
32563256
32573257 @shell .define
32583258 class Shelly (ShellDef ["Shelly.Outputs" ]):
@@ -3264,25 +3264,24 @@ class Shelly(ShellDef["Shelly.Outputs"]):
32643264 )
32653265
32663266 class Outputs (ShellOutputs ):
3267- out_1 : File = shell .outarg (
3267+ out_1 : File | None = shell .out (
32683268 help = "fictional output #1" ,
3269- path_template = "{out_name}_1 .nii" ,
3269+ callable = lambda : "out_1 .nii" ,
32703270 )
3271- out_2 : File = shell .outarg (
3271+ out_2 : File | None = shell .out (
32723272 help = "fictional output #2" ,
3273- path_template = "{out_name}_2 .nii" ,
3273+ callable = lambda : "out_2 .nii" ,
32743274 )
32753275
3276- shelly = Shelly (
3277- out_name = "test" ,
3278- )
3279- outputs = shelly ()
3280- assert outputs .out_1 == attr .NOTHING and outputs .out_2 == attr .NOTHING
3276+ shelly = Shelly (out_name = "test" )
3277+ outputs = shelly (cache_dir = tmp_path )
3278+ assert outputs .out_1 is None
3279+ assert outputs .out_2 is None
32813280
32823281
32833282def test_shell_cmd_non_existing_outputs_2 (tmp_path ):
32843283 """Checking that non existing output files do not return a phantom path,
3285- but return NOTHING instead. This test has one existing and one non existing output file.
3284+ but return None instead. This test has one existing and one non existing output file.
32863285 """
32873286
32883287 @shell .define
@@ -3306,7 +3305,7 @@ class Outputs(ShellOutputs):
33063305 )
33073306
33083307 shelly = Shelly (out_name = "test" )
3309- outputs = shelly ()
3308+ outputs = shelly (cache_dir = tmp_path )
33103309 # the first output file is created
33113310 assert outputs .out_1 .fspath == next (tmp_path .iterdir ()) / "test_1.nii"
33123311 assert outputs .out_1 .fspath .exists ()
@@ -3316,7 +3315,8 @@ class Outputs(ShellOutputs):
33163315
33173316def test_shell_cmd_non_existing_outputs_3 (tmp_path ):
33183317 """Checking that non existing output files do not return a phantom path,
3319- but return NOTHING instead. This test has an existing mandatory output and another non existing output file.
3318+ but return None instead. This test has an existing mandatory output and another
3319+ non existing output file.
33203320 """
33213321
33223322 @shell .define
@@ -3331,55 +3331,51 @@ class Shelly(ShellDef["Shelly.Outputs"]):
33313331
33323332 class Outputs (ShellOutputs ):
33333333 out_1 : File = shell .outarg (
3334- help = "fictional output #1" ,
3335- path_template = "{out_name}_1.nii" ,
3334+ help = "real output #1" ,
3335+ default = "{out_name}_1.nii" ,
33363336 )
3337- out_2 : File = shell .outarg (
3337+ out_2 : File | None = shell .outarg (
33383338 help = "fictional output #2" ,
3339- path_template = "{out_name}_2.nii" ,
3339+ default = "{out_name}_2.nii" ,
33403340 )
33413341
33423342 shelly = Shelly (out_name = "test" )
33433343
3344- outputs = shelly ()
3344+ outputs = shelly (cache_dir = tmp_path )
33453345 # the first output file is created
33463346 assert outputs .out_1 .fspath == next (tmp_path .iterdir ()) / "test_1.nii"
33473347 assert outputs .out_1 .fspath .exists ()
33483348 # the second output file is not created
3349- assert outputs .out_2 == attr . NOTHING
3349+ assert outputs .out_2 is None
33503350
33513351
33523352def test_shell_cmd_non_existing_outputs_4 (tmp_path ):
33533353 """Checking that non existing output files do not return a phantom path,
3354- but return NOTHING instead. This test has an existing mandatory output and another non existing
3354+ but return None instead. This test has an existing mandatory output and another non existing
33553355 mandatory output file."""
33563356
33573357 @shell .define
33583358 class Shelly (ShellDef ["Shelly.Outputs" ]):
33593359 executable = "touch"
33603360 out_name : str = shell .arg (
3361- help = """
3362- base name of the pretend outputs.
3363- """ ,
3361+ help = """base name of the pretend outputs.""" ,
33643362 argstr = "{out_name}_1.nii" ,
33653363 )
33663364
33673365 class Outputs (ShellOutputs ):
33683366 out_1 : File = shell .outarg (
33693367 help = "fictional output #1" ,
3370- path_template = "{out_name}_1.nii" ,
3368+ default = "{out_name}_1.nii" ,
33713369 )
33723370 out_2 : File = shell .outarg (
33733371 help = "fictional output #2" ,
3374- path_template = "{out_name}_2.nii" ,
3372+ default = "{out_name}_2.nii" ,
33753373 )
33763374
3377- shelly = Shelly (
3378- out_name = "test" ,
3379- )
3375+ shelly = Shelly (out_name = "test" )
33803376 # An exception should be raised because the second mandatory output does not exist
33813377 with pytest .raises (Exception ) as excinfo :
3382- shelly ()
3378+ shelly (cache_dir = tmp_path )
33833379 assert "mandatory output for variable out_2 does not exist" == str (excinfo .value )
33843380 # checking if the first output was created
33853381 assert (next (tmp_path .iterdir ()) / "test_1.nii" ).exists ()
0 commit comments