@@ -2545,11 +2545,12 @@ def test_shell_cmd_outputspec_4(plugin, results_function, tmpdir):
2545
2545
"""
2546
2546
customised output_spec, adding files to the output,
2547
2547
using a function to collect output, the function is saved in the field metadata
2548
+ and uses output_dir and the glob function
2548
2549
"""
2549
2550
cmd = ["touch" , "newfile_tmp1.txt" , "newfile_tmp2.txt" ]
2550
2551
2551
- def gather_output (keyname , output_dir ):
2552
- if keyname == "newfile" :
2552
+ def gather_output (field , output_dir ):
2553
+ if field . name == "newfile" :
2553
2554
return list (Path (output_dir ).expanduser ().glob ("newfile*.txt" ))
2554
2555
2555
2556
my_output_spec = SpecInfo (
@@ -2568,6 +2569,55 @@ def gather_output(keyname, output_dir):
2568
2569
assert all ([file .exists for file in res .output .newfile ])
2569
2570
2570
2571
2572
+ @pytest .mark .parametrize ("results_function" , [result_no_submitter , result_submitter ])
2573
+ def test_shell_cmd_outputspec_4a (plugin , results_function ):
2574
+ """
2575
+ customised output_spec, adding files to the output,
2576
+ using a function to collect output, the function is saved in the field metadata
2577
+ and uses output_dir and inputs element
2578
+ """
2579
+ cmd = ["touch" , "newfile_tmp1.txt" , "newfile_tmp2.txt" ]
2580
+
2581
+ def gather_output (executable , output_dir ):
2582
+ files = executable [1 :]
2583
+ return [Path (output_dir ) / file for file in files ]
2584
+
2585
+ my_output_spec = SpecInfo (
2586
+ name = "Output" ,
2587
+ fields = [("newfile" , attr .ib (type = File , metadata = {"callable" : gather_output }))],
2588
+ bases = (ShellOutSpec ,),
2589
+ )
2590
+ shelly = ShellCommandTask (name = "shelly" , executable = cmd , output_spec = my_output_spec )
2591
+
2592
+ res = results_function (shelly , plugin )
2593
+ assert res .output .stdout == ""
2594
+ # newfile is a list
2595
+ assert len (res .output .newfile ) == 2
2596
+ assert all ([file .exists for file in res .output .newfile ])
2597
+
2598
+
2599
+ def test_shell_cmd_outputspec_4b_error ():
2600
+ """
2601
+ customised output_spec, adding files to the output,
2602
+ using a function to collect output, the function is saved in the field metadata
2603
+ with an argument that is not part of the inputs - error is raised
2604
+ """
2605
+ cmd = ["touch" , "newfile_tmp1.txt" , "newfile_tmp2.txt" ]
2606
+
2607
+ def gather_output (executable , output_dir , ble ):
2608
+ files = executable [1 :]
2609
+ return [Path (output_dir ) / file for file in files ]
2610
+
2611
+ my_output_spec = SpecInfo (
2612
+ name = "Output" ,
2613
+ fields = [("newfile" , attr .ib (type = File , metadata = {"callable" : gather_output }))],
2614
+ bases = (ShellOutSpec ,),
2615
+ )
2616
+ shelly = ShellCommandTask (name = "shelly" , executable = cmd , output_spec = my_output_spec )
2617
+ with pytest .raises (AttributeError , match = "ble" ):
2618
+ shelly ()
2619
+
2620
+
2571
2621
@pytest .mark .parametrize ("results_function" , [result_no_submitter , result_submitter ])
2572
2622
def test_shell_cmd_outputspec_5 (plugin , results_function , tmpdir ):
2573
2623
"""
0 commit comments