Commit ce50d120 authored by Thomas Vincent's avatar Thomas Vincent

rework existing tests to use FitResult equality

parent 989e4361
...@@ -31,5 +31,5 @@ __authors__ = ["D. Naudet"] ...@@ -31,5 +31,5 @@ __authors__ = ["D. Naudet"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "01/05/2017" __date__ = "01/05/2017"
from .peak_fit import FitTypes, FitStatus, PeakFitter # noqa from .peak_fit import FitTypes, FitStatus, PeakFitter, FitResult # noqa
from .peak_fit import BackgroundTypes, background_estimation # noqa from .peak_fit import BackgroundTypes, background_estimation # noqa
...@@ -44,7 +44,7 @@ from silx.utils.testutils import ParametricTestCase ...@@ -44,7 +44,7 @@ from silx.utils.testutils import ParametricTestCase
from xsocs import config from xsocs import config
from xsocs.test.utils import test_resources from xsocs.test.utils import test_resources
from xsocs.process.fit import PeakFitter from xsocs.process.fit import PeakFitter, FitResult, FitTypes, BackgroundTypes
from xsocs.io.FitH5 import FitH5 from xsocs.io.FitH5 import FitH5
...@@ -129,6 +129,11 @@ def _cmp_fit_h5_results(test_case, ...@@ -129,6 +129,11 @@ def _cmp_fit_h5_results(test_case,
class TestPeakFitter(ParametricTestCase): class TestPeakFitter(ParametricTestCase):
"""Unit tests of the qspace converter class.""" """Unit tests of the qspace converter class."""
_QSPACE_FILES = 'qspace_1.h5', 'qspace_2.h5', 'qspace_3.h5', 'qspace_4.h5'
_GAUSSIAN_FILES = ('gaussian_1.h5', 'gaussian_2.h5',
'gaussian_3.h5', 'gaussian_4.h5')
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
config.DEFAULT_PROCESS_NUMBER = 2 # Limit number of processes config.DEFAULT_PROCESS_NUMBER = 2 # Limit number of processes
...@@ -143,43 +148,29 @@ class TestPeakFitter(ParametricTestCase): ...@@ -143,43 +148,29 @@ class TestPeakFitter(ParametricTestCase):
shutil.rmtree(self._tmpTestDir) shutil.rmtree(self._tmpTestDir)
self._tmpTestDir = None self._tmpTestDir = None
def test_nominal(self): def test_gaussian(self):
keys = ['fit_f', 'qspace_f'] """Test gaussian fit"""
parameters = [ for fit_f, qspace_f in zip(self._GAUSSIAN_FILES, self._QSPACE_FILES):
('gaussian_1.h5', 'qspace_1.h5'), with self.subTest(fit_f=fit_f, qspace_f=qspace_f):
('gaussian_2.h5', 'qspace_2.h5'), # Configure fitting
('gaussian_3.h5', 'qspace_3.h5'), fitter = PeakFitter(
('gaussian_4.h5', 'qspace_4.h5') qspace_f=test_resources.getfile('qspace/' + qspace_f),
] fit_type=FitTypes.GAUSSIAN,
param_dicts = [dict(zip(keys, params)) for params in parameters] background=BackgroundTypes.NONE)
for params in param_dicts:
with self.subTest(**params):
qspace_f = test_resources.getfile(
'qspace/{0}'.format(params['qspace_f']))
fit_out = os.path.join(self._tmpTestDir, params['fit_f'])
fitter = PeakFitter(qspace_f)
self.assertEqual(fitter.status, fitter.READY) self.assertEqual(fitter.status, fitter.READY)
# Run processing
fitter.peak_fit() fitter.peak_fit()
self.assertEqual(fitter.status, fitter.DONE) self.assertEqual(fitter.status, fitter.DONE)
results = fitter.results # Save as HDF5
fit_out = os.path.join(self._tmpTestDir, fit_f)
results.to_fit_h5(fit_out) fitter.results.to_fit_h5(fit_out)
fit_ref = test_resources.getfile(
'fit_2018_12/{0}'.format(params['fit_f']))
fit_ref_h5 = FitH5(fit_ref)
fit_out_h5 = FitH5(fit_out)
_cmp_fit_h5_files(self, fit_ref_h5, fit_out_h5) # Compare result saved in file
ref = FitResult.from_fit_h5(
test_resources.getfile('fit_2018_12/' + fit_f))
self.assertEqual(ref, FitResult.from_fit_h5(fit_out))
def suite(): def suite():
......
Markdown is supported
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