|
| 1 | +from itertools import chain |
| 2 | +from os import listdir |
| 3 | +from os.path import isfile, join, dirname |
| 4 | + |
| 5 | +from Orange.canvas.application import workflows |
| 6 | +from Orange.canvas.scheme import widgetsscheme |
| 7 | +from Orange.canvas.scheme.readwrite import scheme_load |
| 8 | +from Orange.widgets.tests.base import WidgetTest |
| 9 | + |
| 10 | + |
| 11 | +def discover_workflows(tests_dir): |
| 12 | + ows_path = join(tests_dir, "workflows") |
| 13 | + ows_files = [f for f in listdir(ows_path) |
| 14 | + if isfile(join(ows_path, f)) and f.endswith(".ows")] |
| 15 | + for ows_file in ows_files: |
| 16 | + yield join(ows_path, ows_file) |
| 17 | + |
| 18 | +TEST_WORKFLOWS = chain( |
| 19 | + [t.abspath() for t in workflows.example_workflows()], |
| 20 | + discover_workflows(dirname(__file__)) |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +class TestWorkflows(WidgetTest): |
| 25 | + def test_scheme_examples(self): |
| 26 | + """ |
| 27 | + Test if Orange workflow examples can be opened. Examples in canvas |
| 28 | + and also those placed "workflows" subfolder. |
| 29 | + GH-2240 |
| 30 | + """ |
| 31 | + for ows_file in TEST_WORKFLOWS: |
| 32 | + new_scheme = widgetsscheme.WidgetsScheme() |
| 33 | + with open(ows_file, "rb") as f: |
| 34 | + try: |
| 35 | + scheme_load(new_scheme, f) |
| 36 | + except Exception as e: |
| 37 | + self.fail("Old workflow '{}' could not be loaded\n'{}'". |
| 38 | + format(ows_file, str(e))) |
0 commit comments