Salome HOME
[test] New test to validate telemac catalogs
authorYOANN AUDOUIN <B61570@dsp0851742.postes.calibre.edf.fr>
Mon, 26 Oct 2020 09:32:45 +0000 (10:32 +0100)
committerYOANN AUDOUIN <B61570@dsp0851742.postes.calibre.edf.fr>
Fri, 30 Oct 2020 16:04:19 +0000 (17:04 +0100)
doc/CMakeLists.txt
doc/salome/CMakeLists.txt [new file with mode: 0644]
doc/salome/examples/CMakeLists.txt [new file with mode: 0644]
doc/salome/examples/CTestTestfileInstall.cmake [new file with mode: 0644]
doc/salome/examples/hs_001_telemac_cata.py [new file with mode: 0644]

index d3de7777e4481207b5c08d2f96fff4e1f1b34fe4..61a6f8d40c064d440772a6cc344303f39f59fcb7 100644 (file)
@@ -21,6 +21,8 @@ SET(RSTFILES
   advanced.rst
 )
 
+ADD_SUBDIRECTORY(salome)
+
 SET(SPHINXOPTS )
 SET(SOURCEDIR ${CMAKE_CURRENT_SOURCE_DIR})
 SET(PAPEROPT_a4 -D latex_paper_size=a4)
@@ -32,8 +34,8 @@ SALOME_CONFIGURE_FILE(conf.py.in conf.py)
 
 SET(HTML_ROOT_FILE html/index.html)
 
