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"]
__license__ = "MIT"
__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
......@@ -44,7 +44,7 @@ from silx.utils.testutils import ParametricTestCase
from xsocs import config
from xsocs.test.utils import test_resources
from import PeakFitter
from import PeakFitter, FitResult, FitTypes, BackgroundTypes
from import FitH5
......@@ -129,6 +129,11 @@ def _cmp_fit_h5_results(test_case,
class TestPeakFitter(ParametricTestCase):
"""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')
def setUpClass(cls):
config.DEFAULT_PROCESS_NUMBER = 2 # Limit number of processes
......@@ -143,43 +148,29 @@ class TestPeakFitter(ParametricTestCase):
self._tmpTestDir = None
def test_nominal(self):
keys = ['fit_f', 'qspace_f']
parameters = [
('gaussian_1.h5', 'qspace_1.h5'),
('gaussian_2.h5', 'qspace_2.h5'),
('gaussian_3.h5', 'qspace_3.h5'),
('gaussian_4.h5', 'qspace_4.h5')
param_dicts = [dict(zip(keys, params)) for params in parameters]
for params in param_dicts:
with self.subTest(**params):
qspace_f = test_resources.getfile(
fit_out = os.path.join(self._tmpTestDir, params['fit_f'])
fitter = PeakFitter(qspace_f)
def test_gaussian(self):
"""Test gaussian fit"""
for fit_f, qspace_f in zip(self._GAUSSIAN_FILES, self._QSPACE_FILES):
with self.subTest(fit_f=fit_f, qspace_f=qspace_f):
# Configure fitting
fitter = PeakFitter(
qspace_f=test_resources.getfile('qspace/' + qspace_f),
self.assertEqual(fitter.status, fitter.READY)
# Run processing
self.assertEqual(fitter.status, fitter.DONE)
results = fitter.results
fit_ref = test_resources.getfile(
fit_ref_h5 = FitH5(fit_ref)
fit_out_h5 = FitH5(fit_out)
# Save as HDF5
fit_out = os.path.join(self._tmpTestDir, fit_f)
_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():
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