]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Testing PyWrapping
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 29 Dec 2017 12:47:03 +0000 (13:47 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 29 Dec 2017 12:47:03 +0000 (13:47 +0100)
src/CTestTestfileInstall.cmake
src/PyWrapping/CMakeLists.txt
src/PyWrapping/CTestTestfileInstall.cmake [new file with mode: 0644]
src/PyWrapping/TestPyWrapGathered_medcoupling.py [new file with mode: 0644]
src/PyWrapping/medcoupling.i
src/PyWrapping/tests.set [new file with mode: 0644]
src/RENUMBER/RenumberingFactory.cxx

index 794a509a1295a1c980efba575951287885bbf326..881ef048994690ad6fcf0f5f17a33b460c2fbe2b 100644 (file)
@@ -30,3 +30,5 @@ SUBDIRS(MEDPartitioner)
 #SUBDIRS(ParaMEDMEMTest)
 SUBDIRS(MEDPartitioner_Swig)
 SUBDIRS(RENUMBER_Swig)
+SUBDIRS(PyWrapping)
+
index e079b999737de285a45af5ccd94422b852c1e311..a978d5ca74b549f8e18ddb81cef538631f6a0d3a 100644 (file)
@@ -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 (file)
index 0000000..0e2eb7f
--- /dev/null
@@ -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 (file)
index 0000000..14a2680
--- /dev/null
@@ -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()
index e95cb251037439b29b4047daa242d019b5ae9047..097cbbfd87c07afd7f9e059eb9ca0d5373289f2f 100644 (file)
@@ -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 (file)
index 0000000..4cabfc4
--- /dev/null
@@ -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
index fd4410e9011414fd75113b222c24ad15f9958c1c..2da7cde909324327eeecc7c95a356728094397ef 100644 (file)
 #endif
 
 #include <iostream>
-
-using namespace std;
+#include <algorithm>
 
 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;
       }