From: Cédric Aguerre Date: Tue, 19 Jul 2016 12:00:41 +0000 (+0200) Subject: [MEDCalc] Add tui tests X-Git-Tag: V8_1_0b1~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=684766015f20f7ba14452a1980ba470c67b7f34c;p=modules%2Fmed.git [MEDCalc] Add tui tests --- diff --git a/src/MEDCalc/test/CMakeLists.txt b/src/MEDCalc/test/CMakeLists.txt index 72cf4a1a5..964172e05 100644 --- a/src/MEDCalc/test/CMakeLists.txt +++ b/src/MEDCalc/test/CMakeLists.txt @@ -17,6 +17,8 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +SALOME_CONFIGURE_FILE(medcalc_testutils.py.in ${CMAKE_CURRENT_BINARY_DIR}/medcalc_testutils.py) + IF(SALOME_BUILD_GUI) IF(SALOME_MED_WITH_QTTESTING) ADD_SUBDIRECTORY(gui) @@ -28,6 +30,7 @@ IF(SALOME_MED_ENABLE_PYTHON) ENDIF() SET(TEST_INSTALL_DIRECTORY ${SALOME_MED_INSTALL_TEST}/MEDCalc) +SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/medcalc_testutils.py ${SALOME_INSTALL_SCRIPT_SCRIPTS}) INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} RENAME CTestTestfile.cmake) diff --git a/src/MEDCalc/test/gui/CMakeLists.txt b/src/MEDCalc/test/gui/CMakeLists.txt index 188391e28..dd43e6e7c 100644 --- a/src/MEDCalc/test/gui/CMakeLists.txt +++ b/src/MEDCalc/test/gui/CMakeLists.txt @@ -17,8 +17,6 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SALOME_CONFIGURE_FILE(medcalc_testutils.py.in ${CMAKE_CURRENT_BINARY_DIR}/medcalc_testutils.py) - SET(_test_scripts test_scalarmap.py ) @@ -39,7 +37,6 @@ SET(_test_files SET(TEST_INSTALL_DIRECTORY ${SALOME_MED_INSTALL_TEST}/MEDCalc/gui) SALOME_INSTALL_SCRIPTS(test_qttesting.py ${TEST_INSTALL_DIRECTORY}) -SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/medcalc_testutils.py ${TEST_INSTALL_DIRECTORY}) SALOME_INSTALL_SCRIPTS("${_test_scripts}" ${SALOME_INSTALL_PYTHON}/tests/gui) diff --git a/src/MEDCalc/test/gui/medcalc_testutils.py.in b/src/MEDCalc/test/gui/medcalc_testutils.py.in deleted file mode 100644 index 0b50e06c5..000000000 --- a/src/MEDCalc/test/gui/medcalc_testutils.py.in +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2011-2016 CEA/DEN, 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, 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 -# - -import os - -def __getRootDir(): - rootDir = os.environ.get("MED_ROOT_DIR", "") - return rootDir - -def GetScriptDir(): - relativeDir = "@SALOME_INSTALL_PYTHON@/tests/gui" - return os.path.join(__getRootDir(), relativeDir) - -def GetScenarioDir(): - relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/gui/scenarios" - return os.path.join(__getRootDir(), relativeDir) - -def GetBaselineDir(): - relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/gui/baselines" - return os.path.join(__getRootDir(), relativeDir) - -def GetMEDFileDir(): - relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/gui/medfiles" - return os.path.join(__getRootDir(), relativeDir) diff --git a/src/MEDCalc/test/gui/test_qttesting.py b/src/MEDCalc/test/gui/test_qttesting.py index 1983febb9..b5d421425 100644 --- a/src/MEDCalc/test/gui/test_qttesting.py +++ b/src/MEDCalc/test/gui/test_qttesting.py @@ -45,9 +45,9 @@ class MEDGUITest(unittest.TestCase): def launchSalomeWithScript(self, scriptname): """ TODO: review this - what is the nicest way to launch SALOME GUI from a Python script? """ from salome_instance import SalomeInstance - from medcalc_testutils import GetScriptDir + from medcalc_testutils import GetScriptDirGUI args = "args:%s" % self._tmpDir - pth = os.path.join(GetScriptDir(), scriptname) + pth = os.path.join(GetScriptDirGUI(), scriptname) # Launch SALOME with the test script: inst = SalomeInstance.start(with_gui=True, args=[pth, args]) # And make sure SALOME is stopped before running next one: @@ -60,9 +60,9 @@ class MEDGUITest(unittest.TestCase): """ Compare the screenshot in the current temporary test directory with the reference baseline. Assert if not matching. """ import filecmp - from medcalc_testutils import GetBaselineDir + from medcalc_testutils import GetBaselineDirGUI - base_pth = os.path.join(GetBaselineDir(), basename) + base_pth = os.path.join(GetBaselineDirGUI(), basename) gen_path = os.path.join(self._tmpDir, basename) print base_pth, gen_path try: @@ -79,8 +79,8 @@ class MEDGUITest(unittest.TestCase): def prepareScenario(self, scenario, baseline, med_file): """ Copy scenario to current temporary test dir and substitute paths inside """ - from medcalc_testutils import GetScenarioDir, GetMEDFileDir - scen_path = os.path.join(GetScenarioDir(), scenario) + from medcalc_testutils import GetScenarioDirGUI, GetMEDFileDirGUI + scen_path = os.path.join(GetScenarioDirGUI(), scenario) scen_pth2 = os.path.join(self._tmpDir, scenario) try: shutil.copy(scen_path, scen_pth2) @@ -89,7 +89,7 @@ class MEDGUITest(unittest.TestCase): with open(scen_pth2,'r') as f: filedata = f.read() filedata = filedata.replace("/tmp/%s" % baseline, "%s/%s" % (self._tmpDir, baseline)) - filedata = filedata.replace("/tmp/%s" % med_file, os.path.join(GetMEDFileDir(), med_file)) + filedata = filedata.replace("/tmp/%s" % med_file, os.path.join(GetMEDFileDirGUI(), med_file)) with open(scen_pth2,'w') as f: f.write(filedata) diff --git a/src/MEDCalc/test/gui/test_scalarmap.py b/src/MEDCalc/test/gui/test_scalarmap.py index 6612eb67e..cfcb3dd75 100644 --- a/src/MEDCalc/test/gui/test_scalarmap.py +++ b/src/MEDCalc/test/gui/test_scalarmap.py @@ -17,7 +17,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -""" Test of the scalarmap. +""" Test of the scalarmap. This script is to be passed as an argument of the ./salome command and will be executed within the SALOME Python console. @@ -25,7 +25,8 @@ Python console. import os, sys import SalomePyQt -from medcalc_testutils import GetScenarioDir + +from medcalc_testutils import GetScenarioDirGUI sgPyQt = SalomePyQt.SalomePyQt() sgPyQt.activateModule('MED') @@ -34,4 +35,4 @@ import medcalc # After module activation !! localTestDir = sys.argv[1] medcalc.PlayQtTestingScenario(os.path.join(localTestDir, 'test_scalarmap.xml')) -medcalc.RequestSALOMETermination() # not equivalent to quit()! +medcalc.RequestSALOMETermination() # not equivalent to quit()! diff --git a/src/MEDCalc/test/medcalc_testutils.py.in b/src/MEDCalc/test/medcalc_testutils.py.in new file mode 100644 index 000000000..77e825515 --- /dev/null +++ b/src/MEDCalc/test/medcalc_testutils.py.in @@ -0,0 +1,48 @@ +# Copyright (C) 2011-2016 CEA/DEN, 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, 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 +# + +import os + +def __getRootDir(): + rootDir = os.environ.get("MED_ROOT_DIR", "") + return rootDir + +# === GUI === + +def GetScriptDirGUI(): + relativeDir = "@SALOME_INSTALL_PYTHON@/tests/gui" + return os.path.join(__getRootDir(), relativeDir) + +def GetScenarioDirGUI(): + relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/gui/scenarios" + return os.path.join(__getRootDir(), relativeDir) + +def GetBaselineDirGUI(): + relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/gui/baselines" + return os.path.join(__getRootDir(), relativeDir) + +def GetMEDFileDirGUI(): + relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/gui/medfiles" + return os.path.join(__getRootDir(), relativeDir) + +# === TUI === + +def GetMEDFileDirTUI(): + relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/tui/medfiles" + return os.path.join(__getRootDir(), relativeDir) diff --git a/src/MEDCalc/test/tui/CMakeLists.txt b/src/MEDCalc/test/tui/CMakeLists.txt index 6bb09a53d..5bbaec134 100644 --- a/src/MEDCalc/test/tui/CMakeLists.txt +++ b/src/MEDCalc/test/tui/CMakeLists.txt @@ -17,7 +17,23 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +INCLUDE(tests.set) + +SET(_test_files + medfiles/smooth_surface_and_field.med +) + SET(TEST_INSTALL_DIRECTORY ${SALOME_MED_INSTALL_TEST}/MEDCalc/tui) + +FOREACH(tfile ${TEST_NAMES}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py + DESTINATION ${TEST_INSTALL_DIRECTORY}) +ENDFOREACH() + INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} RENAME CTestTestfile.cmake) + +INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) + +INSTALL(FILES ${_test_files} DESTINATION ${SALOME_MED_INSTALL_RES_DATA}/tests/tui/medfiles) diff --git a/src/MEDCalc/test/tui/CTestTestfileInstall.cmake b/src/MEDCalc/test/tui/CTestTestfileInstall.cmake index f361715a6..91bf41305 100644 --- a/src/MEDCalc/test/tui/CTestTestfileInstall.cmake +++ b/src/MEDCalc/test/tui/CTestTestfileInstall.cmake @@ -16,3 +16,11 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # + +INCLUDE(tests.set) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${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/src/MEDCalc/test/tui/access_API.py b/src/MEDCalc/test/tui/access_API.py new file mode 100644 index 000000000..4dbff4689 --- /dev/null +++ b/src/MEDCalc/test/tui/access_API.py @@ -0,0 +1,27 @@ +# Copyright (C) 2016 CEA/DEN, 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, 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 +# + +import medcalc +medcalc.medconsole.setConsoleGlobals(globals()) +import MEDCALC + +from medcalc.medconsole import saveWorkspace, cleanWorkspace +from medcalc.medconsole import putInWorkspace, removeFromWorkspace +from medcalc.medconsole import accessField +from medcalc.medconsole import getEnvironment, ls, la diff --git a/src/MEDCalc/test/tui/import_pvsimple.py b/src/MEDCalc/test/tui/import_pvsimple.py new file mode 100644 index 000000000..630a200e3 --- /dev/null +++ b/src/MEDCalc/test/tui/import_pvsimple.py @@ -0,0 +1,20 @@ +# Copyright (C) 2016 CEA/DEN, 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, 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 +# + +import pvsimple as pvs diff --git a/src/MEDCalc/test/tui/load_file.py b/src/MEDCalc/test/tui/load_file.py new file mode 100644 index 000000000..ed1e5419c --- /dev/null +++ b/src/MEDCalc/test/tui/load_file.py @@ -0,0 +1,34 @@ +# Copyright (C) 2016 CEA/DEN, 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, 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 +# + +import medcalc +medcalc.medconsole.setConsoleGlobals(globals()) +import MEDCALC + +from medcalc.medconsole import saveWorkspace, cleanWorkspace +from medcalc.medconsole import putInWorkspace, removeFromWorkspace +from medcalc.medconsole import accessField +from medcalc.medconsole import getEnvironment, ls, la + +import os + +from medcalc_testutils import GetMEDFileDirTUI + +datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med") +source_id = medcalc.LoadDataSource(datafile) diff --git a/src/MEDCalc/test/tui/medcalc_test_utils.py b/src/MEDCalc/test/tui/medcalc_test_utils.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/MEDCalc/test/tui/medfiles/smooth_surface_and_field.med b/src/MEDCalc/test/tui/medfiles/smooth_surface_and_field.med new file mode 100644 index 000000000..226ce3b21 Binary files /dev/null and b/src/MEDCalc/test/tui/medfiles/smooth_surface_and_field.med differ diff --git a/src/MEDCalc/test/tui/scalar_map.py b/src/MEDCalc/test/tui/scalar_map.py new file mode 100644 index 000000000..54541ad23 --- /dev/null +++ b/src/MEDCalc/test/tui/scalar_map.py @@ -0,0 +1,38 @@ +# Copyright (C) 2016 CEA/DEN, 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, 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 +# + +import medcalc +medcalc.medconsole.setConsoleGlobals(globals()) +import MEDCALC + +from medcalc.medconsole import saveWorkspace, cleanWorkspace +from medcalc.medconsole import putInWorkspace, removeFromWorkspace +from medcalc.medconsole import accessField +from medcalc.medconsole import getEnvironment, ls, la + +import os + +from medcalc_testutils import GetMEDFileDirTUI + +datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med") +source_id = medcalc.LoadDataSource(datafile) + +presentation_id = medcalc.MakeScalarMap(accessField(source_id), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) + +medcalc.RemovePresentation(presentation_id) diff --git a/src/MEDCalc/test/tui/tests.set b/src/MEDCalc/test/tui/tests.set new file mode 100644 index 000000000..112519ff0 --- /dev/null +++ b/src/MEDCalc/test/tui/tests.set @@ -0,0 +1,25 @@ +# Copyright (C) 2016 CEA/DEN, 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, 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 + access_API + load_file + import_pvsimple +# scalar_map +)