Commit 6f9e4953 authored by payno's avatar payno
Browse files

[unittest] move unit test for pymca to be an optional dependancy

parent f7e1979a
......@@ -7,7 +7,67 @@ variables:
no_proxy: .esrf.fr,localhost
.build_template: &test_linux_template
.build_template: &test_linux_template_pymca
stage: test
before_script:
- arch
- export PYTHONPATH="${PYTHONPATH}:/usr/lib/python3/dist-packages/"
- export LD_LIBRARY_PATH=/lib/i386-linux-gnu/:${LD_LIBRARY_PATH}
- export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu/:${LD_LIBRARY_PATH}
- export XAS_TEST_PROCESS=False
- python --version
- python -m pip install pip --upgrade
- python -m pip install setuptools --upgrade
- python -m pip install numpy --upgrade
- python -m pip install matplotlib
script:
- source ./ci/install_scripts.sh
- install_orange3
- install_anyqt 'master'
- python -m pip install -r requirements.txt
- python -m pip install fabio --upgrade --pre
- python -m pip install silx --upgrade --pre
- python -m pip install pymca --upgrade --pre
- python -m pip install Orange3 --upgrade --pre
- cd xas
- git clone https://gitlab.esrf.fr/payno/pushworkflow.git
- cd -
- python -m pip install -e .
- python -m xas --help
- /usr/bin/xvfb-run --server-args="-screen 0 1024x768x24" -a xas test -v
.build_template: &test_linux_template_larch
stage: test
before_script:
- arch
- export PYTHONPATH="${PYTHONPATH}:/usr/lib/python3/dist-packages/"
- export LD_LIBRARY_PATH=/lib/i386-linux-gnu/:${LD_LIBRARY_PATH}
- export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu/:${LD_LIBRARY_PATH}
- export XAS_TEST_PROCESS=False
- python --version
- python -m pip install pip --upgrade
- python -m pip install setuptools --upgrade
- python -m pip install numpy --upgrade
- python -m pip install matplotlib
script:
- source ./ci/install_scripts.sh
- install_orange3
- install_anyqt 'master'
- python -m pip install -r requirements.txt
- python -m pip install fabio --upgrade --pre
- python -m pip install silx --upgrade --pre
- python -m pip install larch --upgrade --pre
- python -m pip install Orange3 --upgrade --pre
- cd xas
- git clone https://gitlab.esrf.fr/payno/pushworkflow.git
- cd -
- python -m pip install -e .
- python -m xas --help
- /usr/bin/xvfb-run --server-args="-screen 0 1024x768x24" -a xas test -v
.build_template: &test_linux_template_pymca_larch
stage: test
before_script:
- arch
......@@ -36,17 +96,27 @@ variables:
- /usr/bin/xvfb-run --server-args="-screen 0 1024x768x24" -a xas test -v
test:python3.5-stretch-pyqt5:
test:python3.5-stretch-pyqt5_pymca:
image: docker-registry.esrf.fr/dau/tomwer:python3.5_stretch_pyqt5
<<: *test_linux_template_pymca
test:python3.5-stretch-pyqt5_larch:
image: docker-registry.esrf.fr/dau/tomwer:python3.5_stretch_pyqt5
<<: *test_linux_template_pymca
test:python3.5-stretch-pyqt5_pymca_larch:
image: docker-registry.esrf.fr/dau/tomwer:python3.5_stretch_pyqt5
<<: *test_linux_template
<<: *test_linux_template_pymca
test:python3.5-stretch-pyside2:
test:python3.5-stretch-pyside2_pymca_larch:
image: docker-registry.esrf.fr/dau/tomwer:python3.5_stretch_pyqt5
<<: *test_linux_template
<<: *test_linux_template_pymca
test:test-xas-tutorials:
test:test-xas-tutorials_pymca:
type: test
image: docker-registry.esrf.fr/dau/tomwer:python3.5_stretch_pyqt5
before_script:
......
......@@ -30,9 +30,16 @@ import logging
import os
import shutil
import tempfile
import unittest
from silx.gui import qt
from orangecontrib.xas.test.OrangeWorkflowTest import OrangeWorflowTest
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.gui.qtapplicationmanager import QApplicationManager
......@@ -43,6 +50,7 @@ _logger = logging.getLogger(__file__)
app = QApplicationManager()
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestSimplePyMcaWorkflow(OrangeWorflowTest):
"""Test the following workflow:
- XASInputOW
......
......@@ -40,8 +40,8 @@ from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.pymca.normalization
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, \
ProcessRunnable
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn
from orangecontrib.xas.process import ProcessRunnable
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from ..progress import QProgress
......
......@@ -31,12 +31,19 @@ import unittest
import tempfile
import shutil
from xas.core.utils import DownloadDataset
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from ...pushworkflow.scheme.parser import scheme_load
from ..process import exec_
import os
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestWorkflowFromOwsFile(unittest.TestCase):
"""test construction of XAS object"""
def setUp(self):
......
......@@ -31,19 +31,24 @@ import os
import shutil
import tempfile
import unittest
import numpy
from xas.core.process.exafs import PyMca_exafs
from xas.core.process.ft import PyMca_ft
from xas.core.process.k_weight import PyMca_k_weight
from xas.core.io import XASWriter
from xas.core.process.pymca.normalization import PyMca_normalization
from xas.core.types import XASObject
from xas.core.utils import spectra as spectra_utils
from ..reprocessing import exec_
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from xas.core.process.pymca.exafs import PyMca_exafs
from xas.core.process.pymca.ft import PyMca_ft
from xas.core.process.pymca.k_weight import PyMca_k_weight
from xas.core.process.pymca.normalization import PyMca_normalization
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestReprocessing(unittest.TestCase):
"""test construction of XAS object"""
def setUp(self):
......
......@@ -28,12 +28,12 @@ __date__ = "07/25/2019"
import unittest
from .test_io import suite as test_io_suite
from xas.core.process.test.test_roi import suite as test_roi_suite
from .test_exafs import suite as test_exafs_suite
from .test_ft import suite as test_ft_suite
from .test_io import suite as test_io_suite
from .test_k_weight import suite as test_k_weight_suite
from .test_normalization import suite as test_normalization_suite
from .test_roi import suite as test_roi_suite
from .test_workflow import suite as test_workflow_suite
......
......@@ -30,14 +30,21 @@ __date__ = "06/11/2019"
import os
import unittest
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.exafs import pymca_exafs
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.pymca.exafs import pymca_exafs
from xas.io.utils.pymca import read_spectrum
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.types import Spectrum, XASObject
from xas.io.utils.pymca import read_spectrum
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestEXAFSSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def setUp(self):
......
......@@ -29,17 +29,22 @@ __date__ = "06/11/2019"
import os
import unittest
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.exafs import pymca_exafs
from xas.core.process.ft import pymca_ft
from xas.core.process.k_weight import pymca_k_weight
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.types import XASObject, Spectrum
from xas.io.utils.pymca import read_spectrum
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.pymca.exafs import pymca_exafs
from xas.core.process.pymca.ft import pymca_ft
from xas.core.process.pymca.k_weight import pymca_k_weight
from xas.core.process.pymca.normalization import pymca_normalization
from xas.io.utils.pymca import read_spectrum
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestFTSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def setUp(self):
......
......@@ -26,19 +26,24 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
import shutil
import tempfile
import h5py
import numpy
import os
import unittest
from xas.core.io import XASWriter
from xas.core.io import read as read_xas
from xas.core.utils import spectra as spectra_utils
from xas.core.types import XASObject
from silx.io.url import DataUrl
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
import shutil
import tempfile
import h5py
import numpy
import os
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
class TestReadWrite(unittest.TestCase):
......@@ -50,6 +55,7 @@ class TestReadWrite(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.outputdir)
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
def testReadSpectrum(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
res = read_xas(spectra_url=DataUrl(file_path=data_file,
......
......@@ -29,15 +29,21 @@ __date__ = "06/11/2019"
import os
import unittest
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.k_weight import pymca_k_weight
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.types import Spectrum, XASObject
from xas.io.utils.pymca import read_spectrum
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.k_weight import pymca_k_weight
from xas.core.process.pymca.normalization import pymca_normalization
from xas.io.utils.pymca import read_spectrum
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestKWeightSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def setUp(self):
......
......@@ -31,21 +31,26 @@ import os
import shutil
import tempfile
import unittest
import h5py
import numpy
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from silx.io.url import DataUrl
from xas.core.io import read as read_xas
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.types import Spectrum, XASObject
from xas.core.utils import spectra as spectra_utils
from xas.io.utils.pymca import read_spectrum
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca=True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.pymca.normalization import pymca_normalization
from xas.io.utils.pymca import read_spectrum
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestNormalizationSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
"""Make sure the process is processing correctly on a spectrum"""
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file)
......@@ -71,8 +76,9 @@ class TestNormalizationSingleSpectrum(unittest.TestCase):
self.assertTrue('NormalizedSignal' in res.spectra[0])
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestNormalizationMultipleSpectrum(unittest.TestCase):
""""""
"""Make sure the process is processing correctly on a XASObject spectra"""
def setUp(self):
self.spectra = spectra_utils.create_dataset(shape=(256, 20, 10))
self.energy = numpy.linspace(start=3.26, stop=3.96, num=256)
......
......@@ -22,6 +22,9 @@
# THE SOFTWARE.
#
# ###########################################################################*/
"""
unit test for workflow composed of pymca process
"""
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
......@@ -31,24 +34,29 @@ import os
import shutil
import tempfile
import unittest
import h5py
import numpy
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from silx.io.url import DataUrl
from xas.core.process.exafs import pymca_exafs, PyMca_exafs
from xas.core.process.ft import pymca_ft, PyMca_ft
from xas.core.process.k_weight import pymca_k_weight, PyMca_k_weight
from xas.core.process.roi import xas_roi, _ROI as XASROI
from xas.core.io import XASWriter
from xas.core.io import read as read_xas
from xas.core.process.pymca.normalization import pymca_normalization, \
PyMca_normalization
from xas.core.types import XASObject
from xas.core.utils import spectra as spectra_utils
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.pymca.exafs import pymca_exafs, PyMca_exafs
from xas.core.process.pymca.ft import pymca_ft, PyMca_ft
from xas.core.process.pymca.k_weight import pymca_k_weight, PyMca_k_weight
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.process.pymca.normalization import PyMca_normalization
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestStreamSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def test_pymca_process(self):
......@@ -107,6 +115,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
self.assertTrue(len(out.spectra[0].ft.intensity) > 0)
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestWorkflowAndH5LinkedFile(unittest.TestCase):
"""
Test that the workflow can process and store process in a targeted h5 file
......@@ -167,6 +176,7 @@ class TestWorkflowAndH5LinkedFile(unittest.TestCase):
self.assertEqual(len(processes), 0)
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestSaveFlowAuto(unittest.TestCase):
"""Test that the processing can be stored continuously on a temporary
.h5 file then dump without lost during call to 'dump_xas' of the XASObject
......
......@@ -38,7 +38,7 @@ def suite():
test_suite = unittest.TestSuite()
from xas.core.process.pymca import test as test_process
from xas.core.process import test as test_process
test_suite.addTest(test_process.suite())
from .test_types import suite as test_types_suite
test_suite.addTest(test_types_suite())
......
......@@ -36,13 +36,22 @@ from xas.core.types import Spectrum, XASObject
from xas.io.utils.pymca import read_spectrum
from xas.core.utils import spectra as spectra_utils
from xas.core.io import read as read_xas
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from silx.io.url import DataUrl
import silx.io.utils
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
class TestSpectrum(unittest.TestCase):
"""Test the spectrum class"""
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
def test_from_dat(self):
"""check that we can create a Spectrum from a pymca .dat file"""
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file)
spectrum = Spectrum(energy=energy, mu=mu)
......@@ -50,6 +59,7 @@ class TestSpectrum(unittest.TestCase):
self.assertTrue(spectrum.mu is not None)
def test_from_numpy_array(self):
"""check that we can create a Spectrum from numpy arrays"""
energy = numpy.arange(10, 20)
mu = numpy.arange(10)
spectrum = Spectrum(energy=energy, mu=mu)
......@@ -62,7 +72,9 @@ class TestSpectrum(unittest.TestCase):
class TestXASObject(unittest.TestCase):
"""test construction of XAS object from a single spectra"""
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
def test_create_from_single_spectrum(self):
"""check that we can create a XASObject from a pymca .dat file"""
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
spectrum = {}
spectrum['Energy'], spectrum['Mu'] = read_spectrum(data_file)
......@@ -82,6 +94,7 @@ class TestXASObject(unittest.TestCase):
self.assertEqual(obj2, obj)
def test_create_from_several_spectrums(self):
"""check that we can create a XASObject from numpy arrays"""
self.spectra = spectra_utils.create_dataset(shape=(256, 20, 10))
self.energy = numpy.linspace(start=3.26, stop=3.96, num=256)
self.output_dir = tempfile.mkdtemp()
......
......@@ -29,22 +29,27 @@ __date__ = "06/12/2019"
import os
import unittest
import xas.core.process.exafs
import xas.core.process.ft
import xas.core.process.k_weight
import xas.core.process.roi
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
import xas.core.io
import xas.core.process.pymca.normalization
from xas.app.process import exec_ as exec_workflow
from xas.core.types import XASObject
from xas.pushworkflow.scheme.link import Link
from xas.pushworkflow.scheme.node import Node
from xas.pushworkflow.scheme.scheme import Scheme
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
import xas.core.process.pymca.exafs
import xas.core.process.pymca.ft
import xas.core.process.pymca.k_weight
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
import xas.core.process.pymca.normalization
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestWorkflowFunctions(unittest.TestCase):
"""Test some processing workflow"""
def setUp(self):
......@@ -53,9 +58,9 @@ class TestWorkflowFunctions(unittest.TestCase):
read_task = Node(callback=xas.core.io.read_frm_file)
normalization_task = Node(
callback=xas.core.process.pymca.normalization.pymca_normalization)
exafs_task = Node(callback=xas.core.process.exafs.pymca_exafs)
k_weight_task = Node(callback=xas.core.process.k_weight.pymca_k_weight)
ft_task = Node(callback=xas.core.process.ft.pymca_ft)
exafs_task = Node(callback=xas.core.process.pymca.exafs.pymca_exafs)
k_weight_task = Node(callback=xas.core.process.pymca.k_weight.pymca_k_weight)
ft_task = Node(callback=xas.core.process.pymca.ft.pymca_ft)
nodes = (
read_task, normalization_task, exafs_task, k_weight_task, ft_task)
......@@ -83,6 +88,7 @@ class TestWorkflowFunctions(unittest.TestCase):
assert 'FTRadius' in xas_obj_out.spectra[0].ft
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestWorkflowCallableClasses(unittest.TestCase):
"""Test some processing workflow"""
def setUp(self):
......@@ -93,9 +99,9 @@ class TestWorkflowCallableClasses(unittest.TestCase):
normalization_task = Node(
callback=xas.core.process.pymca.normalization.PyMca_normalization)
k_weight_task = Node(callback=xas.core.process.k_weight.PyMca_k_weight)
exafs_task = Node(callback=xas.core.process.exafs.PyMca_exafs)
ft_task = Node(callback=xas.core.process.ft.PyMca_ft)
k_weight_task = Node(callback=xas.core.process.pymca.k_weight.PyMca_k_weight)
exafs_task = Node(callback=xas.core.process.pymca.exafs.PyMca_exafs)
ft_task = Node(callback=xas.core.process.pymca.ft.PyMca_ft)
nodes = (read_task, roi_task, normalization_task, k_weight_task,
exafs_task, ft_task)
......
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