test_exec.py 4.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017-2019 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__ = "06/26/2019"


import unittest
import tempfile
import shutil
payno's avatar
payno committed
33
from est.core.utils import DownloadDataset
payno's avatar
payno committed
34
from ewoksorange.owsconvert import ows_to_ewoks
35
import os
36
37
from est.io.utils.information import InputInformation
from silx.io.url import DataUrl
payno's avatar
payno committed
38

39
try:
payno's avatar
PEP8    
payno committed
40
    import PyMca5  # noqa
41
42
43
44
45
except ImportError:
    has_pymca = False
else:
    has_pymca = True
    from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
46
47


payno's avatar
payno committed
48
@unittest.skipIf(has_pymca is False, "PyMca5 is not installed")
49
50
class TestWorkflowFromOwsFile(unittest.TestCase):
    """test construction of XAS object"""
payno's avatar
payno committed
51

52
53
    def setUp(self):
        self.outputdir = tempfile.mkdtemp()
payno's avatar
payno committed
54
55
56
57
58
59
60
61
62
63
        for workflow_file in (
            "ows_files/example_pymca.ows",
            "ows_files/example_larch.ows",
        ):
            DownloadDataset(
                dataset=workflow_file, output_folder=self.outputdir, timeout=2.0
            )
        self.pymca_orange_file = os.path.join(self.outputdir, "example_pymca.ows")
        self.larch_orange_file = os.path.join(self.outputdir, "example_larch.ows")
        self.data_input_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
payno's avatar
payno committed
64
        self.output_file = os.path.join(self.outputdir, "output.h5")
65
66
67
68

    def tearDown(self):
        shutil.rmtree(self.outputdir)

69
    def testPymcaExecWorkflow(self):
70
        """Test regarding the instantiation of the pymcaXAS"""
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
        graph = ows_to_ewoks(filename=self.pymca_orange_file)
        input_information = InputInformation(
            spectra_url=DataUrl(
                file_path=self.data_input_file,
                scheme="PyMca",
                data_path="Column 1",
            ),
            channel_url=DataUrl(
                file_path=self.data_input_file,
                scheme="PyMca",
                data_path="Column 2",
            ),
        )
        varinfo = {
            "input_information": input_information.to_dict(),
            "output_file": self.output_file,
        }
        graph.execute(varinfo=varinfo)
        self.assertTrue(os.path.exists(self.output_file))

    def testLarchExecWorkflow(self):
        """Test regarding the instantiation of the pymcaXAS"""
        graph = ows_to_ewoks(filename=self.pymca_orange_file)
        input_information = InputInformation(
            spectra_url=DataUrl(
                file_path=self.data_input_file,
                scheme="PyMca",
                data_path="Column 1",
            ),
            channel_url=DataUrl(
                file_path=self.data_input_file,
                scheme="PyMca",
                data_path="Column 2",
            ),
        )
        varinfo = {
            "input_information": input_information.to_dict(),
            "output_file": self.output_file,
            "mback": {"z": 29},
        }
        graph.execute(varinfo=varinfo)
        self.assertTrue(os.path.exists(self.output_file))