test_sub_graph.py 1.9 KB
Newer Older
Wout De Nolf's avatar
Wout De Nolf committed
1
2
3
4
5
6
7
8
9
10
11
12
from ewokscore import load_graph
from ewokscore.utils import qualname
from .utils import assert_taskgraph_result


def myfunc(name=None, value=0):
    print("name:", name, "value:", value)
    return value + 1


def test_sub_graph():
    subsubgraph = {
13
        "graph": {"input_nodes": [{"id": "in", "node": "subsubnode1"}]},
Wout De Nolf's avatar
Wout De Nolf committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        "nodes": [
            {
                "id": "subsubnode1",
                "task_type": "method",
                "task_identifier": qualname(myfunc),
                "default_inputs": [
                    {"name": "name", "value": "subsubnode1"},
                    {"name": "value", "value": 0},
                ],
            }
        ],
    }

    subgraph = {
28
        "graph": {"input_nodes": [{"id": "in", "node": "subnode1", "sub_node": "in"}]},
Wout De Nolf's avatar
Wout De Nolf committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        "nodes": [
            {"id": "subnode1", "task_type": "graph", "task_identifier": subsubgraph}
        ],
    }

    graph = {
        "nodes": [
            {
                "id": "node1",
                "task_type": "method",
                "task_identifier": qualname(myfunc),
                "default_inputs": [
                    {"name": "name", "value": "node1"},
                    {"name": "value", "value": 0},
                ],
            },
            {"id": "node2", "task_type": "graph", "task_identifier": subgraph},
        ],
        "links": [
            {
                "source": "node1",
                "target": "node2",
51
                "sub_target": "in",
Wout De Nolf's avatar
Wout De Nolf committed
52
53
54
55
56
57
58
59
                "data_mapping": [
                    {"target_input": "value", "source_output": "return_value"}
                ],
            }
        ],
    }

    ewoksgraph = load_graph(graph)
60
    tasks = ewoksgraph.execute(results_of_all_nodes=True)
Wout De Nolf's avatar
Wout De Nolf committed
61
62
63
64
65
    expected = {
        "node1": {"return_value": 1},
        ("node2", ("subnode1", "subsubnode1")): {"return_value": 2},
    }
    assert_taskgraph_result(ewoksgraph, expected, tasks=tasks)