-ADD_CUSTOM_COMMAND(OUTPUT ${HTML_ROOT_FILE} 
-  COMMAND ${CMAKE_COMMAND} -E make_directory html 
+ADD_CUSTOM_COMMAND(OUTPUT ${HTML_ROOT_FILE}
+  COMMAND ${CMAKE_COMMAND} -E make_directory html
   COMMAND ${CMAKE_COMMAND} -E make_directory doctrees
   COMMAND ${SPHINX_EXECUTABLE} -c ${CMAKE_BINARY_DIR}/doc -b html ${ALLSPHINXOPTS} html
   DEPENDS ${RSTFILES}
@@ -41,7 +43,7 @@ ADD_CUSTOM_COMMAND(OUTPUT ${HTML_ROOT_FILE}
 
 ADD_CUSTOM_TARGET(BUILD_HTML ALL DEPENDS ${HTML_ROOT_FILE})
 
-INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ 
+INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
   DESTINATION ${SALOME_HYDROSOLVER_INSTALL_DOC}
   PATTERN ".buildinfo" EXCLUDE
 )
diff --git a/doc/salome/CMakeLists.txt b/doc/salome/CMakeLists.txt
new file mode 100644 (file)
index 0000000..da10b1c
--- /dev/null
@@ -0,0 +1,20 @@
+# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# 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
+#
+ADD_SUBDIRECTORY(examples)
diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt
new file mode 100644 (file)
index 0000000..552daa4
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# 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
+#
+SET(EXAMPLES_TESTS
+  hs_001_telemac_cata.py
+)
+
+SET(TEST_INSTALL_DIRECTORY ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test)
+INSTALL(FILES ${EXAMPLES_TESTS} DESTINATION ${TEST_INSTALL_DIRECTORY})
+
+INSTALL(FILES CTestTestfileInstall.cmake
+        DESTINATION ${TEST_INSTALL_DIRECTORY}
+        RENAME CTestTestfile.cmake)
diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake
new file mode 100644 (file)
index 0000000..08f6195
--- /dev/null
@@ -0,0 +1,30 @@
+# 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(SALOME_TEST_DRIVER "$ENV{ABSOLUTE_APPLI_PATH}/bin/salome/appliskel/salome_test_driver.py")
+SET(COMPONENT_NAME HYDROSOLVER)
+SET(TIMEOUT        300)
+
+SET(EXAMPLES_TESTS
+  hs_001_telemac_cata.py
+)
+
+FOREACH(tfile ${EXAMPLES_TESTS})
+  SET(TEST_NAME HYDROSOLVER_${tfile})
+  ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tfile}.py)
+  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}")
+ENDFOREACH()
diff --git a/doc/salome/examples/hs_001_telemac_cata.py b/doc/salome/examples/hs_001_telemac_cata.py
new file mode 100644 (file)
index 0000000..90c79cf
--- /dev/null
@@ -0,0 +1,172 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Modules Python
+import sys
+from os import path, listdir, system, chdir, environ, remove
+from argparse import ArgumentParser
+import shutil
+import re
+
+import salome
+from execution.telemac_cas import TelemacCas, get_dico
+
+# Adding Eficas to PYTHONPATH
+sys.path.append(environ["EFICAS_NOUVEAU_ROOT"])
+try:
+    import Telemac.prefs
+except ImportError as excp:
+    print("Add the path to eficas to PYTHONPATH")
+if hasattr(Telemac.prefs, 'encoding'):
+    # Hack pour changer le codage par defaut des strings
+    import sys
+    reload(sys)
+    sys.setdefaultencoding(prefs.encoding)
+    del sys.setdefaultencoding
+    # Fin hack
+
+HEADER = '\033[95m'
+OKBLUE = '\033[94m'
+OKGREEN = '\033[92m'
+WARNING = '\033[93m'
+FAIL = '\033[91m'
+ENDC = '\033[0m'
+BOLD = '\033[1m'
+UNDERLINE = '\033[4m'
+
+PREFIX = {'telemac2d':'t2d',
+          'telemac3d':'t3d',
+          'tomawac':'tom',
+          'sisyphe':'sis',
+          'artemis':'art',
+          'waqtel':'waq'}
+
+def diff_cas(cas1, cas2):
+    """
+    Diff between two cases will return True if cas.get for each keyword (in
+    both files) returns the same thing
+
+    @param cas1 (TelemacCas) cas1
+    @param cas2 (TelemacCas) cas2
+
+    @returns True if identical
+    """
+
+    # Get the list of keys from cas1 and cas2
+    keys = list(cas1.values.keys())
+    keys.extend(key for key in cas2.values.keys() if key not in keys)
+
+    diff = True
+    for key in keys:
+        val1 = cas1.get(key)
+        val2 = cas2.get(key)
+        if val1 != val2:
+            diff = False
+            print("Differences for {}\n{}: {}\n{}:"\
+                  .format(key,
+                          path.basename(cas1.file_name),
+                          val1,
+                          path.basename(cas2.file_name),
+                          val2,
+                          ))
+
+    return diff
+
+
+def read_write_eficas(module, steering_file, eficas_steering):
+    """
+    Import a steergin file in Eficas and save it back
+
+    @param module Name of the telemac-mascaret module
+    @param steering_file Name of the steering file
+    @param eficas_file Name of the steering file written by Eficas
+    """
+    from InterfaceQT4.eficas_go import getEficasSsIhm
+    code = 'TELEMAC'
+    my_eficas = getEficasSsIhm(code='TELEMAC',labelCode=module)
+
+    handler = my_eficas.fileOpen(steering_file)
+    if not handler:
+        raise Exception(steering_file, "Eficas crashed")
+    if not handler.isJdcValid():
+        report = handler.getJdcRapport()
+        raise Exception(steering_file, report)
+
+    handler.fileSaveAs(eficas_steering)
+
+def validate_catalog(module, root_dir):
+    """
+    Validate a given Catalog for a given module
+
+    @param module Name of the module
+    @param root_dir Telemac root path
+    """
+    print(" "*2, "~> For module", module)
+    examples_dir = path.join(root_dir, 'examples', module)
+    output_dir = path.join(root_dir, 'examples', 'eficas')
+
+    telemac_dico = path.join(root_dir, 'sources', module, module+'.dico')
+
+    crashed = []
+    different = []
+    for example in sorted(listdir(examples_dir)):
+        example_dir = path.join(examples_dir, example)
+        chdir(example_dir)
+        print("  "*3, "~> In example folder ", example_dir)
+        for case in sorted(listdir(example_dir)):
+            if case.endswith('.cas') and \
+               "_reecrit" not in case and \
+               case[0:3] == PREFIX[module] and \
+               "_reecrit" not in case and \
+               "_ori" not in case:
+                # Adding lang extension (.fr for translated french case)
+                print("  "*4, "~> For test case ", case)
+                root, _ = path.splitext(case)
+
+                lang = ''
+                eficas_case = root + "_reecrit.cas"
+
+                # Import and export in eficas
+                try:
+                    read_write_eficas(module, case, eficas_case)
+                except Exception as e:
+                    print(e)
+                    crashed.append(case)
+                    print(" "*8+FAIL+"FAILED"+ENDC)
+                    print(" "*8+"Crashed in eficas")
+                    continue
+
+                ori_cas = TelemacCas(case, telemac_dico)
+                eficas_cas = TelemacCas(eficas_case, telemac_dico)
+
+                isdiff = diff_cas(ori_cas, eficas_cas)
+
+                if not isdiff:
+                    different.append(case)
+                    print(" "*8+FAIL+"FAILED"+ENDC)
+                    print(" "*8+"Diff in steering case")
+                    continue
+
+                # Clean up of files
+                remove(eficas_case)
+
+                # Passed the test case
+                print(" "*8+OKGREEN+"PASSED"+ENDC)
+
+    if crashed != []:
+        print("The following test in", module,
+              " crashed in eficas:", crashed)
+    if different != []:
+        print("The following test in", module,
+              " have a difference with normal run:", different)
+
+salome.salome_init()
+
+#-----------------
+#-- Eficas
+#-----------------
+
+for module in ['telemac2d', 'telemac3d']:
+    # Testing loading of catalog
+    validate_catalog(module, environ["HOMETEL"])
+