From f970a374f8228afe51c80cff4df9399ee6638477 Mon Sep 17 00:00:00 2001 From: Nabil Ghodbane Date: Tue, 21 Mar 2023 13:14:09 +0100 Subject: [PATCH] Fix MEDCoupling tests currently failing 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 Taking into account code review as discussed in this pull request: https://codev-tuleap.cea.fr/plugins/git/?action=pull-requests&repo_id=146&group_id=116#/pull-requests/2456/overview --- src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingDataForTest.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingExamplesTest.py | 6 ++---- src/MEDCoupling_Swig/MEDCouplingIntersectTest.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingNumPyTest.py | 5 +---- src/MEDCoupling_Swig/MEDCouplingPickleTest.py | 5 +---- src/MEDCoupling_Swig/UsersGuideExamplesTest.py | 5 +---- .../UsersGuideExamplesTest_numpy.py | 5 +---- .../Swig/MEDLoaderCouplingTrainingSession.py | 4 +++- src/MEDLoader/Swig/MEDLoaderDataForTest.py | 2 ++ src/MEDLoader/Swig/UsersGuideExamplesTest_ML.py | 5 +++-- src/MEDLoader/Test/MCTestLauncher.py | 1 + src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx | 14 +++++++++++++- src/MEDPartitioner_Swig/CTestTestfileInstall.cmake | 5 ++++- src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py | 3 ++- src/PyWrapping/TestPyWrapGathered_medcoupling.py | 3 ++- src/RENUMBER_Swig/CTestTestfileInstall.cmake | 7 +++++-- src/RENUMBER_Swig/UsersGuideExamplesTest.py | 5 +---- 24 files changed, 51 insertions(+), 69 deletions(-) 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..4175fd56b 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,7 @@ def WriteInTmpDir(func): with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) ret = func(*args,**kwargs) + 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..db0eeb93f 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,6 @@ 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 + +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..db85e7674 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,7 @@ def WriteInTmpDir(func): with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) ret = func(*args,**kwargs) + 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..ad6f24183 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,6 @@ for ff1TS in ff: field=ff1TS.getFieldAtLevel(ON_CELLS,level) field=ff1TS.getFieldOnMeshAtLevel(ON_CELLS,level,mm) #! [UG_RWFieldAdv_5] + +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..3a0b8f254 100644 --- a/src/MEDLoader/Test/MCTestLauncher.py +++ b/src/MEDLoader/Test/MCTestLauncher.py @@ -28,4 +28,5 @@ with tempfile.TemporaryDirectory() as tmpdirname: os.chdir(tmpdirname) p = sp.check_output(full_path) print(p.decode()) + 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..9429b1109 100644 --- a/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake +++ b/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake @@ -21,12 +21,15 @@ SET(TEST_NAMES MEDPartitionerTest ) +SET(PYTHONPATH $ENV{PYTHONPATH}) +CMAKE_PATH(APPEND PYTHONPATH "../../bin") 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..fff478300 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMTestTools.py @@ -21,11 +21,12 @@ 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) + 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..a8e66ce27 100644 --- a/src/PyWrapping/TestPyWrapGathered_medcoupling.py +++ b/src/PyWrapping/TestPyWrapGathered_medcoupling.py @@ -25,11 +25,12 @@ 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) + 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..3543c73bf 100644 --- a/src/RENUMBER_Swig/CTestTestfileInstall.cmake +++ b/src/RENUMBER_Swig/CTestTestfileInstall.cmake @@ -21,13 +21,16 @@ SET(TEST_NAMES MEDRenumberTest ) +SET(PYTHONPATH $ENV{PYTHONPATH}) +CMAKE_PATH(APPEND PYTHONPATH "../../bin") 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 +39,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 -- 2.39.2