Commit 5f22ed9a authored by payno's avatar payno
Browse files

[unit test] add a workflow unit test with the four first process. Should ne...

[unit test] add a workflow unit test with the four first process. Should ne executed without any log error from pymca
parent a9aba832
Pipeline #11798 failed with stage
in 12 minutes and 30 seconds
......@@ -32,7 +32,7 @@ from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import xas_process_io
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
import xas.core.process.exafs.pymca_exafs
import xas.core.process.exafs
import logging
_logger = logging.getLogger(__file__)
......
......@@ -32,7 +32,7 @@ from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import xas_process_io
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import XASFourierTransformParameters
import xas.core.process.ft.pymca_ft
import xas.core.process.ft
import logging
_logger = logging.getLogger(__file__)
......
......@@ -32,7 +32,7 @@ from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from xas.core.types import xas_process_io
import xas.core.process.k_weight.pymca_k_weight
import xas.core.process.k_weight
import logging
_logger = logging.getLogger(__file__)
......
......@@ -34,7 +34,7 @@ from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import XASNormalizat
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import xas_process_io
import logging
import xas.core.process.ft.pymca_ft
import xas.core.process.normalization
_logger = logging.getLogger(__file__)
......
......@@ -31,14 +31,13 @@ __date__ = "06/11/2019"
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from xas.core.utils.pymca import read_spectrum
from xas.core.types import xas_process_io
from xas.core.spectrum import Spectrum
from Orange.widgets.settings import Setting
from silx.io.url import DataUrl
import os
import logging
import xas.core.process.io.read
import xas.core.process.io
_logger = logging.getLogger(__file__)
......
......@@ -39,6 +39,7 @@ def pymca_exafs(configuration):
:param dict configuration: should contain the
:return: configuration dict
:rtype: dict
"""
pymca_xas = XASClass()
if 'Energy' not in configuration or 'Mu' not in configuration:
......@@ -50,14 +51,16 @@ def pymca_exafs(configuration):
pymca_xas.setConfiguration(configuration)
# TODO: kvalues could be already store.
if 'EXAFSKValues' in configuration:
if 'EXAFSKValues' in configuration and 'Mu' in configuration:
kValues = configuration['EXAFSKValues']
else:
configuration = pymca_xas.processSpectrum()
e0 = configuration["Edge"]
if 'Mu' not in configuration:
print('********************** computing **********************')
configuration = pymca_xas.processSpectrum()
e0 = configuration['Edge']
energy = configuration['Energy']
mu = configuration['Mu']
kValues = e2k(energy - e0)
mu = configuration['Mu']
res = pymca_xas.postEdge(k=kValues, mu=mu)
res = pymca_xas.mergeConfigurationDicts(configuration, res)
configuration.update(res)
......
......@@ -33,6 +33,7 @@ from .test_exafs import suite as test_exafs_suite
from .test_ft import suite as test_ft_suite
from .test_k_weight import suite as test_k_weight_suite
from .test_normalization import suite as test_normalization_suite
from .test_workflow import suite as test_workflow_suite
def suite():
......@@ -42,4 +43,5 @@ def suite():
test_suite.addTest(test_ft_suite())
test_suite.addTest(test_k_weight_suite())
test_suite.addTest(test_normalization_suite())
test_suite.addTest(test_workflow_suite())
return test_suite
......@@ -28,9 +28,11 @@ __date__ = "06/11/2019"
import unittest
from xas.core.process.exafs import pymca_exafs
from xas.core.process.exafs import pymca_exafs, _logger as pymca_exafs_logger
from PyMca5.PyMcaPhysics.xas.XASClass import _logger as xas_class_logger
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.utils.pymca import read_spectrum
from silx.utils.testutils import TestLogging
import os
......@@ -40,7 +42,9 @@ class TestIO(unittest.TestCase):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
config = {}
config['Energy'], config['Mu'] = read_spectrum(data_file)
res = pymca_exafs(configuration=config)
with TestLogging(pymca_exafs_logger, error=0, warning=0):
with TestLogging(xas_class_logger, error=0, warning=0):
res = pymca_exafs(configuration=config)
self.assertTrue(isinstance(res, dict))
self.assertTrue('PostEdgeB' in res)
self.assertTrue('EXAFSKValues' in res)
......
......@@ -28,9 +28,11 @@ __date__ = "06/11/2019"
import unittest
from xas.core.process.ft import pymca_ft
from xas.core.process.ft import pymca_ft, _logger as pymca_ft_logger
from PyMca5.PyMcaPhysics.xas.XASClass import _logger as xas_class_logger
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.utils.pymca import read_spectrum
from silx.utils.testutils import TestLogging
import os
......@@ -40,7 +42,9 @@ class TestIO(unittest.TestCase):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
config = {}
config['Energy'], config['Mu'] = read_spectrum(data_file)
res = pymca_ft(configuration=config)
with TestLogging(pymca_ft_logger, error=0, warning=0):
with TestLogging(xas_class_logger, error=0, warning=0):
res = pymca_ft(configuration=config)
self.assertTrue(isinstance(res, dict))
self.assertTrue('FTRadius' in res)
self.assertTrue('FTImaginary' in res)
......
......@@ -28,9 +28,11 @@ __date__ = "06/11/2019"
import unittest
from xas.core.process.io import read
from xas.core.process.io import read, _logger as io_logger
from silx.io.url import DataUrl
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from PyMca5.PyMcaPhysics.xas.XASClass import _logger as xas_class_logger
from silx.utils.testutils import TestLogging
import os
......@@ -38,7 +40,9 @@ class TestInput(unittest.TestCase):
"""Make sure the process have valid io"""
def testWithConfiguration(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
res = read(spectrum_url=DataUrl(file_path=data_file, scheme='PyMca'))
with TestLogging(io_logger, error=0, warning=0):
with TestLogging(xas_class_logger, error=0, warning=0):
res = read(spectrum_url=DataUrl(file_path=data_file, scheme='PyMca'))
self.assertTrue(isinstance(res, dict))
self.assertTrue('Mu' in res)
self.assertTrue('Energy' in res)
......
......@@ -28,12 +28,20 @@ __date__ = "06/11/2019"
import unittest
from silx.utils.testutils import TestLogging
from xas.core.process.k_weight import pymca_k_weight, _logger as pymca_k_logger
from PyMca5.PyMcaPhysics.xas.XASClass import _logger as xas_class_logger
class TestIO(unittest.TestCase):
"""Make sure the process have valid io"""
def testWithConfiguration(self):
return
config = {'SET_KWEIGHT': 2.0}
with TestLogging(pymca_k_logger, error=0, warning=0):
with TestLogging(xas_class_logger, error=0, warning=0):
res = pymca_k_weight(configuration=config)
self.assertTrue('SET_KWEIGHT' in res)
def suite():
......
......@@ -28,7 +28,8 @@ __date__ = "06/11/2019"
import unittest
from xas.core.process.normalization import pymca_normalization
from xas.core.process.normalization import pymca_normalization, _logger as pymca_normalization_logger
from silx.utils.testutils import TestLogging
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.utils.pymca import read_spectrum
import os
......@@ -40,7 +41,8 @@ class TestIO(unittest.TestCase):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
config = {}
config['Energy'], config['Mu'] = read_spectrum(data_file)
res = pymca_normalization(configuration=config)
with TestLogging(pymca_normalization_logger, error=0, warning=0):
res = pymca_normalization(configuration=config)
self.assertTrue(isinstance(res, dict))
self.assertTrue('NormalizedMu' in res)
self.assertTrue('NormalizedEnergy' in res)
......
# 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/11/2019"
import unittest
import os
from PyMca5.PyMcaPhysics.xas.XASClass import _logger as xas_class_logger
from silx.utils.testutils import TestLogging
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from silx.io.url import DataUrl
from xas.core.process.exafs import pymca_exafs
from xas.core.process.ft import pymca_ft
from xas.core.process.io import read
from xas.core.process.k_weight import pymca_k_weight
from xas.core.process.normalization import pymca_normalization
class TestStream(unittest.TestCase):
"""Make sure the process have valid io"""
with TestLogging(xas_class_logger, error=0, warning=0):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
out = read(spectrum_url=DataUrl(file_path=data_file, scheme='PyMca'))
out = pymca_normalization(configuration=out)
out = pymca_k_weight(configuration=out)
out = pymca_exafs(configuration=out)
out = pymca_ft(configuration=out)
def suite():
test_suite = unittest.TestSuite()
for ui in (TestStream, ):
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