|
1 | 1 | import pytest |
2 | 2 | import shutil, os |
3 | 3 | import time |
4 | | -import platform |
| 4 | +import attr |
5 | 5 |
|
6 | 6 | from .utils import ( |
7 | 7 | add2, |
|
12 | 12 | list_output, |
13 | 13 | fun_addvar3, |
14 | 14 | add2_sub2_res, |
| 15 | + fun_addvar_none, |
| 16 | + fun_addvar_default, |
15 | 17 | ) |
16 | 18 | from ..submitter import Submitter |
17 | 19 | from ..core import Workflow |
18 | | -from ... import mark |
19 | | - |
20 | 20 |
|
21 | 21 | if bool(shutil.which("sbatch")): |
22 | 22 | Plugins = ["cf", "slurm"] |
@@ -229,6 +229,84 @@ def test_wf_2d_outpasdict(plugin): |
229 | 229 | assert wf.output_dir.exists() |
230 | 230 |
|
231 | 231 |
|
| 232 | +@pytest.mark.parametrize("plugin", Plugins) |
| 233 | +def test_wf_3(plugin): |
| 234 | + """ testing None value for an input""" |
| 235 | + wf = Workflow(name="wf_3", input_spec=["x", "y"]) |
| 236 | + wf.add(fun_addvar_none(name="addvar", a=wf.lzin.x, b=wf.lzin.y)) |
| 237 | + wf.add(add2(name="add2", x=wf.addvar.lzout.out)) |
| 238 | + wf.set_output([("out", wf.add2.lzout.out)]) |
| 239 | + wf.inputs.x = 2 |
| 240 | + wf.inputs.y = None |
| 241 | + wf.plugin = plugin |
| 242 | + |
| 243 | + with Submitter(plugin=plugin) as sub: |
| 244 | + sub(wf) |
| 245 | + |
| 246 | + assert wf.output_dir.exists() |
| 247 | + results = wf.result() |
| 248 | + assert 4 == results.output.out |
| 249 | + |
| 250 | + |
| 251 | +@pytest.mark.xfail(reason="the task error doesn't propagate") |
| 252 | +@pytest.mark.parametrize("plugin", Plugins) |
| 253 | +def test_wf_3a_exception(plugin): |
| 254 | + """ testinh wf without set input, attr.NOTHING should be set |
| 255 | + and the function should raise an exception |
| 256 | + """ |
| 257 | + wf = Workflow(name="wf_3", input_spec=["x", "y"]) |
| 258 | + wf.add(fun_addvar_none(name="addvar", a=wf.lzin.x, b=wf.lzin.y)) |
| 259 | + wf.add(add2(name="add2", x=wf.addvar.lzout.out)) |
| 260 | + wf.set_output([("out", wf.add2.lzout.out)]) |
| 261 | + wf.inputs.x = 2 |
| 262 | + wf.inputs.y = attr.NOTHING |
| 263 | + wf.plugin = plugin |
| 264 | + |
| 265 | + with pytest.raises(TypeError) as excinfo: |
| 266 | + with Submitter(plugin=plugin) as sub: |
| 267 | + sub(wf) |
| 268 | + assert "unsupported" in str(excinfo.value) |
| 269 | + |
| 270 | + |
| 271 | +@pytest.mark.parametrize("plugin", Plugins) |
| 272 | +def test_wf_4(plugin): |
| 273 | + """wf with a task that doesn't set one input and use the function default value""" |
| 274 | + wf = Workflow(name="wf_4", input_spec=["x", "y"]) |
| 275 | + wf.add(fun_addvar_default(name="addvar", a=wf.lzin.x)) |
| 276 | + wf.add(add2(name="add2", x=wf.addvar.lzout.out)) |
| 277 | + wf.set_output([("out", wf.add2.lzout.out)]) |
| 278 | + wf.inputs.x = 2 |
| 279 | + wf.plugin = plugin |
| 280 | + |
| 281 | + with Submitter(plugin=plugin) as sub: |
| 282 | + sub(wf) |
| 283 | + |
| 284 | + assert wf.output_dir.exists() |
| 285 | + results = wf.result() |
| 286 | + assert 5 == results.output.out |
| 287 | + |
| 288 | + |
| 289 | +@pytest.mark.parametrize("plugin", Plugins) |
| 290 | +def test_wf_4a(plugin): |
| 291 | + """ wf with a task that doesn't set one input, |
| 292 | + the unset input is send to the task input, |
| 293 | + so the task should use the function default value |
| 294 | + """ |
| 295 | + wf = Workflow(name="wf_4a", input_spec=["x", "y"]) |
| 296 | + wf.add(fun_addvar_default(name="addvar", a=wf.lzin.x, y=wf.lzin.y)) |
| 297 | + wf.add(add2(name="add2", x=wf.addvar.lzout.out)) |
| 298 | + wf.set_output([("out", wf.add2.lzout.out)]) |
| 299 | + wf.inputs.x = 2 |
| 300 | + wf.plugin = plugin |
| 301 | + |
| 302 | + with Submitter(plugin=plugin) as sub: |
| 303 | + sub(wf) |
| 304 | + |
| 305 | + assert wf.output_dir.exists() |
| 306 | + results = wf.result() |
| 307 | + assert 5 == results.output.out |
| 308 | + |
| 309 | + |
232 | 310 | @pytest.mark.parametrize("plugin", Plugins) |
233 | 311 | def test_wf_st_1(plugin): |
234 | 312 | """ Workflow with one task, a splitter for the workflow""" |
|
0 commit comments