Commit 4aef19a5 authored by payno's avatar payno
Browse files

[io][test_input_information] add test on the input information

parent bac7880a
...@@ -29,6 +29,7 @@ __date__ = "07/21/2021" ...@@ -29,6 +29,7 @@ __date__ = "07/21/2021"
from est.io.utils.information import InputInformation from est.io.utils.information import InputInformation
from est.io.utils.information import SpecInputInformation from est.io.utils.information import SpecInputInformation
from est.app.utils import get_xas_obj
from silx.io.url import DataUrl from silx.io.url import DataUrl
import unittest import unittest
import os import os
...@@ -50,6 +51,7 @@ class TestInputInformation(unittest.TestCase): ...@@ -50,6 +51,7 @@ class TestInputInformation(unittest.TestCase):
"""Test the different way of providing a spec file entry are """Test the different way of providing a spec file entry are
all valid""" all valid"""
self.data_input_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat") self.data_input_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
# first way providing directly url
input_information_1 = InputInformation( input_information_1 = InputInformation(
spectra_url=DataUrl( spectra_url=DataUrl(
file_path=self.data_input_file, file_path=self.data_input_file,
...@@ -62,18 +64,28 @@ class TestInputInformation(unittest.TestCase): ...@@ -62,18 +64,28 @@ class TestInputInformation(unittest.TestCase):
data_path="Column 2", data_path="Column 2",
), ),
) )
xas_obj_1 = get_xas_obj(input_information_1)
self.assertTrue(input_information_1.channel_url is not None)
self.assertTrue(xas_obj_1.energy is not None)
# second way providing only a spec file
input_information_2 = InputInformation( input_information_2 = InputInformation(
spec_input=SpecInputInformation(spec_file=self.data_input_file)
)
input_information_3 = InputInformation(
spec_input=SpecInputInformation( spec_input=SpecInputInformation(
spec_file=self.data_input_file, spec_file=self.data_input_file,
energy_abs_col_name="Column 1", energy_abs_col_name="Column 1",
input_abs_col_name="Column 2", input_abs_col_name="Column 2",
) ),
) )
xas_obj_2 = get_xas_obj(input_information_2)
self.assertTrue(xas_obj_2.energy is not None)
self.assertTrue(xas_obj_2.spectra.data.flat[0] is not None)
self.assertEqual(input_information_1, input_information_2) # third way providing a spec file and column names
self.assertEqual(input_information_1, input_information_3) input_information_3 = InputInformation(
spec_input=SpecInputInformation(
spec_file=self.data_input_file,
),
)
xas_obj_3 = get_xas_obj(input_information_3)
self.assertTrue(xas_obj_3.energy is not None)
self.assertTrue(xas_obj_3.spectra.data.flat[0] is not None)
...@@ -40,10 +40,10 @@ class SpecInputInformation: ...@@ -40,10 +40,10 @@ class SpecInputInformation:
def __init__( def __init__(
self, self,
spec_file, spec_file,
energy_abs_col_name, energy_abs_col_name=None,
input_abs_col_name, input_abs_col_name=None,
input_monitor_col_name, input_monitor_col_name=None,
scan_title, scan_title=None,
): ):
self.__spec_file = None self.__spec_file = None
self.__scan_title = None self.__scan_title = None
...@@ -110,8 +110,8 @@ class InputInformation: ...@@ -110,8 +110,8 @@ class InputInformation:
def __init__( def __init__(
self, self,
spectra_url, spectra_url=None,
channel_url, channel_url=None,
config_url=None, config_url=None,
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0), dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
energy_unit=ur.eV, energy_unit=ur.eV,
...@@ -133,6 +133,14 @@ class InputInformation: ...@@ -133,6 +133,14 @@ class InputInformation:
self.__I2_url = None self.__I2_url = None
self.__mu_ref_url = None self.__mu_ref_url = None
if (
spectra_url is not None or channel_url is not None
) and spec_input is not None:
raise ValueError(
"Either spec input or urls (spectra and channel) "
"must be provided. Not both"
)
self.spectra_url = spectra_url self.spectra_url = spectra_url
self.channel_url = channel_url self.channel_url = channel_url
self.config_url = config_url self.config_url = config_url
......
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