Commit 24bbd2be authored by payno's avatar payno
Browse files

[test][ewoks] add two tests on conversion from orange to ewoks and from ewoks to orange

- one for pymca example
- one for larch example
parent 56d83d98
Pipeline #50995 failed with stages
in 6 minutes and 8 seconds
# 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__ = "20/07/2021"
from ewoksorange.owsconvert import ows_to_ewoks, ewoks_to_ows
from ewokscore.graph import TaskGraph
from est.core.utils import DownloadDataset
import unittest
import tempfile
import shutil
import os
import xml.etree.ElementTree as ET
class TestOrangeGraph(unittest.TestCase):
......@@ -18,14 +48,23 @@ class TestOrangeGraph(unittest.TestCase):
DownloadDataset(dataset=file_, output_folder=self.folder, timeout=2.0)
self._example_pymca_ows = os.path.join(self.folder, "example_pymca.ows")
self._example_larch_ows = os.path.join(self.folder, "example_larch.ows")
assert os.path.exists(self._example_larch_ows)
assert os.path.exists(self._example_pymca_ows)
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def test_orange_graph_to_ewo_graph_pymca(self):
"""test conversion of a workflow based on pymca to ewoks graph"""
@staticmethod
def get_link_info(link_node):
return (
link_node.get("sink_channel"),
link_node.get("sink_node_id"),
link_node.get("source_channel"),
link_node.get("source_channel_id"),
)
def test_orange_graph_pymca(self):
"""test conversion of a workflow based on pymca to ewoks graph
from orange to ewoks and from ewoks to orange"""
# step 1: from ows to ewoks graph
graph = ows_to_ewoks(self._example_pymca_ows)
self.assertTrue(isinstance(graph, TaskGraph))
self.assertEqual(len(graph.start_nodes()), 1)
......@@ -41,8 +80,51 @@ class TestOrangeGraph(unittest.TestCase):
self.assertTrue(node in graph.graph.nodes())
self.assertEqual(len(graph.graph.edges), 5)
def test_orange_graph_to_ewo_graph_larch(self):
"""test conversion of a workflow based on pymca to ewoks graph"""
# step 2: from generated ewoks graph to orange
destination = os.path.join(self.folder, "output_pymca_examples.ows")
ewoks_to_ows(ewoksgraph=graph, destination=destination)
self.assertTrue(os.path.exists(destination))
# insure links and nodes are defined
tree = ET.parse(destination)
root = tree.getroot()
children_tags = {elmt.tag: elmt for elmt in root}
# test root element
self.assertTrue("nodes" in children_tags)
self.assertTrue("links" in children_tags)
self.assertTrue("node_properties" in children_tags)
# check nodes
nodes = [elmt for elmt in children_tags["nodes"]]
nodes_by_name = {node.get("name"): node.get("qualified_name") for node in nodes}
qualified_names = (
"orangecontrib.est.widgets.utils.xas_input.XASInputOW",
"orangecontrib.est.widgets.utils.xas_output.XASOutputOW",
"orangecontrib.est.widgets.pymca.normalization.NormalizationOW",
"orangecontrib.est.widgets.pymca.exafs.ExafsOW",
"orangecontrib.est.widgets.pymca.k_weight.KWeightOW",
"orangecontrib.est.widgets.pymca.ft.FTOW",
)
names = (
"input",
"output",
"normalization",
"exafs",
"k weight",
"fourier transform",
)
for q_name, name in zip(qualified_names, names):
self.assertEqual(nodes_by_name[name], q_name)
# check links
links = [elmt for elmt in children_tags["links"]]
links_by_id = {link.get("id"): self.get_link_info(link) for link in links}
self.assertEqual(len(links_by_id), 5)
def test_orange_graph_larch(self):
"""test conversion of a workflow based on larch to ewoks graph
from orange to ewoks and from ewoks to orange"""
# step 1: from ows to ewoks graph
graph = ows_to_ewoks(self._example_larch_ows)
self.assertTrue(isinstance(graph, TaskGraph))
self.assertEqual(len(graph.start_nodes()), 1)
......@@ -50,3 +132,42 @@ class TestOrangeGraph(unittest.TestCase):
for node in ("input", "output", "pre edge", "autobk", "xftf"):
self.assertTrue(node in graph.graph.nodes())
self.assertEqual(len(graph.graph.edges), 4)
# step 2: from generated ewoks graph to orange
destination = os.path.join(self.folder, "output_larch_examples.ows")
ewoks_to_ows(ewoksgraph=graph, destination=destination)
self.assertTrue(os.path.exists(destination))
# insure links and nodes are defined
tree = ET.parse(destination)
root = tree.getroot()
children_tags = {elmt.tag: elmt for elmt in root}
# test root element
self.assertTrue("nodes" in children_tags)
self.assertTrue("links" in children_tags)
self.assertTrue("node_properties" in children_tags)
# check nodes
nodes = [elmt for elmt in children_tags["nodes"]]
nodes_by_name = {node.get("name"): node.get("qualified_name") for node in nodes}
qualified_names = (
"orangecontrib.est.widgets.utils.xas_input.XASInputOW",
"orangecontrib.est.widgets.utils.xas_output.XASOutputOW",
"orangecontrib.est.widgets.larch.pre_edge.PreEdgeOW",
"orangecontrib.est.widgets.larch.autobk.AutobkOW",
"orangecontrib.est.widgets.larch.xftf.XFTFOW",
)
names = (
"input",
"output",
"pre edge",
"autobk",
"xftf",
)
for q_name, name in zip(qualified_names, names):
self.assertEqual(nodes_by_name[name], q_name)
# check links
links = [elmt for elmt in children_tags["links"]]
links_by_id = {link.get("id"): self.get_link_info(link) for link in links}
self.assertEqual(len(links_by_id), 4)
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