From b3c8bb2979932c281da9c83f16a7f9bdeaad444b Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 3 Jul 2024 17:04:12 +0200 Subject: [PATCH] template for a test --- src/freesas/test/meson.build | 1 + src/freesas/test/test_all.py | 4 ++- src/freesas/test/test_dnn.py | 61 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/freesas/test/test_dnn.py diff --git a/src/freesas/test/meson.build b/src/freesas/test/meson.build index 981fa4c..3b82001 100644 --- a/src/freesas/test/meson.build +++ b/src/freesas/test/meson.build @@ -7,6 +7,7 @@ py.install_sources([ 'test_average.py', 'test_bift.py', 'test_cormap.py', +'test_dnn.py', 'test_distance.py', 'test_fitting.py', 'test_model.py', diff --git a/src/freesas/test/test_all.py b/src/freesas/test/test_all.py index 2831e99..00084d1 100644 --- a/src/freesas/test/test_all.py +++ b/src/freesas/test/test_all.py @@ -5,7 +5,7 @@ __author__ = "Guillaume" __license__ = "MIT" __copyright__ = "2015, ESRF" -__date__ = "25/04/2020" +__date__ = "03/07/2024" import unittest from . import test_model @@ -18,6 +18,7 @@ from . import test_sas_argparser from . import test_fitting from . import test_resources +from . import test_dnn def suite(): @@ -32,6 +33,7 @@ def suite(): testSuite.addTest(test_sas_argparser.suite()) testSuite.addTest(test_fitting.suite()) testSuite.addTest(test_resources.suite()) + testSuite.addTest(test_dnn.suite()) return testSuite diff --git a/src/freesas/test/test_dnn.py b/src/freesas/test/test_dnn.py new file mode 100644 index 0000000..bf6824f --- /dev/null +++ b/src/freesas/test/test_dnn.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# Project: freesas +# https://github.com/kif/freesas +# +# Copyright (C) 2024-2024 European Synchrotron Radiation Facility, Grenoble, France +# +# 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__ = ["Jérôme Kieffer"] +__license__ = "MIT" +__date__ = "03/07/2024" + +import unittest +import logging +import os +from .utilstest import get_datafile +from ..resources import resource_filename +from ..sasio import load_scattering_data +# from ..dnn import preprocess +logger = logging.getLogger(__name__) + +class TestDNN(unittest.TestCase): + + def test_preprocess(self): + """ + Test for the preprocessing function + """ + datfile = get_datafile("bsa_005_sub.dat") + data = load_scattering_data(datfile) + q, I, sigma = data.T + # Iprep = preprocess(q, I) + # self.assertEqual(Iprep.max(), 1, msg="range 0-1") + # self.assertEqual(Iprep.shape, 1024, msg="size 1024") + + +def suite(): + test_suite = unittest.TestSuite() + test_suite.addTest(TestDNN("test_preprocess")) + return test_suite + + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(suite())