test_tutorials.py 5.8 KB
Newer Older
Wout De Nolf's avatar
Wout De Nolf committed
1
import pytest
2
from ewoksorange.bindings import ows_to_ewoks
Wout De Nolf's avatar
Wout De Nolf committed
3
from ewoksorange.orange_version import ORANGE_VERSION
4
5
6
7
8
9
10

try:
    from importlib import resources
except ImportError:
    import importlib_resources as resources


11
def test_sumtask_tutorial1_with_qt(ewoks_orange_canvas):
12
13
14
    from orangecontrib.ewoks_example_category import tutorials

    with resources.path(tutorials, "sumtask_tutorial1.ows") as filename:
15
        assert_sumtask_tutorial_with_qt(ewoks_orange_canvas, filename)
16
17
18
19
20
21
22
23
24


def test_sumtask_tutorial1_without_qt(register_ewoks_example_addons):
    from orangecontrib.ewoks_example_category import tutorials

    with resources.path(tutorials, "sumtask_tutorial1.ows") as filename:
        assert_sumtask_tutorial_without_qt(filename)


25
def test_sumtask_tutorial2_with_qt(ewoks_orange_canvas):
26
27
28
    from orangecontrib.evaluate.ewoks_example_submodule import tutorials

    with resources.path(tutorials, "sumtask_tutorial2.ows") as filename:
29
        assert_sumtask_tutorial_with_qt(ewoks_orange_canvas, filename)
30
31
32
33
34
35
36
37
38


def test_sumtask_tutorial2_without_qt(ewoks_orange_canvas):
    from orangecontrib.evaluate.ewoks_example_submodule import tutorials

    with resources.path(tutorials, "sumtask_tutorial2.ows") as filename:
        assert_sumtask_tutorial_without_qt(filename)


39
def test_sumtask_tutorial3_with_qt(ewoks_orange_canvas):
40
41
42
43
44
    from orangecontrib.ewoks_example_supercategory.ewoks_example_subcategory import (
        tutorials,
    )

    with resources.path(tutorials, "sumtask_tutorial3.ows") as filename:
45
        assert_sumtask_tutorial_with_qt(ewoks_orange_canvas, filename)
46
47
48
49
50
51
52
53
54
55
56


def test_sumtask_tutorial3_without_qt(ewoks_orange_canvas):
    from orangecontrib.ewoks_example_supercategory.ewoks_example_subcategory import (
        tutorials,
    )

    with resources.path(tutorials, "sumtask_tutorial3.ows") as filename:
        assert_sumtask_tutorial_without_qt(filename)


57
def test_list_operations_with_qt(ewoks_orange_canvas):
58
59
60
    from orangecontrib.list_operations import tutorials

    with resources.path(tutorials, "sumlist_tutorial.ows") as filename:
61
        assert_sumlist_tutorial_with_qt(ewoks_orange_canvas, filename)
62
63
64
65
66
67
68
69
70


def test_list_operations_without_qt(ewoks_orange_canvas):
    from orangecontrib.list_operations import tutorials

    with resources.path(tutorials, "sumlist_tutorial.ows") as filename:
        assert_sumlist_tutorial_without_qt(filename)


Wout De Nolf's avatar
Wout De Nolf committed
71
72
73
74
@pytest.mark.skipif(
    ORANGE_VERSION == ORANGE_VERSION.oasys_fork,
    reason="Oasys does not have Orange3 widgets",
)
75
76
77
78
79
80
81
def test_mixed_tutorial1_with_qt(ewoks_orange_canvas):
    from orangecontrib.ewoks_example_category import tutorials

    with resources.path(tutorials, "mixed_tutorial1.ows") as filename:
        assert_mixed_tutorial_with_qt(ewoks_orange_canvas, filename)


Wout De Nolf's avatar
Wout De Nolf committed
82
83
84
85
@pytest.mark.skipif(
    ORANGE_VERSION == ORANGE_VERSION.oasys_fork,
    reason="Oasys does not have Orange3 widgets",
)
86
87
88
89
90
91
92
93
def test_mixed_tutorial1_without_qt(register_ewoks_example_addons):
    from orangecontrib.ewoks_example_category import tutorials

    with resources.path(tutorials, "mixed_tutorial1.ows") as filename:
        assert_mixed_tutorial_without_qt(filename)


def assert_sumtask_tutorial_with_qt(ewoks_orange_canvas, filename):
94
95
96
97
    """Execute workflow using the Qt widgets and signals"""
    ewoks_orange_canvas.load_ows(str(filename))
    ewoks_orange_canvas.wait_widgets()
    widgets = list(ewoks_orange_canvas.widgets_from_name("task6"))
98
    results = widgets[0].task_output_values
99
100
101
102
103
104
105
106
107
108
    assert results == {"result": 16}


def assert_sumtask_tutorial_without_qt(filename):
    """Execute workflow after converting it to an ewoks workflow"""
    graph = ows_to_ewoks(filename)
    results = graph.execute()
    assert results["5"].output_values == {"result": 16}


109
def assert_sumlist_tutorial_with_qt(ewoks_orange_canvas, filename):
110
111
    """Execute workflow using the Qt widgets and signals"""
    ewoks_orange_canvas.load_ows(str(filename))
112
113
114
115
116
117

    # Remove artificial delay for this test
    for widget in ewoks_orange_canvas.iter_widgets():
        if "delay" in widget.default_inputs:
            widget.default_inputs["delay"] = 0

118
119
    wgenerator = list(ewoks_orange_canvas.widgets_from_name("List generator"))[0]
    wgenerator.defaultInputsHaveChanged()
120
    results = wgenerator.task_output_values
121
122
    listsum = sum(results["list"])

123
    ewoks_orange_canvas.wait_widgets()
124
125
126
127
128
129
130
131
132
133
134
135

    widgets = list(ewoks_orange_canvas.widgets_from_name("Print list sum"))
    widgets = list(ewoks_orange_canvas.widgets_from_name("Print list sum (1)"))
    widgets = list(ewoks_orange_canvas.widgets_from_name("Print list sum (2)"))
    for w in widgets:
        results = {name: var.value for name, var in w.task_inputs.items()}
        assert results == {"sum": listsum}


def assert_sumlist_tutorial_without_qt(filename):
    """Execute workflow after converting it to an ewoks workflow"""
    graph = ows_to_ewoks(filename)
136
137
138
139
140
141
142

    # Remove artificial delay for this test
    for attrs in graph.graph.nodes.values():
        for adict in attrs.get("default_inputs", list()):
            if adict["name"] == "delay":
                adict["value"] = 0

Wout De Nolf's avatar
Wout De Nolf committed
143
    results = graph.execute(results_of_all_nodes=True)
144
145
146
    listsum = sum(results["0"].output_values["list"])
    for i in [4, 5, 6]:
        assert results[str(i)].input_values == {"sum": listsum}
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161


def assert_mixed_tutorial_with_qt(ewoks_orange_canvas, filename):
    """Execute workflow using the Qt widgets and signals"""
    ewoks_orange_canvas.load_ows(str(filename))
    ewoks_orange_canvas.wait_widgets()
    widgets = list(ewoks_orange_canvas.widgets_from_name("Adder2"))
    results = widgets[0].task_output_values
    assert results == {"result": 3}


def assert_mixed_tutorial_without_qt(filename):
    """Execute workflow after converting it to an ewoks workflow"""
    graph = ows_to_ewoks(filename)
    results = graph.execute()
162
    assert results["1"].output_values == {"result": 3}