|
13 | 13 | ShellSpec,
|
14 | 14 | SpecInfo,
|
15 | 15 | File,
|
| 16 | + Directory, |
16 | 17 | MultiOutputFile,
|
17 | 18 | MultiInputObj,
|
18 | 19 | )
|
@@ -2927,6 +2928,110 @@ def test_shell_cmd_outputspec_7b_error():
|
2927 | 2928 | assert "has to have a callable" in str(e.value)
|
2928 | 2929 |
|
2929 | 2930 |
|
| 2931 | +@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter]) |
| 2932 | +def test_shell_cmd_outputspec_7c(tmpdir, plugin, results_function): |
| 2933 | + """ |
| 2934 | + customised output_spec, adding Directory to the output named by args |
| 2935 | + """ |
| 2936 | + |
| 2937 | + def get_lowest_directory(directory_path): |
| 2938 | + return str(directory_path).replace(str(Path(directory_path).parents[0]), "") |
| 2939 | + |
| 2940 | + cmd = "mkdir" |
| 2941 | + args = [f"{tmpdir}/dir1", f"{tmpdir}/dir2"] |
| 2942 | + |
| 2943 | + my_output_spec = SpecInfo( |
| 2944 | + name="Output", |
| 2945 | + fields=[ |
| 2946 | + ( |
| 2947 | + "resultsDir", |
| 2948 | + attr.ib( |
| 2949 | + type=Directory, |
| 2950 | + metadata={ |
| 2951 | + "output_file_template": "{args}", |
| 2952 | + "help_string": "output file", |
| 2953 | + }, |
| 2954 | + ), |
| 2955 | + ) |
| 2956 | + ], |
| 2957 | + bases=(ShellOutSpec,), |
| 2958 | + ) |
| 2959 | + |
| 2960 | + shelly = ShellCommandTask( |
| 2961 | + name="shelly", |
| 2962 | + executable=cmd, |
| 2963 | + args=args, |
| 2964 | + output_spec=my_output_spec, |
| 2965 | + resultsDir="outdir", |
| 2966 | + ).split("args") |
| 2967 | + |
| 2968 | + res = results_function(shelly, plugin) |
| 2969 | + for index, arg_dir in enumerate(args): |
| 2970 | + assert Path(Path(tmpdir) / Path(arg_dir)).exists() == True |
| 2971 | + assert get_lowest_directory(arg_dir) == f"/dir{index+1}" |
| 2972 | + |
| 2973 | + |
| 2974 | +@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter]) |
| 2975 | +def test_shell_cmd_outputspec_7d(tmpdir, plugin, results_function): |
| 2976 | + """ |
| 2977 | + customised output_spec, adding Directory to the output named by input spec |
| 2978 | + """ |
| 2979 | + |
| 2980 | + def get_lowest_directory(directory_path): |
| 2981 | + return str(directory_path).replace(str(Path(directory_path).parents[0]), "") |
| 2982 | + |
| 2983 | + cmd = "mkdir" |
| 2984 | + |
| 2985 | + my_input_spec = SpecInfo( |
| 2986 | + name="Input", |
| 2987 | + fields=[ |
| 2988 | + ( |
| 2989 | + "resultsDir", |
| 2990 | + attr.ib( |
| 2991 | + type=str, |
| 2992 | + metadata={ |
| 2993 | + "position": 1, |
| 2994 | + "help_string": "new directory", |
| 2995 | + "argstr": "", |
| 2996 | + }, |
| 2997 | + ), |
| 2998 | + ) |
| 2999 | + ], |
| 3000 | + bases=(ShellSpec,), |
| 3001 | + ) |
| 3002 | + |
| 3003 | + my_output_spec = SpecInfo( |
| 3004 | + name="Output", |
| 3005 | + fields=[ |
| 3006 | + ( |
| 3007 | + "resultsDir", |
| 3008 | + attr.ib( |
| 3009 | + type=Directory, |
| 3010 | + metadata={ |
| 3011 | + "output_file_template": "{resultsDir}", |
| 3012 | + "help_string": "output file", |
| 3013 | + }, |
| 3014 | + ), |
| 3015 | + ) |
| 3016 | + ], |
| 3017 | + bases=(ShellOutSpec,), |
| 3018 | + ) |
| 3019 | + |
| 3020 | + shelly = ShellCommandTask( |
| 3021 | + name="shelly", |
| 3022 | + executable=cmd, |
| 3023 | + input_spec=my_input_spec, |
| 3024 | + output_spec=my_output_spec, |
| 3025 | + resultsDir=Path(tmpdir) / Path("test"), |
| 3026 | + ) |
| 3027 | + |
| 3028 | + res = results_function(shelly, plugin) |
| 3029 | + assert (Path(tmpdir) / Path("test")).exists() == True |
| 3030 | + assert get_lowest_directory(res.output.resultsDir) == get_lowest_directory( |
| 3031 | + Path(tmpdir) / Path("test") |
| 3032 | + ) |
| 3033 | + |
| 3034 | + |
2930 | 3035 | @pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
|
2931 | 3036 | def test_shell_cmd_state_outputspec_1(plugin, results_function, tmpdir):
|
2932 | 3037 | """
|
|
0 commit comments