From 1ae13cd7d3a6a72aaa532c5436a8a55973be0531 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 29 Dec 2017 13:47:03 +0100 Subject: [PATCH] Testing PyWrapping --- src/CTestTestfileInstall.cmake | 2 + src/PyWrapping/CMakeLists.txt | 14 +++ src/PyWrapping/CTestTestfileInstall.cmake | 27 +++++ .../TestPyWrapGathered_medcoupling.py | 110 ++++++++++++++++++ src/PyWrapping/medcoupling.i | 2 +- src/PyWrapping/tests.set | 21 ++++ src/RENUMBER/RenumberingFactory.cxx | 23 ++-- 7 files changed, 190 insertions(+), 9 deletions(-) create mode 100644 src/PyWrapping/CTestTestfileInstall.cmake create mode 100644 src/PyWrapping/TestPyWrapGathered_medcoupling.py create mode 100644 src/PyWrapping/tests.set diff --git a/src/CTestTestfileInstall.cmake b/src/CTestTestfileInstall.cmake index 794a509a1..881ef0489 100644 --- a/src/CTestTestfileInstall.cmake +++ b/src/CTestTestfileInstall.cmake @@ -30,3 +30,5 @@ SUBDIRS(MEDPartitioner) #SUBDIRS(ParaMEDMEMTest) SUBDIRS(MEDPartitioner_Swig) SUBDIRS(RENUMBER_Swig) +SUBDIRS(PyWrapping) + diff --git a/src/PyWrapping/CMakeLists.txt b/src/PyWrapping/CMakeLists.txt index e079b9997..a978d5ca7 100644 --- a/src/PyWrapping/CMakeLists.txt +++ b/src/PyWrapping/CMakeLists.txt @@ -92,3 +92,17 @@ ENDIF(WIN32) INSTALL(TARGETS _medcoupling DESTINATION ${MEDCOUPLING_INSTALL_PYTHON}) INSTALL(FILES medcoupling.i medcoupling_pycode DESTINATION ${MEDCOUPLING_INSTALL_HEADERS}) SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/medcoupling.py ${MEDCOUPLING_INSTALL_PYTHON}) + +INCLUDE(tests.set) + +FOREACH(test ${BASE_TESTS}) + GET_FILENAME_COMPONENT(testname ${test} NAME_WE) + ADD_TEST(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test}) + SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}") +ENDFOREACH() + +SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/PyWrapping) + +INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} RENAME CTestTestfile.cmake) +INSTALL(FILES ${BASE_TESTS} DESTINATION ${TEST_INSTALL_DIRECTORY}) +INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) diff --git a/src/PyWrapping/CTestTestfileInstall.cmake b/src/PyWrapping/CTestTestfileInstall.cmake new file mode 100644 index 000000000..0e2eb7f6b --- /dev/null +++ b/src/PyWrapping/CTestTestfileInstall.cmake @@ -0,0 +1,27 @@ +# Copyright (C) 2017 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 +# + +INCLUDE(tests.set) + +FOREACH(tfile ${BASE_TESTS}) + GET_FILENAME_COMPONENT(BASE_NAME ${tfile} NAME_WE) + SET(TEST_NAME ${COMPONENT_NAME}_${BASE_NAME}) + ADD_TEST(${TEST_NAME} python ${tfile}) + SET_TESTS_PROPERTIES( ${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} ) +ENDFOREACH() diff --git a/src/PyWrapping/TestPyWrapGathered_medcoupling.py b/src/PyWrapping/TestPyWrapGathered_medcoupling.py new file mode 100644 index 000000000..14a268000 --- /dev/null +++ b/src/PyWrapping/TestPyWrapGathered_medcoupling.py @@ -0,0 +1,110 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2017 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 +# +# Author : Anthony Geay (EDF R&D) + +from medcoupling import * +import unittest + +class FileCreator(object): + def __init__(self,tester,fname): + self._tester=tester + self._fname=fname + pass + + def fileName(self): + return self._fname + + def __enter__(self): + import os + if os.path.exists(self._fname): + os.remove(self._fname) + pass + return self + + def __exit__(self, type, value, traceback): + import os + if not os.path.exists(self._fname): + self._tester.assertTrue(False) + pass + else: + os.remove(self._fname) + pass + +class medcouplingTest(unittest.TestCase): + + @unittest.skipUnless(HasMEDFileExt(),"Requires link to MED file") + def test1(self): + import sys + fname="mctest1.med" + arr=DataArrayDouble(10) ; arr.iota() + m=MEDCouplingCMesh() + m.setCoords(arr,arr) + m.setName("mesh") + with FileCreator(self,fname) as fc: + m.write(fc.fileName()) + m=m.buildUnstructured() + with FileCreator(self,fname) as fc: + m.write(fc.fileName()) + f=MEDCouplingFieldDouble(ON_NODES) ; f.setMesh(m) ; f.setArray(m.getCoords()) ; f.setName("field") + with FileCreator(self,fname) as fc: + f.write(fc.fileName()) + f=MEDCouplingFieldFloat(ON_NODES) ; f.setMesh(m) + d=DataArrayFloat(m.getNumberOfNodes()) ; d.iota() + f.setArray(d) ; f.setName("field1") + with FileCreator(self,fname) as fc: + f.write(fc.fileName()) + pass + + @unittest.skipUnless(HasRenumberExt(),"Requires Boost or Metis to activate Renumberer") + def test2(self): + arr=DataArrayDouble(10) ; arr.iota() + m=MEDCouplingCMesh() ; m.setCoords(arr,arr) + m=m.buildUnstructured() ; m.setName("mesh") + # + renf=RenumberingFactory("Boost") + neigh,neighi=m.computeNeighborsOfCells() + n2o,o2n=renf.renumber(neigh,neighi) + mRenum=m[n2o] + pass + + @unittest.skipUnless(HasPartitionerExt(),"Requires Partitioner activation") + def test3(self): + arr=DataArrayDouble(10) ; arr.iota() + m=MEDCouplingCMesh() ; m.setCoords(arr,arr) + m=m.buildUnstructured() ; m.setName("mesh") + m.write("all.med") + a,b=m.computeNeighborsOfCells() + sk=MEDCouplingSkyLineArray(b,a) + g=MEDPartitioner.Graph(sk) + g.partGraph(4) + procIdOnCells=g.getPartition().getValuesArray() + m0=m[procIdOnCells.findIdsEqual(0)] ; m0.setName("m0") + m0.write("part0.med") + pass + + @unittest.skipUnless(HasParallelInterpolatorExt(),"Requires // interpolator activated") + def test4(self): + interface=CommInterface() + pass + + pass + +if __name__ == "__main__": + unittest.main() diff --git a/src/PyWrapping/medcoupling.i b/src/PyWrapping/medcoupling.i index e95cb2510..097cbbfd8 100644 --- a/src/PyWrapping/medcoupling.i +++ b/src/PyWrapping/medcoupling.i @@ -92,7 +92,7 @@ #endif } - bool HasParallelInterpolator() + bool HasParallelInterpolatorExt() { #ifdef WITH_PARALLEL_INTERPOLATOR return true; diff --git a/src/PyWrapping/tests.set b/src/PyWrapping/tests.set new file mode 100644 index 000000000..4cabfc492 --- /dev/null +++ b/src/PyWrapping/tests.set @@ -0,0 +1,21 @@ +# Copyright (C) 2017 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 +# +# Author : Anthony Geay (EDF R&D) + +SET(BASE_TESTS TestPyWrapGathered_medcoupling.py) \ No newline at end of file diff --git a/src/RENUMBER/RenumberingFactory.cxx b/src/RENUMBER/RenumberingFactory.cxx index fd4410e90..2da7cde90 100644 --- a/src/RENUMBER/RenumberingFactory.cxx +++ b/src/RENUMBER/RenumberingFactory.cxx @@ -27,20 +27,27 @@ #endif #include - -using namespace std; +#include namespace MED_RENUMBER -{ - Renumbering* RenumberingFactory(const string &s) +{ + bool CompareRenumMeth(const std::string& s1, const char *s2) + { + std::string ss1(s1),ss2(s2); + std::transform(ss1.begin(), ss1.end(), ss1.begin(), ::tolower); + std::transform(ss2.begin(), ss2.end(), ss2.begin(), ::tolower); + return ss1==ss2; + } + + Renumbering* RenumberingFactory(const std::string &s) { #ifdef MED_ENABLE_METIS #ifdef ENABLE_BOOST - if (s==METIS_ALG) + if ( CompareRenumMeth(s,METIS_ALG) ) { return new METISRenumbering; } - else if(s==BOOST_ALG) + else if( CompareRenumMeth(s,BOOST_ALG) ) { return new BOOSTRenumbering; } @@ -51,7 +58,7 @@ namespace MED_RENUMBER } #endif #ifndef ENABLE_BOOST - if (s==METIS_ALG) + if ( CompareRenumMeth(s,METIS_ALG) ) { return new METISRenumbering; } @@ -64,7 +71,7 @@ namespace MED_RENUMBER #endif #ifndef MED_ENABLE_METIS #ifdef ENABLE_BOOST - if (s==BOOST_ALG) + if ( CompareRenumMeth(s,BOOST_ALG) ) { return new BOOSTRenumbering; } -- 2.39.2