From 7d78bd10d5eaa97f4f1877372e42cff469ffce32 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sat, 27 Jan 2018 18:20:16 +0100 Subject: [PATCH] Updating tests to verify savings --- test/CTestTestfileInstall.cmake.in | 1 + test/Makefile.am | 2 + test/test6711/CTestTestfile.cmake | 31 +++++++ test/test6711/Doc_TUI_Exemple_01_Savings.py | 89 +++++++++++++++++++++ test/test6711/utExtend.py | 42 ++++++++++ 5 files changed, 165 insertions(+) create mode 100644 test/test6711/CTestTestfile.cmake create mode 100644 test/test6711/Doc_TUI_Exemple_01_Savings.py create mode 100644 test/test6711/utExtend.py diff --git a/test/CTestTestfileInstall.cmake.in b/test/CTestTestfileInstall.cmake.in index 4077d89..57be46a 100644 --- a/test/CTestTestfileInstall.cmake.in +++ b/test/CTestTestfileInstall.cmake.in @@ -31,6 +31,7 @@ SUBDIRS( test6701 test6702 test6703 + test6711 test6901 test6902 ) diff --git a/test/Makefile.am b/test/Makefile.am index 7cacecc..40a054c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -34,6 +34,7 @@ install-data-local: cp -R $(DIR)test6701 $(SALOMETESTDIR) cp -R $(DIR)test6702 $(SALOMETESTDIR) cp -R $(DIR)test6703 $(SALOMETESTDIR) + cp -R $(DIR)test6711 $(SALOMETESTDIR) cp -R $(DIR)test6901 $(SALOMETESTDIR) cp -R $(DIR)test6902 $(SALOMETESTDIR) cp $(DIR)CTestTestfileInstall.cmake.in $(SALOMETESTDIR)/CTestTestfile.cmake @@ -45,6 +46,7 @@ uninstall-local: rm -rf $(SALOMETESTDIR)/test6701 rm -rf $(SALOMETESTDIR)/test6702 rm -rf $(SALOMETESTDIR)/test6703 + rm -rf $(SALOMETESTDIR)/test6711 rm -rf $(SALOMETESTDIR)/test6901 rm -rf $(SALOMETESTDIR)/test6902 rm $(SALOMETESTDIR)/CTestTestfile.cmake diff --git a/test/test6711/CTestTestfile.cmake b/test/test6711/CTestTestfile.cmake new file mode 100644 index 0000000..2a21699 --- /dev/null +++ b/test/test6711/CTestTestfile.cmake @@ -0,0 +1,31 @@ +# Copyright (C) 2008-2018 EDF R&D +# +# This file is part of SALOME ADAO module +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(TEST_NAMES + Doc_TUI_Exemple_01_Savings + ) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ADAO_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + #ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/test/test6711/Doc_TUI_Exemple_01_Savings.py b/test/test6711/Doc_TUI_Exemple_01_Savings.py new file mode 100644 index 0000000..1731669 --- /dev/null +++ b/test/test6711/Doc_TUI_Exemple_01_Savings.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2018 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D +"Verification d'un exemple de la documentation" + +import os, pprint +from utExtend import assertAlmostEqualArrays + +# ============================================================================== +def test1(): + """Test""" + from numpy import array, matrix + import adaoBuilder + case = adaoBuilder.New() + case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) + case.set( 'Background', Vector=[0, 1, 2] ) + case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) + case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) + case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) + case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) + case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) + # + case.setObserver("Analysis", String="print('==> Nombre d analyses : %i'%len(var))") + # + case.execute() + # + base_file = "output_test6711" + print("") + print("#===============================================================================") + print("#=== Restitution en dictionnaire basique =======================================") + case.get() + print("#===============================================================================") + print("#=== Restitution en fichier TUI ================================================") + # print(case.dump(FileName=base_file+"_TUI.py", Formater="TUI")) + case.dump(FileName=base_file+"_TUI.py", Formater="TUI") + print("#===============================================================================") + print("#=== Restitution en fichier DIC ================================================") + # print(case.dump(FileName=base_file+"_DIC.py", Formater="DIC")) + case.dump(FileName=base_file+"_DIC.py", Formater="DIC") + print("#===============================================================================") + print("#=== Restitution en fichier YACS ===============================================") + # print(case.dump(FileName=base_file+"_YACS.xml", Formater="YACS")) + case.dump(FileName=base_file+"_YACS.xml", Formater="YACS") + print("#===============================================================================") + # + print("") + cwd = os.getcwd() + for f in [ + base_file+"_TUI.py", + base_file+"_DIC.py", + base_file+"_YACS.xml", + ]: + if os.path.exists(os.path.abspath(cwd+"/"+f)): + print("#=== Fichier \"%s\" correctement généré"%f) + os.remove(os.path.abspath(cwd+"/"+f)) + else: + raise ValueError("Fichier \"%s\" inexistant"%f) + print("") + # + return case.get("Analysis")[-1] + +# ============================================================================== +if __name__ == "__main__": + print('\n AUTODIAGNOSTIC\n') + print("""Exemple de la doc : + + Cas-test vérifiant les conversions + ++++++++++++++++++++++++++++++++++ +""") + xa = test1() + assertAlmostEqualArrays(xa, [0.25, 0.80, 0.95], places = 5) diff --git a/test/test6711/utExtend.py b/test/test6711/utExtend.py new file mode 100644 index 0000000..c428c0c --- /dev/null +++ b/test/test6711/utExtend.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2018 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +""" + Unittest extensions for Numpy objects +""" +__author__ = "Jean-Philippe ARGAUD" +__all__ = ["assertAlmostEqualVector"] + +import numpy + +# ============================================================================== +def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None): + "Compare two vectors, like unittest.assertAlmostEqual" + if msg is not None: + print(msg) + if delta is not None: + if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any(): + raise AssertionError("%s != %s within %s places"%(first,second,delta)) + else: + if ( (numpy.asarray(first) - numpy.asarray(second)) > 10**(-int(places)) ).any(): + raise AssertionError("%s != %s within %i places"%(first,second,places)) + return max(abs(numpy.asarray(first) - numpy.asarray(second))) -- 2.39.2