Commit 92871b60 authored by payno's avatar payno
Browse files

[orangecontrib][test] add test for converting esrf task graph to ows and .ows...

[orangecontrib][test] add test for converting esrf task graph to ows and .ows to graph with the current est implementation
parent 13493a73
......@@ -31,6 +31,7 @@ import unittest
from .test_larch_workflow import suite as test_larch_workflow_suite
from .test_pymca_workflow import suite as test_pymca_workflow_suite
from .test_converter import suite as test_converter_suite
from .test_workflow_concept import suite as test_workflow_concept_suite
from ..widgets import test as test_widgets
......@@ -40,6 +41,7 @@ def suite(loader=None, pattern="test*.py"):
test_suite.addTest(test_larch_workflow_suite())
test_suite.addTest(test_pymca_workflow_suite())
test_suite.addTests(test_converter_suite())
test_suite.addTest(test_workflow_concept_suite())
return test_suite
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "15/03/2021"
import unittest
from est.core.utils import DownloadDataset
from esrf2orange3.owsconvert import ows_to_esrf, esrf_to_ows
from esrftaskgraph.graph import TaskGraph
import tempfile
import shutil
import os
class TestOwsToGraph(unittest.TestCase):
"""Test conversion of a .ows using est classes to an esrf graph"""
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
file_pymca = "ows_files/example_pymca.ows"
file_larch = "ows_files/example_larch.ows"
for file_ in (file_larch, file_pymca):
DownloadDataset(dataset=file_, output_folder=self.folder, timeout=2.0)
self.file_pymca = os.path.join(self.folder, "example_pymca.ows")
self.file_larch = os.path.join(self.folder, "example_larch.ows")
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def testTranslation(self):
for input_file, i_task in zip((self.file_pymca, self.file_larch), (6, 5)):
with self.subTest(input_file=input_file):
graph = ows_to_esrf(input_file)
self.assertTrue(isinstance(graph, TaskGraph))
self.assertEqual(len(graph.graph.nodes()), i_task)
self.assertEqual(len(graph.graph.edges()), i_task - 1)
class TestGraphToOws(unittest.TestCase):
"""Insure we can convert an esrf graph using est tasks can be converted
to orange widget"""
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
self.output_ows_file = os.path.join(self.folder, "output.ows")
self.pymca_workflow_dict = {
"directed": True,
"multigraph": False,
"graph": {"name": "PyMca processing"},
"nodes": [
{"inputs": {}, "class": "ignored read", "id": "input"},
{"inputs": {}, "class": "xas writer", "id": "output"},
{
"inputs": {},
"class": "est.core.process.pymca.normalization.PyMca_normalization",
"id": "normalization",
},
{
"inputs": {},
"class": "est.core.process.pymca.exafs.PyMca_exafs",
"id": "exafs",
},
{
"inputs": {},
"class": "est.core.process.pymca.k_weight.PyMca_k_weight",
"id": "k weight",
},
{
"inputs": {},
"class": "est.core.process.pymca.ft.PyMca_ft",
"id": "fourier transform",
},
],
"links": [
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "input",
"target": "normalization",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "normalization",
"target": "exafs",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "exafs",
"target": "k weight",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "k weight",
"target": "fourier transform",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "fourier transform",
"target": "output",
},
],
}
self.larch_workflow_dict = {
"directed": True,
"multigraph": False,
"graph": {"name": "Larch processing"},
"nodes": [
{"inputs": {}, "class": "ignored read", "id": "input"},
{"inputs": {}, "class": "xas writer", "id": "output"},
{
"inputs": {},
"class": "est.core.process.larch.pre_edge.Larch_pre_edge",
"id": "pre edge",
},
{"inputs": {}, "class": "larch_autobk", "id": "autobk"},
{
"inputs": {},
"class": "est.core.process.larch.xftf.Larch_xftf",
"id": "xftf",
},
],
"links": [
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "input",
"target": "pre edge",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "pre edge",
"target": "autobk",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "autobk",
"target": "xftf",
},
{
"arguments": {"xas_obj": "res_xas_obj"},
"source": "xftf",
"target": "output",
},
],
}
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def testTranslation(self):
for graph in (self.larch_workflow_dict, self.pymca_workflow_dict):
with self.subTest(graph=graph):
esrf_to_ows(graph, self.output_ows_file)
self.assertTrue(os.path.exists(self.output_ows_file))
def suite():
test_suite = unittest.TestSuite()
for ui in (TestOwsToGraph, TestGraphToOws):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
if __name__ == "__main__":
unittest.main(defaultTest="suite")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment