|
16 | 16 |
|
17 | 17 |
|
18 | 18 | @python.define(outputs=["b"]) |
19 | | -def arrayout(val): |
| 19 | +def ArrayOut(val): |
20 | 20 | return np.array([val, val]) |
21 | 21 |
|
22 | 22 |
|
23 | 23 | def test_multiout(tmpdir): |
24 | 24 | """testing a simple function that returns a numpy array""" |
25 | | - wf = Workflow("wf", input_spec=["val"], val=2) |
26 | | - wf.add(arrayout(name="mo", val=wf.lzin.val)) |
27 | 25 |
|
28 | | - wf.set_output([("array", wf.mo.lzout.b)]) |
29 | | - wf.cache_dir = tmpdir |
| 26 | + @workflow.define(outputs=["array"]) |
| 27 | + def Workflow(val): |
| 28 | + mo = workflow.add(ArrayOut(val=val)) |
| 29 | + return mo.b |
30 | 30 |
|
31 | | - with Submitter(worker="cf", n_procs=2) as sub: |
32 | | - sub(runnable=wf) |
| 31 | + wf = Workflow(val=2) |
33 | 32 |
|
34 | | - results = wf.result(return_inputs=True) |
| 33 | + with Submitter(worker="cf", cache_dir=tmpdir, n_procs=2) as sub: |
| 34 | + results = sub(wf) |
35 | 35 |
|
36 | | - assert results[0] == {"wf.val": 2} |
37 | | - assert np.array_equal(results[1].output.array, np.array([2, 2])) |
| 36 | + assert np.array_equal(results.outputs.array, np.array([2, 2])) |
38 | 37 |
|
39 | 38 |
|
40 | 39 | def test_multiout_st(tmpdir): |
41 | 40 | """testing a simple function that returns a numpy array, adding splitter""" |
42 | | - wf = Workflow("wf", input_spec=["val"], val=[0, 1, 2]) |
43 | | - wf.add(arrayout(name="mo")) |
44 | | - wf.mo.split("val", val=wf.lzin.val).combine("val") |
45 | 41 |
|
46 | | - wf.set_output([("array", wf.mo.lzout.b)]) |
47 | | - wf.cache_dir = tmpdir |
| 42 | + @workflow.define(outputs=["array"]) |
| 43 | + def Workflow(values): |
| 44 | + mo = workflow.add(ArrayOut().split(val=values).combine("val")) |
| 45 | + return mo.b |
48 | 46 |
|
49 | | - with Submitter(worker="cf", n_procs=2) as sub: |
50 | | - sub(runnable=wf) |
| 47 | + wf = Workflow(values=[0, 1, 2]) |
51 | 48 |
|
52 | | - results = wf.result(return_inputs=True) |
| 49 | + with Submitter(worker="cf", cache_dir=tmpdir, n_procs=2) as sub: |
| 50 | + results = sub(wf) |
53 | 51 |
|
54 | | - assert results[0] == {"wf.val": [0, 1, 2]} |
55 | 52 | for el in range(3): |
56 | | - assert np.array_equal(results[1].output.array[el], np.array([el, el])) |
| 53 | + assert np.array_equal(results.outputs.array[el], np.array([el, el])) |
57 | 54 |
|
58 | 55 |
|
59 | 56 | def test_numpy_hash_1(): |
@@ -81,20 +78,19 @@ def test_numpy_hash_3(): |
81 | 78 |
|
82 | 79 | def test_task_numpyinput_1(tmp_path: Path): |
83 | 80 | """task with numeric numpy array as an input""" |
84 | | - nn = Identity(name="NA") |
85 | | - nn.cache_dir = tmp_path |
86 | | - nn.split(x=[np.array([1, 2]), np.array([3, 4])]) |
| 81 | + nn = Identity().split(x=[np.array([1, 2]), np.array([3, 4])]) |
87 | 82 | # checking the results |
88 | | - results = nn() |
89 | | - assert (results[0].output.out == np.array([1, 2])).all() |
90 | | - assert (results[1].output.out == np.array([3, 4])).all() |
| 83 | + outputs = nn(cache_dir=tmp_path) |
| 84 | + assert (outputs.out[0] == np.array([1, 2])).all() |
| 85 | + assert (outputs.out[1] == np.array([3, 4])).all() |
91 | 86 |
|
92 | 87 |
|
93 | 88 | def test_task_numpyinput_2(tmp_path: Path): |
94 | 89 | """task with numpy array of type object as an input""" |
95 | | - nn = Identity(name="NA") |
96 | | - nn.cache_dir = tmp_path |
97 | | - nn.split(x=[np.array(["VAL1"], dtype=object), np.array(["VAL2"], dtype=object)]) |
| 90 | + nn = Identity().split( |
| 91 | + x=[np.array(["VAL1"], dtype=object), np.array(["VAL2"], dtype=object)] |
| 92 | + ) |
98 | 93 | # checking the results |
99 | | - results = nn() |
100 | | - assert (results[0].output.out == np.array(["VAL1"], dtype=object)).all() |
| 94 | + outputs = nn(cache_dir=tmp_path) |
| 95 | + assert outputs.out[0] == np.array(["VAL1"], dtype=object) |
| 96 | + assert outputs.out[1] == np.array(["VAL2"], dtype=object) |
0 commit comments