From: Nabil Ghodbane Date: Tue, 21 Mar 2023 12:14:09 +0000 (+0100) Subject: Fix MEDCOUPLING tests currently on error on Windows OS: X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4dcf437c9b158b447430307b7b52fca80c179bae;p=tools%2Fmedcoupling.git Fix MEDCOUPLING tests currently on error on Windows OS: 1/ fix import in python scripts 2/ fix PYTHONPATH search path in CTestTestfileInstall.cmake consistently for Windows 3/ Implement Linux which equivalent command on Windows --- diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py index 2dd2abcc6..f834e7590 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py @@ -19,10 +19,7 @@ # import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py index ef75ebf43..6018ba3f1 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py index ef24dfb42..59e0c83c3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py @@ -19,10 +19,7 @@ # import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py index b2850aca8..443a957e1 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 58fba2e02..c8864d1ba 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -19,10 +19,7 @@ # import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py index dacf44203..38ffb06c4 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 3a5cacd9f..7f43e34b0 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py index 88495dd38..54ec15bd0 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * class MEDCouplingDataForTest: def build2DTargetMesh_1(cls): diff --git a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py index 5cb37f820..6035b8242 100644 --- a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi, sqrt @@ -34,6 +31,10 @@ def WriteInTmpDir(func): with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) ret = func(*args,**kwargs) + # on windows, if we remain in this temporary directory + # Windows will lock it and deletion attempt will fail + if sys.platform == "win32": + os.chdir(os.path.dirname(tmpdirname)) pass return ret return decoratedFunc diff --git a/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py b/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py index 1712b314e..f49da20ce 100644 --- a/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime diff --git a/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py b/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py index 2903e8fd0..b837feb75 100644 --- a/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * if MEDCouplingHasNumPyBindings(): from numpy import * diff --git a/src/MEDCoupling_Swig/MEDCouplingPickleTest.py b/src/MEDCoupling_Swig/MEDCouplingPickleTest.py index d8fbd0c48..f095af347 100644 --- a/src/MEDCoupling_Swig/MEDCouplingPickleTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingPickleTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * from MEDCouplingDataForTest import MEDCouplingDataForTest if MEDCouplingHasNumPyBindings(): diff --git a/src/MEDCoupling_Swig/UsersGuideExamplesTest.py b/src/MEDCoupling_Swig/UsersGuideExamplesTest.py index 40d966dae..56f8121a9 100755 --- a/src/MEDCoupling_Swig/UsersGuideExamplesTest.py +++ b/src/MEDCoupling_Swig/UsersGuideExamplesTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * from math import pi, sqrt # ! [PySnippetUMeshStdBuild1_1] diff --git a/src/MEDCoupling_Swig/UsersGuideExamplesTest_numpy.py b/src/MEDCoupling_Swig/UsersGuideExamplesTest_numpy.py index 8a1bf605f..607d9992a 100644 --- a/src/MEDCoupling_Swig/UsersGuideExamplesTest_numpy.py +++ b/src/MEDCoupling_Swig/UsersGuideExamplesTest_numpy.py @@ -18,10 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * from math import pi, sqrt diff --git a/src/MEDLoader/Swig/MEDLoaderCouplingTrainingSession.py b/src/MEDLoader/Swig/MEDLoaderCouplingTrainingSession.py index 703bd84f9..d13a32618 100644 --- a/src/MEDLoader/Swig/MEDLoaderCouplingTrainingSession.py +++ b/src/MEDLoader/Swig/MEDLoaderCouplingTrainingSession.py @@ -21,7 +21,7 @@ from MEDLoader import * from MEDCouplingRemapper import * -import math, os +import math, sys import tempfile,os,shutil zeDir = tempfile.mkdtemp() @@ -600,4 +600,9 @@ omega=sum(angle2)/(ts[-1][2]-ts[0][2]) print(sum(angle2)) ; assert abs(sum(angle2)-1.12)<1e-2 print("Au pdt (%d,%d) a %r s le couple est de : %r N.m, power/omega=%r N.m"%(ts[2][0],ts[2][1],ts[2][2],zeTorque[2],power/omega)) assert abs(power/omega-0.37)<1e-2 + +# on windows, if we remain in this temporary directory +# Windows will lock it and deletion attempt will fail +if sys.platform == "win32": + os.chdir(os.path.dirname(zeDir)) shutil.rmtree(zeDir) diff --git a/src/MEDLoader/Swig/MEDLoaderDataForTest.py b/src/MEDLoader/Swig/MEDLoaderDataForTest.py index 759acc451..84795152f 100644 --- a/src/MEDLoader/Swig/MEDLoaderDataForTest.py +++ b/src/MEDLoader/Swig/MEDLoaderDataForTest.py @@ -21,6 +21,7 @@ from MEDLoader import * from math import pi,e,sqrt +import sys def WriteInTmpDir(func): def decaratedFunc(*args,**kwargs): @@ -29,6 +30,10 @@ def WriteInTmpDir(func): with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) ret = func(*args,**kwargs) + # on windows, if we remain in this temporary directory + # Windows will lock it and deletion attempt will fail + if sys.platform == "win32": + os.chdir(os.path.dirname(tmpdirname)) pass return ret return decaratedFunc diff --git a/src/MEDLoader/Swig/UsersGuideExamplesTest_ML.py b/src/MEDLoader/Swig/UsersGuideExamplesTest_ML.py index 2ffef8196..675d5814f 100644 --- a/src/MEDLoader/Swig/UsersGuideExamplesTest_ML.py +++ b/src/MEDLoader/Swig/UsersGuideExamplesTest_ML.py @@ -19,8 +19,7 @@ # from MEDLoader import * -import os -import tempfile,os,shutil +import tempfile, os, sys, shutil zeDir = tempfile.mkdtemp() os.chdir(zeDir) @@ -188,4 +187,9 @@ for ff1TS in ff: field=ff1TS.getFieldAtLevel(ON_CELLS,level) field=ff1TS.getFieldOnMeshAtLevel(ON_CELLS,level,mm) #! [UG_RWFieldAdv_5] + +# on windows, if we remain in this temporary directory +# Windows will lock it and deletion attempt will fail +if sys.platform == "win32": + os.chdir(os.path.dirname(zeDir)) shutil.rmtree(zeDir) diff --git a/src/MEDLoader/Test/MCTestLauncher.py b/src/MEDLoader/Test/MCTestLauncher.py index 86759b2ec..e70fac9f9 100644 --- a/src/MEDLoader/Test/MCTestLauncher.py +++ b/src/MEDLoader/Test/MCTestLauncher.py @@ -28,4 +28,8 @@ with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) p = sp.check_output(full_path) print(p.decode()) + # on windows, if we remain in this temporary directory + # Windows will lock it and deletion attempt will fail + if sys.platform == "win32": + os.chdir(os.path.dirname(tmpdirname)) pass diff --git a/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx b/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx index bfeb394e8..462912b24 100644 --- a/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx +++ b/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx @@ -93,13 +93,22 @@ std::string MEDPARTITIONERTest::getPartitionerExe() const if ( getenv("MEDCOUPLING_ROOT_DIR") ) { execName=getenv("MEDCOUPLING_ROOT_DIR"); //.../INSTALL/MED +#ifndef WIN32 execName+="/bin/medpartitioner"; +#else + execName+="\\bin\\medpartitioner.exe"; +#endif std::ifstream my_file(execName.c_str()); if (my_file.good()) return execName; } execName = getcwd(NULL, 0); +#ifndef WIN32 execName += "/../../MEDPartitioner/medpartitioner"; +#else + execName += "\\..\\..\\MEDPartitioner\\medpartitioner.exe"; +#endif + if (! std::ifstream(execName.c_str())) CPPUNIT_FAIL("Can't find medpartitioner, please set MEDCOUPLING_ROOT_DIR"); return execName; @@ -996,8 +1005,11 @@ void MEDPARTITIONERTest::launchMetisOrScotchMedpartitionerOnTestMeshes(std::stri string cmd,execName,sourceName,targetName; execName=getPartitionerExe(); - +#ifndef WIN32 cmd="which "+execName+" 2>/dev/null 1>/dev/null"; //no trace +#else + cmd="dir "+execName+" > NUL 2>&1"; //no trace +#endif res=system(cmd.c_str()); CPPUNIT_ASSERT_EQUAL_MESSAGE(execName + " - INVALID PATH TO medpartitioner", 0, res); diff --git a/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake b/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake index 5b0074a1c..f0e7db6fd 100644 --- a/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake +++ b/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake @@ -21,12 +21,20 @@ SET(TEST_NAMES MEDPartitionerTest ) +SET(PYTHONPATH $ENV{PYTHONPATH}) +IF(WIN32) + SET(PYTHONPATH "$ENV{PYTHONPATH};../../bin") +ELSE(WIN32) + SET(PYTHONPATH "$ENV{PYTHONPATH}:../../bin") +ENDIF(WIN32) + FOREACH(tfile ${TEST_NAMES}) SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) ADD_TEST(${TEST_NAME} python ${tfile}.py) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} - ENVIRONMENT "PYTHONPATH=../../bin:$ENV{PYTHONPATH}" + ENVIRONMENT "${PYTHONPATH}" + ) ENDFOREACH() diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py b/src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py index 60280d189..51691651c 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py @@ -21,11 +21,15 @@ def WriteInTmpDir(func): def decaratedFunc(*args,**kwargs): - import tempfile,os + import tempfile,os, sys ret = None with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) ret = func(*args,**kwargs) + # on windows, if we remain in this temporary directory + # Windows will lock it and deletion attempt will fail + if sys.platform == "win32": + os.chdir(os.path.dirname(tmpdirname)) pass return ret return decaratedFunc diff --git a/src/PyWrapping/TestPyWrapGathered_medcoupling.py b/src/PyWrapping/TestPyWrapGathered_medcoupling.py index 53a97d492..f933d7ce9 100644 --- a/src/PyWrapping/TestPyWrapGathered_medcoupling.py +++ b/src/PyWrapping/TestPyWrapGathered_medcoupling.py @@ -25,11 +25,15 @@ import unittest def WriteInTmpDir(func): def decoratedFunc(*args,**kwargs): - import tempfile,os + import tempfile,os, sys ret = None with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) ret = func(*args,**kwargs) + # on windows, if we remain in this temporary directory + # Windows will lock it and deletion attempt will fail + if sys.platform == "win32": + os.chdir(os.path.dirname(tmpdirname)) pass return ret return decoratedFunc diff --git a/src/RENUMBER_Swig/CTestTestfileInstall.cmake b/src/RENUMBER_Swig/CTestTestfileInstall.cmake index 09e57cacf..ccf32c2d0 100644 --- a/src/RENUMBER_Swig/CTestTestfileInstall.cmake +++ b/src/RENUMBER_Swig/CTestTestfileInstall.cmake @@ -21,13 +21,21 @@ SET(TEST_NAMES MEDRenumberTest ) +SET(PYTHONPATH $ENV{PYTHONPATH}) +IF(WIN32) + SET(PYTHONPATH "$ENV{PYTHONPATH};../../bin") +ELSE(WIN32) + SET(PYTHONPATH "$ENV{PYTHONPATH}:../../bin") +ENDIF(WIN32) + FOREACH(tfile ${TEST_NAMES}) SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) ADD_TEST(${TEST_NAME} python ${tfile}.py) + SET(TEST_ENVIRONMENT) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} - ENVIRONMENT "PYTHONPATH=../../bin:$ENV{PYTHONPATH}" + ENVIRONMENT "${PYTHONPATH}" ) ENDFOREACH() @@ -36,5 +44,5 @@ ADD_TEST(${TEST_NAME} python UsersGuideExamplesTest.py) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} - ENVIRONMENT "PYTHONPATH=../../bin:$ENV{PYTHONPATH}" + ENVIRONMENT "${PYTHONPATH}" ) diff --git a/src/RENUMBER_Swig/UsersGuideExamplesTest.py b/src/RENUMBER_Swig/UsersGuideExamplesTest.py index c4639069f..cc851db0d 100644 --- a/src/RENUMBER_Swig/UsersGuideExamplesTest.py +++ b/src/RENUMBER_Swig/UsersGuideExamplesTest.py @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * from math import pi, sqrt