|
14 | 14 | add2_sub2_res,
|
15 | 15 | fun_addvar_none,
|
16 | 16 | fun_addvar_default,
|
| 17 | + fun_write_file, |
| 18 | + fun_write_file_list, |
| 19 | + fun_write_file_list2dict, |
17 | 20 | )
|
18 | 21 | from ..submitter import Submitter
|
19 | 22 | from ..core import Workflow
|
@@ -2825,3 +2828,72 @@ def test_wf_lzoutall_st_2a(plugin):
|
2825 | 2828 | {"out_add": [8, 62], "out_sub": [4, 58]},
|
2826 | 2829 | {"out_add": [62, 602], "out_sub": [58, 598]},
|
2827 | 2830 | ]
|
| 2831 | + |
| 2832 | + |
| 2833 | +# worfklows that have files in the result, the files should be copied to the wf dir |
| 2834 | + |
| 2835 | + |
| 2836 | +@pytest.mark.parametrize("plugin", Plugins) |
| 2837 | +def test_wf_resultfile_1(plugin): |
| 2838 | + """ workflow with a file in the result, file should be copied to the wf dir""" |
| 2839 | + wf = Workflow(name="wf_file_1", input_spec=["x"]) |
| 2840 | + wf.add(fun_write_file(name="writefile", filename=wf.lzin.x)) |
| 2841 | + wf.inputs.x = "file_1.txt" |
| 2842 | + wf.plugin = plugin |
| 2843 | + wf.set_output([("wf_out", wf.writefile.lzout.out)]) |
| 2844 | + |
| 2845 | + with Submitter(plugin=plugin) as sub: |
| 2846 | + sub(wf) |
| 2847 | + |
| 2848 | + results = wf.result() |
| 2849 | + # checking if the file exists and if it is in the Workflow directory |
| 2850 | + assert results.output.wf_out.exists() |
| 2851 | + assert results.output.wf_out == wf.output_dir / "file_1.txt" |
| 2852 | + |
| 2853 | + |
| 2854 | +@pytest.mark.parametrize("plugin", Plugins) |
| 2855 | +def test_wf_resultfile_2(plugin): |
| 2856 | + """ workflow with a list of files in the wf result, |
| 2857 | + all files should be copied to the wf dir |
| 2858 | + """ |
| 2859 | + wf = Workflow(name="wf_file_1", input_spec=["x"]) |
| 2860 | + wf.add(fun_write_file_list(name="writefile", filename_list=wf.lzin.x)) |
| 2861 | + file_list = ["file_1.txt", "file_2.txt", "file_3.txt"] |
| 2862 | + wf.inputs.x = file_list |
| 2863 | + wf.plugin = plugin |
| 2864 | + wf.set_output([("wf_out", wf.writefile.lzout.out)]) |
| 2865 | + |
| 2866 | + with Submitter(plugin=plugin) as sub: |
| 2867 | + sub(wf) |
| 2868 | + |
| 2869 | + results = wf.result() |
| 2870 | + # checking if the file exists and if it is in the Workflow directory |
| 2871 | + for ii, file in enumerate(results.output.wf_out): |
| 2872 | + assert file.exists() |
| 2873 | + assert file == wf.output_dir / file_list[ii] |
| 2874 | + |
| 2875 | + |
| 2876 | +@pytest.mark.parametrize("plugin", Plugins) |
| 2877 | +def test_wf_resultfile_3(plugin): |
| 2878 | + """ workflow with a dictionaries of files in the wf result, |
| 2879 | + all files should be copied to the wf dir |
| 2880 | + """ |
| 2881 | + wf = Workflow(name="wf_file_1", input_spec=["x"]) |
| 2882 | + wf.add(fun_write_file_list2dict(name="writefile", filename_list=wf.lzin.x)) |
| 2883 | + file_list = ["file_1.txt", "file_2.txt", "file_3.txt"] |
| 2884 | + wf.inputs.x = file_list |
| 2885 | + wf.plugin = plugin |
| 2886 | + wf.set_output([("wf_out", wf.writefile.lzout.out)]) |
| 2887 | + |
| 2888 | + with Submitter(plugin=plugin) as sub: |
| 2889 | + sub(wf) |
| 2890 | + |
| 2891 | + results = wf.result() |
| 2892 | + # checking if the file exists and if it is in the Workflow directory |
| 2893 | + for key, val in results.output.wf_out.items(): |
| 2894 | + if key == "random_int": |
| 2895 | + assert val == 20 |
| 2896 | + else: |
| 2897 | + assert val.exists() |
| 2898 | + ii = int(key.split("_")[1]) |
| 2899 | + assert val == wf.output_dir / file_list[ii] |
0 commit comments